Skip to main content

rangeslib

Tests and quality Documentation Python 3.12+ License: MIT

rangeslib is a typed Python library for eager, C++-inspired range pipelines. The public API is intentionally small:

from rangeslib import ranges, views

The mental model is:

ranges creates values
views transforms values
views.to converts the final result

Quick Start

from rangeslib import ranges, views

result = (
    ranges.iota(1, 11)
    | views.filter(lambda value: value % 2 == 0)
    | views.transform(lambda value: value * 10)
    | views.take(3)
    | views.to(list)
)

assert result == [20, 40, 60]

Range values are eager and reusable. Most adaptors return another Range; the terminal views.to(...) adaptor returns whatever collection or factory you ask for.

Existing Iterables

Ordinary Python iterables can start pipelines too:

from rangeslib import views

text = "abcdef" | views.take(3) | views.to("".join)
assert text == "abc"

chars = "abc" | views.all()
assert list(chars) == ["a", "b", "c"]

views.all() is the eager Python counterpart to C++ views::all: it adapts an existing iterable into a reusable Range.

Reusable Pipelines

Adaptors can be composed before data is supplied:

from rangeslib import views

first_three_even = views.filter(lambda value: value % 2 == 0) | views.take(3)

assert list([1, 2, 3, 4, 5, 6] | first_three_even) == [2, 4, 6]
assert list([10, 11, 12, 14] | first_three_even) == [10, 12, 14]

Sources And Views

The ranges facade creates source ranges:

from rangeslib import ranges

ranges.empty()
ranges.single("value")
ranges.iota(1, 5)
ranges.indices(3)
ranges.repeat("x", 3)

The views facade contains transformations such as:

all, reverse, filter, transform, take, drop, counted,
elements, keys, values, enumerate, concat, zip, cartesian_product,
adjacent, pairwise, chunk, slide, stride, join, split, to

See docs/usage.md for the full API catalog.

C++ Ranges Correspondence

rangeslib borrows naming and broad behavior from C++20/23/26 ranges, but it is not a lazy C++ view implementation. The most important differences are:

  • Python iterables replace C++ iterator/sentinel pairs.
  • Range stores eager values instead of reference-like lazy views.
  • Tuple results are ordinary Python tuples, not tuples of references.
  • Python type checking is useful but cannot express every C++ tuple-like rule.

See docs/cpp-comparison.md for details.

Installation

Python 3.12 or newer is required.

python -m pip install .

For development:

python -m pip install -e ".[dev]"

rangeslib has no runtime dependencies.

Development

Useful commands live in scripts/:

./scripts/run_tests.sh       # tests only
./scripts/typecheck.sh       # mypy + Pyright
./scripts/check.sh           # Ruff, typing, tests, coverage
./scripts/check_all.sh       # check.sh + strict Sphinx docs
./scripts/check_package.sh   # sdist/wheel build and install smoke test
./scripts/run_playground.sh  # manual playground

Before a release commit, run:

./scripts/check_all.sh
./scripts/check_package.sh

Documentation

Build the Sphinx site with:

./scripts/generate_docs.sh

Generated HTML is written to docs/_build/html/ and published to GitHub Pages after CI succeeds on main.

Releases

Changing [project].version in pyproject.toml on main automatically runs the complete quality and package checks, then creates the matching Git tag and GitHub Release. Published GitHub Releases trigger PyPI publishing through Trusted Publishing after the PyPI project is configured.

For future work, prefer opening or collecting issues before adding more adaptors immediately. See docs/roadmap.md.

See docs/publishing.md for the PyPI setup checklist.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rangeslib-0.6.0.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rangeslib-0.6.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file rangeslib-0.6.0.tar.gz.

File metadata

  • Download URL: rangeslib-0.6.0.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rangeslib-0.6.0.tar.gz
Algorithm Hash digest
SHA256 04adcf6fdcb9985edc9bed1aa17cce884f6f8c27f09e3e5548c72e3b55ad8613
MD5 7a96052ec435d1a777d5439a2d95e6f4
BLAKE2b-256 4ed7728c70b21bf194575ac7028f632d8d07e38232876aeffa9ee947ddbdd185

See more details on using hashes here.

Provenance

The following attestation bundles were made for rangeslib-0.6.0.tar.gz:

Publisher: publish.yml on TheUltimateOrion/RangesLib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rangeslib-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: rangeslib-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rangeslib-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdf2fccb6db14ef7f05fc4df4102db11e26e54cfd8c6540c383c71b1db0ce9ee
MD5 ee507b7d723c6bb1104758b57f26d7a0
BLAKE2b-256 ec2bbde65301a8ad4a72745e5e2619d272aec53bb77523b628734e3348272843

See more details on using hashes here.

Provenance

The following attestation bundles were made for rangeslib-0.6.0-py3-none-any.whl:

Publisher: publish.yml on TheUltimateOrion/RangesLib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 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