Registry / data / python-ranges

python-ranges

JSON →
library1.2.2pypypi✓ verified 87d ago

Continuous Range, RangeSet, and RangeDict data structures for Python >=3.9. v1.2.2 provides immutable and hashable interval/multi-interval containers with O(log n) operations. Moderate release cadence.

pip install python-ranges
INSTALL
IMPORT
SIG · PYTHON-RANGES
P
python-ranges
datapythonv1.2.2
Install
1.6s avg
Import
16ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.016s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.016s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Range
from ranges import Range
Directly from ranges package.
RangeSet
from ranges import RangeSet
Collection of non-overlapping ranges.
RangeDict
from ranges import RangeDict
Mapping from ranges to values.

Basic usage of Range, RangeSet, and RangeDict.

from ranges import Range, RangeSet, RangeDict # Create a Range r = Range(1, 5) # [1, 5) print(r) # Range(1, 5) # Check membership print(3 in r) # True print(5 in r) # False # Intersection, union r2 = Range(3, 7) # [3, 7) print(r & r2) # Range(3, 5) print(r | r2) # RangeSet(Range(1, 7)) # RangeSet rs = RangeSet(r, Range(10, 15)) print(rs) # RangeSet(Range(1, 5), Range(10, 15)) # RangeDict rd = RangeDict({Range(0, 10): 'low', Range(10, 20): 'high'}) print(rd[5]) # 'low'
Debug
Known issues
breakingRanges are half-open [start, end) by default. Mistaking inclusive/exclusive leads to off-by-one errors.
fix
Remember that Range(a, b) includes a but excludes b. Use Range.closed(a, b) for inclusive endpoints if needed.
affects: all
gotchaRange objects are immutable and hashable, but creation with invalid bounds (start > end) raises ValueError.
fix
Always validate that start <= end before constructing a Range.
affects: all
gotchaWhen using RangeDict, keys must be Range objects; plain tuples or integers will not work and may raise TypeError or silently misbehave.
fix
Always use Range objects as keys in RangeDict.
affects: all
Errors
Common errors & fixes
ValueError: Cannot create Range with start > end
Attempting to create Range(5, 1) where start > end.
fix
Ensure start <= end, e.g., Range(1, 5).
TypeError: unhashable type: 'slice'
Using slice objects (e.g., my_dict[1:5]) when Range objects are expected.
fix
Replace slice with Range: my_dict[Range(1, 5)].
Upgrade
Version history
1.2.2latest on PyPI · released Feb 15, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources