portion
Python data structure and operations for intervals
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction: pure Python wheel with a single runtime dependency (sortedcontainers).
- Active maintenance with a release 61 days ago and 523 repository stars.
License · maintenance · safety
LGPL-3.0-or-later (copyleft) — 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.
last release 2026-06-14 (61 days) · last repo commit 2026-06-29 · 523 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,697,074 downloads/mo, #3,643 on PyPI
Alternatives
Verify before relying
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]- 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.
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 on this page. Verify before relying on it.
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
portion on PyPI
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.
Requires Python 3.10 or later.
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]
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 the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagesortedcontainers |
| Maintenance | Actively maintained 61 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,697,074 / month, #3,643 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: EducationIntended Audience :: Information TechnologyIntended Audience :: Science/ResearchLicense :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Mathematics |
Evidence: portion-2.6.2-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “interval data structure”
- portionportion provides data structures and operations for working with…
- igwn-segmentsProvides segment, segmentlist, and segmentlistdict objects for…
- intervaltreeA self-balancing interval tree data structure that stores and queries…
Give your agent the search over MCP, or paste the wish link into any chat.
More Scientific/Engineering packages
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
pandas provides fast, flexible data structures (Series and DataFrame) for loading, cleaning, transforming, and analyzing labeled or relational data in Python.
scipy provides numerical algorithms for mathematics, science, and engineering—including optimization, integration, linear algebra, Fourier transforms, signal and image processing, and ODE solvers—built on numpy arrays.
scikit-learn provides a comprehensive Python library for supervised and unsupervised machine learning, including classification, regression, clustering, dimensionality reduction, and model evaluation tools built on NumPy and SciPy.
Install it if you need to train, evaluate, or deploy supervised or unsupervised learning models.
dill extends Python's pickle module to serialize and deserialize a much wider range of Python objects, including functions, lambdas, classes, and interpreter sessions, to byte streams for storage or network transmission.
Multiprocess is an enhanced fork of Python's standard multiprocessing library that uses dill for better serialization, allowing you to spawn processes with a threading-like API and share complex objects between them.
Install it if you use multiprocessing and encounter pickle serialization limits with lambdas or complex objects.
See also intervals · intervaltree · ncls · igwn-segments · python-ranges · infinity · multiset · timeloop · skia-pathops