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.8.0.tar.gz (34.3 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.8.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rangeslib-0.8.0.tar.gz
Algorithm Hash digest
SHA256 273bf46e979b2132d302b909267408101e1cf267bc4fb2fa18f7c20719d2079f
MD5 9b44bbad775f0f6de089bbf9aee67e1a
BLAKE2b-256 c62444a75a39c381c384f2f617b047cf500dc2aca7142e12449ea9ce1ad640b7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: rangeslib-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 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.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d0c85b1e1a5910f756b620fb7ea3b071c71d22cf96b5f7194ae79fe87f06da4
MD5 d56acf3e6e4ddabce30ca03fbbc5d1a2
BLAKE2b-256 f9e06d35ccc0d85cf751468c35aef991731b732f0f0690838ae3e34d6b464923

See more details on using hashes here.

Provenance

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

This release

0.8.0 This release

2 files

0.7.0

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