Summarize contiguous numeric (integer) ranges found on standard input
Here's a simple tool you can use to check whether you have one or more expected sets of contiguous integers in a file (or some other input).
Installation
$ pip install summarize-ranges
Works with Python 3.8 through 3.14.
Options
--tsvprint TAB-separated high,low range values.--pythonprint closed,open Python ranges.--ignore-word-boundaries(or--iwb) match numbers with no respect for word boundaries (e.g., match the33inabc33def).--ignore-negatives(or--in) do not match leading hyphens that would otherwise indicate a negative number. Socatch-22will result in the number22being collected rather than-22.
Example usage
You can of course redirect a file or more complicated pipeline into
summarize-ranges. The examples below all just use echo for simplicity.
# One range is found:
$ echo 3 | summarize-ranges
Range 1: 3
$ echo 3 4 5 | summarize-ranges
Range 1: 3 to 5
# TAB-separated output:
$ echo 3 4 5 | summarize-ranges --tsv
3 5
# TAB-separated output for Python:
$ echo 3 4 5 | summarize-ranges --tsv --python
3 6
# Two ranges:
$ echo 3 5 | summarize-ranges
Range 1: 3
Range 2: 5
$ echo some text 3 more 4 text and 6, 7, 8. | summarize-ranges
Range 1: 3 to 4
Range 2: 6 to 8
# Negative numbers are recognized:
$ echo some text -3 and -4. | summarize-ranges
Range 1: -4 to -3
# But leading hyphens in numbers can be ignored:
$ echo some text -3 and -4. | summarize-ranges --ignore-negatives
Range 1: 3 to 4
# Python style closed-open ranges
$ echo 3 | summarize-ranges --python
Range 1: 3 to 4
$ echo 3 4 5 10 11 | summarize-ranges --python
Range 1: 3 to 6
Range 2: 10 to 12
# Ignore word boundaries:
$ echo some33 text34here and 35. | summarize-ranges --ignore-word-boundaries
Range 1: 33 to 35
Python API
There is a simple Python class, RangeSummarizer you can use to build your
own tools. See src/summarize_ranges/ranges.py and the tests in
test/test_summarizer.py.
Testing
Testing is done with pytest and nox.
env PYTHONPATH=src pytest and nox can be used directly. Or, to use the
Makefile, install uv, then make test
or make nox.
Possible enhancements
- Allow for
--expect high,lowarguments and exit non-zero if the expected range(s) are not found. This could also have a--strictoption to check that there are no additional unexpected ranges found and a--quietoption to suppress output (though/dev/nullcan just be used).
Metadata
Release files for summarize-ranges 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| summarize_ranges-0.1.1.tar.gz | 13.1 kB | Without provenance | Details |
Release files / summarize_ranges-0.1.1.tar.gz
| Download URL | summarize_ranges-0.1.1.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ee9d5cfbc1dee2688e76bafb24b202d6c30201c2cba410370fda7506fc4edfc
|
|
BLAKE2b-256 checksum How to use checksums |
79ce28aae7249b5801ac278ae1c5083dd141822ba041d060ad5c62d18ae588b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.2
|
Security for summarize-ranges 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.