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(str)
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 and publishes the distribution to PyPI 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.7.0.tar.gz (33.7 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.7.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rangeslib-0.7.0.tar.gz
Algorithm Hash digest
SHA256 d45ab4efcc96d00110f3561aa6104eda9bf35dc3f5893f0b874849cdeeee8910
MD5 43fe2b4ef5ee4e596d83f2432ac01167
BLAKE2b-256 d5203152ae67735639f0af5f96b4851697dc231b540afef5cd9e526d3bca2b90

See more details on using hashes here.

Provenance

The following attestation bundles were made for rangeslib-0.7.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.7.0-py3-none-any.whl.

File metadata

  • Download URL: rangeslib-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d1d925d4656508c3734176d2f698fc55c3ecd9e922edaa6c02831a6bacb3fb6
MD5 85bdcb057dd21ed09b8b3115e32109c4
BLAKE2b-256 b8557a53da5bef6196796f080ec2fda4d3ade0ea877a7cc79a4a68816e3051bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for rangeslib-0.7.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

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

This release

0.7.0 This release

2 files

0.6.1

2 files

0.6.0

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