Skip to main content

Extents - An Intervals Library in Pure Python

extents is an intervals library implemented in pure python. It draws its inspiration from the PyInterval library (github).

This library is capable of representing open, closed and semi-open/closed intervals. It also supports set operations on intervals (i.e., union, intersection and complement).

Examples:

Basic use cases:

Basic use of this library includes creating simple intervals, and manipulating them through set operations

from extents import interval        # the interval class represents a collection of intervals

ival1 = interval([0, 1])            # the singleton interval set containing the closed interval [0, 1]
print(ival1)                        # Interval([0, 1])
print(~ival1)                       # Interval((-inf, 0), (1, inf)) -- the interval set of (-inf, 0) and (1, inf) -- 
                                    # which compose the complement of [0, 1]

ival2 = interval((4, 5))            # the singleton interval set containing the open interval (4, 5)
print(ival2)                        # Interval((4, 5))
print(~ival2)                       # Interval((-inf, 4], [5, inf)) -- the interval set of (-inf, 4] and [5, inf) --
                                    # which are the complement of (4, 5)]

ival3 = interval([0, 1], [5, 6])    # the interval set [0, 1] and [5, 6]
ival4 = interval([0, 3], [4, 5.5])  # the interval set [0, 3] and [4, 5.5]
print(ival3 | ival4)                # the interval set [0, 3] and [4, 6], which is the union of ival3 and ival4
print(ival3 & ival4)                # the interval set [0, 1] and [5, 5.5], which is the intersection of ival3 and ival4

ival5 = interval([0, 1], [0.5, 3])  # intervals are automatically union-ed during construction.
print(ival5)                        # resulting in the interval [0, 3]

The output of the commands above would be:

Interval([0, 1])
Interval((-inf, 0), (1, inf))
Interval((4, 5))
Interval((-inf, 4], [5, inf))
Interval([0, 3], [4, 6])
Interval([0, 1], [5, 5.5])
Interval([0, 3])

Advanced use cases:

In order to construct a semi-open interval, you can import the Component and ComponentType, and construct the internal interval components.

For example,

from extents import interval, Component, ComponentType

ival = interval(Component(0, 1, ComponentType.HALF_CLOSED_LEFT),
                Component(5, 6, ComponentType.HALF_CLOSED_RIGHT)
                )
print(ival)  # construct the interval set: [0, 1), (5, 6]

Additional Examples:

See the tests/extents_test.py file.

Installation:

From github:

$ pip install git+https://github.com/swapp-ai/extents

From source:

$ git clone https://github.com/swapp-ai/extents
$ cd extents
$ pip install .

Metadata

Release files for extents 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for extents 0.2.2
File Size Uploaded
extents-0.2.2.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for extents 0.2.2
File Interpreter ABI Platform
extents-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / extents-0.2.2.tar.gz

Download URL extents-0.2.2.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
34f494fe8815bda4a017b880998f08600366ad47c9406d46269c195c15f6441b
BLAKE2b-256 checksum
How to use checksums
c02cc86c7a2c407e19100aa7a9bf714a567476f17158ba5955306c23aaa1beb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / extents-0.2.2-py3-none-any.whl

Download URL extents-0.2.2-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
acd987b1d8a49dcc43b34d420055ace9d46fc7f1c6786dda58d183e724d8bf8c
BLAKE2b-256 checksum
How to use checksums
8fdbfcdc64c988b86e6c25b3d6e94455f7a5e00c113692ae3233f382017e11a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page