skillfed

python-ranges

Continuous Range, RangeSet, and RangeDict data structures

python-ranges v1.2.2 77.7K downloads/30d#14,505 on PyPI101
Permissive license Abandoned released

What it is and what it does

python-ranges fills a gap in Python's standard library by providing proper continuous range data structures. The built-in range() only works with integers and doesn't support continuous values like floats or dates. This package introduces Range (a single continuous interval), RangeSet (a collection of non-overlapping ranges), and RangeDict (a dictionary that uses ranges as keys). These structures let you replace verbose if/elif/else chains and boundary-checking logic with cleaner, more readable code. For example, instead of writing multiple conditional branches to determine which tax bracket an income falls into, you can use a RangeDict to map income ranges directly to tax calculations.

The Range class supports any comparable data type—numbers, strings, dates—and can represent bounded or unbounded intervals with inclusive or exclusive endpoints. RangeSet provides set-like operations (union, intersection, difference) on collections of ranges. The package has zero runtime dependencies and installs easily, but development has stalled since early 2023, so it receives no active maintenance or updates.

Use it for:

  • Implement tax bracket or tiered pricing logic by mapping income or price ranges to corresponding rates or fees.
  • Validate user input by checking if a value falls within acceptable bounds using membership testing.
  • Clamp numeric or comparable values to a range without verbose min/max nesting.
  • Build interval-based queries or lookups where you need to find which range a value belongs to.
  • Perform set operations on date ranges, version ranges, or other comparable intervals.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides Range, RangeSet, and RangeDict data structures for representing continuous and non-continuous ranges of values, and for using ranges as dictionary keys.

Yes, if you need range data structures and can accept abandoned maintenance. The package is stable, has no known vulnerabilities, and solves a real problem with clean syntax. However, do not rely on it for active bug fixes or compatibility updates beyond Python 3.9. It is suitable for self-contained projects where you control the Python version and can tolerate no future support.

Install

python-ranges on PyPI

pip

pip install python-ranges

uv

uv add python-ranges

poetry

poetry add python-ranges

Installing python-ranges

Before you install

Low install friction with no runtime dependencies. However, the project is abandoned—last commit was 2023-07-25 and no releases since 2023-02-15. Requires Python 3.9 or higher.

License in practice

Licensed under MIT (permissive), so you can use, modify, and distribute this package freely with minimal restrictions.

Quickstart

pip install python-ranges

from ranges import Range, RangeDict

# Check membership
if 5 in Range(1, 10):
    print("Value in range")

# Use ranges as dictionary keys
tax_brackets = RangeDict({
    Range(0, 9701): 0.10,
    Range(9701, 39476): 0.12,
})
rate = tax_brackets[15000]

Requires Python 3.9 or higher.

Verify before relying

  • Whether the package handles edge cases with non-numeric types (strings, dates) as thoroughly as the description suggests.
  • Performance characteristics when working with very large ranges or RangeSets.
  • Compatibility with Python versions after 3.9, given the abandoned maintenance status.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance abandoned — 1,276 days since the last release
Last repo commit
First released
Downloads 77,689/month — #14,505 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: python_ranges-1.2.2-py3-none-any.whl

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

range data structurecontinuous ranges pythonrange dictionaryrange set operationsinterval arithmeticrange membership testingrange-based lookups
data-structuresinterval-arithmetic

More Software Development packages