Intervals

0.9.2 · abandoned · verified Thu Apr 16

The `intervals` library (version 0.9.2) provides basic tools for handling intervals or ranges of comparable objects in Python. It supports defining closed, open, or half-open intervals and performing operations such as checking for containment. This specific package, maintained by kvesteri, appears to be abandoned, with no updates since 2016, and its functionality has largely been superseded by other, more actively maintained interval libraries like `portion` (which itself evolved from a library called `python-intervals`).

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create `Interval` objects using factory methods and directly, and how to perform a basic containment check. Note that rich interval operations (like `overlaps`, `intersection`, `union`) might be less intuitive or require manual implementation with this older, unmaintained library compared to modern alternatives.

from intervals import Interval, IntInterval

# Create an interval using the factory method
i1 = Interval.closed(1, 5) # Represents [1, 5]
print(f"Interval i1: {i1}")

# Create a half-open interval
i2 = Interval.closedopen(5, 10) # Represents [5, 10)
print(f"Interval i2: {i2}")

# Create a specific type of interval (e.g., integer interval)
i3 = IntInterval(3, 7) # Represents [3, 7]
print(f"Interval i3: {i3}")

# Check for containment
print(f"4 in i1: {4 in i1}") # Expected: True
print(f"5 in i2: {5 in i2}") # Expected: True
print(f"10 in i2: {10 in i2}") # Expected: False

# Check for overlap (note: older versions might not have a direct 'overlaps' method, requiring manual check or utility functions)
# For simple overlap, you might compare bounds manually or use set operations if applicable
# Or, rely on a library like 'portion' for richer operations.

view raw JSON →