Skip to main content

⛰️ arranges - dealing with ranges

A stable string representation for multiple ranges, so they can be used as fields, indexes and so on.

This library provides a few classes:

  • ⛓️ Segment is a class that can be treated like a set and its constructor is compatible with range and slice. It is derived from str so is easy to compare and serializes nicely. It is immutable, hashable and has a stable string representation.
  • 🏔️ Ranges is an ordered tuple of Segments. It is also immutable and derived from str like the above. It can be constructed from comma-separated Python-style slice notation strings (e.g. "1:10, 20:", "0x00:0xff and ":"), integers, slices, ranges, integers and (nested) iterables of the above.
  • ♾️ An inf singleton that is a float with a value of math.inf but has an __index__ that returns sys.maxsize and compares equal to infinity and maxsize, and its string representation is "inf".
  • 📕 A Dict that is keyed by Ranges and holds one per unique value.

The Ranges class is designed to be used as fields in Pydantic BaseModels, but can be used anywhere you need a range. They are not designed with speed in mind, and comparisons usually use the canonical string form by converting other things into Ranges objects. That said, they use lru_cache in most places so are usually fast enough. Their preferred pronoun is they/them.

📦 Installation

pip install arranges if you want to use them. You'll need Python 3.11 or above.

📖 Docs

See the tests for executable documentation

⚠️ Constraints

I made them to select lines or bytes in a stream of data, so they:

  • 🔢 only support ints;
  • ≮ do not allow negative indices, the minimum is 0 and the maximum is unbounded;
  • ✅ are compatible with range and slice, but step is fixed to 1. If you pass something with a step into its constructor it'll be converted to a list of ints (range(0, 10, 2) becomes "0,2,4,6,8");
  • ∪ do not support duplicate ranges. Ranges are merged together as they are added to the Ranges object;
  • 🐍 they are unpydantic in that its constructors are duck-typed, which is what I need;
  • ☣️ they violate the Zen of Python by having multiple ways to do the same thing, but I found that useful; and
  • ⚠️ Currently the interface is unstable, so lock the exact version in if you don't want breaking changes.

👨‍💻 Hacking

To add features etc you'll ideally need git, make, bash and something with a debugger. Config for Visual Studio Code is included.

Clone the repo and make dev to make the venv, install dependencies, then code . to open the project up in the venv with tests and debugging and all that jazz.

Type make help to see the other options, or run the one-liner scripts in the ./build dir if you want to run steps without all that fancy caching nonsense.

⚖️ License

Free as in freedom from legalese; the WTFPL with a warranty clause.

Release files for arranges 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arranges 0.2.3
File Size Uploaded
arranges-0.2.3.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for arranges 0.2.3
File Interpreter ABI Platform
arranges-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 25.1 kB

Release files / arranges-0.2.3.tar.gz

Download URL arranges-0.2.3.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
eb7440cbc90b8c2993c0fe012bb180c90dce99723b3c73b26a11a5e5d8c66d09
BLAKE2b-256 checksum
How to use checksums
c0ed866104ff62ea67f0fe625900d2a284f1fdf8d0a75bf89044a3d98d34239f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / arranges-0.2.3-py3-none-any.whl

Download URL arranges-0.2.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
818b27f582df9dcd280bad3545bba47ecae3c688ff25b1720ef565884635e876
BLAKE2b-256 checksum
How to use checksums
8f4d90c04ed768ce08d68087f92945f2a914f7530ba381d6ebb329ed98db1131
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release 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