Skip to main content

Mergable range object for use in Pydantic classes

Project description

Arranges

Range string fields for Pydantic BaseModels

I needed a way to parse batches of byte, row and line and other object ranges in my merge-files app, in a way that I can just drop it in as a string field type. The reason for this is so the machine-generated command line help is flat and readable by humans.

It it kinda grew into a monster so I've split it out into this separate package. It gives a couple of classes for dealing with ranges:

  • Range, a class that can be constructed from Python-style slice notation strings (e.g. "1:10", "0x00:0xff, ":"), range-likes, iterables of int-like objects. It has convenient properties lke being iterable, immutable, has a stable string representation and matching hash, it can be treated like a set and its constructor is compatible with range and slice.
  • The Ranges class is similar but supports holes in ranges - it's an ordered, mutable list of non-overlapping Range objects that simplifies as data is added.

Constraints

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

  • only supports ints;
  • does not allow negative indices, the minimum is 0 and the maximum is unbounded;
  • it's compatible with range and slice, but step is fixed to 1. This may change in the future;
  • does not support duplicate ranges. Ranges are merged together as they are added to the Ranges object;
  • it is unpydantic in that its constructors are duck-typed, which is what I need; and
  • it violates the Zen of Python by having multiple ways to do the same thing, but it's also useful.
  • Currently the interface is unstable, so lock the exact version in if you don't want breaking changes.

Installation

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

Dev setup

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.

Usage

License

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

Political note: I don't want to live in a world where lawyers tell me how to speak. If you don't trust me enough to use the WTFPL then you shouldn't be running my code in the first place.

Project details


Download files

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

Source Distribution

arranges-0.0.4.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

arranges-0.0.4-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file arranges-0.0.4.tar.gz.

File metadata

  • Download URL: arranges-0.0.4.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for arranges-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c24c4cd7b9c4447b4356dd77fb2cc8a9ce7dbc313ccd053839d4286c9ca9847a
MD5 b7c66ce134e8e6f86f7c28baa66a3d22
BLAKE2b-256 31f0df5b2ea5c4499fd889521139b6f0bba40c07104f5f653f5bf495e05da741

See more details on using hashes here.

File details

Details for the file arranges-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: arranges-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for arranges-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f1aa9e400d91911e0015e269f35a51057a706955d249d10ed928c55486de7cf6
MD5 c15f51fdc32a4bd2166fb4be1ece53a7
BLAKE2b-256 a497e8d6d8acd8b4e054a5aa14d7b8902752d247824731f37de6649bdb325746

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page