--- id: portion version: "2.6.2" license: LGPL-3.0-or-later license_treatment: copyleft maintenance: active --- # portion — Python data structure and operations for intervals License: copyleft · Maintenance: active · Downloads: 1.7M/mo ## What it is and what it does portion is a Python library for creating and manipulating intervals—single ranges or unions of ranges—with automatic simplification and rich set operations. It handles any comparable objects as bounds (numbers, dates, strings) and supports both finite and infinite intervals with open or closed boundaries. The library provides intersection, union, complement, and difference operations, plus tests for emptiness, overlap, and adjacency. Typical use cases include scheduling systems, range queries, temporal logic, and mathematical interval arithmetic. It includes a dict-like structure to map intervals to data, discrete iteration over interval values, and import/export to strings and Python built-in types. The library is actively maintained, well-tested, and requires only sortedcontainers as a runtime dependency. Use it for: - Scheduling and time-slot management: represent availability windows and find overlaps or gaps. - Range queries in databases or data structures: efficiently test membership and compute intersections. - Temporal logic and constraint solving: work with time intervals and their logical combinations. - Numerical analysis: represent and manipulate domains, ranges, and solution sets. - Interval mapping: associate data with ranges and query by interval containment. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. portion provides data structures and operations for working with intervals—including unions, intersections, complements, and containment tests—with automatic simplification and support for any comparable objects. Yes. portion is production-stable (Development Status 5), actively maintained, has no known vulnerabilities, and imposes minimal install friction. The copyleft license (LGPL-3.0-or-later) is a consideration for proprietary use but poses no barrier for open-source projects. Install it if you need interval arithmetic or range operations. ## Install pip install portion uv add portion poetry add portion ## Installing portion Before you install: Low friction: pure Python wheel with a single runtime dependency (sortedcontainers). Active maintenance with a release 61 days ago and 523 repository stars. License in practice: LGPL-3.0-or-later (copyleft): derivative works and distributions must preserve the license and provide source code access; suitable for open-source projects but requires careful review in proprietary contexts. Quickstart: pip install portion import portion as P # Create intervals interval = P.closed(1, 2) print(interval) # [1,2] # Perform operations result = P.closed(0, 2) & P.closed(1, 3) print(result) # [1,2] Requires Python 3.10 or later. Verify before relying: - Whether discrete interval simplification (e.g., [0,1] | [2,3] → [0,3] for integers) is available via the customization API mentioned in the description. - Performance characteristics for very large interval sets or deeply nested operations. - Whether the dict-like interval mapping structure supports all standard dict operations. ## Package facts - License: LGPL-3.0-or-later (copyleft) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 1.7M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags interval data structure, interval operations union intersection, range and span handling, interval set arithmetic, comparable object intervals, interval simplification, discrete interval iteration, interval-arithmetic, range-operations, set-theory [View on SkillFed](https://skillfed.io/packages/portion) · [View on PyPI](https://pypi.org/project/portion/)