Table of Contents generated with DocToc
tracking-numbers
A library that parses tracking numbers and provides common types.
The data is sourced from tracking_number_data and the definitions are code-generated.
Why?
The typical shipping tracking number has a lot of data encoded within. While some couriers share similar logic (serial number, check digit, etc), others have entirely different ways of representing tracking numbers.
Instead of hand-rolling parsing code for all of these cases, the author of tracking_number_data has put together a repo that serves as a language-agnostic source of knowledge for various couriers and their shipping products.
This library uses that data to code-generate definitions to create python bindings for parsing tracking numbers.
The library itself has no external dependencies, and can be used to decode basic tracking data without the need of an API or external data source at runtime.
Installation
Install the tracking-numbers library using pypi
pip install tracking-numbers
Usage
Here are the main public functions to use:
get_tracking_number(number)
Parses the number and returns the TrackingNumber dataclass, if detected, or none otherwise.
from tracking_numbers import get_tracking_number
tracking_number = get_tracking_number("1ZY0X1930320121606")
# => TrackingNumber(
# valid=False,
# number='1ZY0X1930320121606',
# serial_number=[6, 0, 5, 1, 9, 3, 0, 3, 2, 0, 1, 2, 1, 6, 0],
# tracking_url='https://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1ZY0X1930320121604',
# courier=Courier(code='ups', name='UPS'),
# product=Product(name='UPS'),
# )
get_definition(product_name)
Given a product name, gets the TrackingNumberDefinition associated.
You can call definition.test(number) to parse a number for that specific product.
from tracking_numbers import get_definition
ups_definition = get_definition('UPS')
tracking_number = ups_definition.test("1ZY0X1930320121606")
# => TrackingNumber(
# valid=False,
# number='1ZY0X1930320121606',
# serial_number=[6, 0, 5, 1, 9, 3, 0, 3, 2, 0, 1, 2, 1, 6, 0],
# tracking_url='https://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1ZY0X1930320121604',
# courier=Courier(code='ups', name='UPS'),
# product=Product(name='UPS'),
# )
tracking_number = ups_definition.test('some_valid_fedex_number')
# => None
Testing
We use the test cases defined in the courier data to generate pytest test cases. In this way, we can be confident that the logic for parsing tracking numbers is working properly.
Metadata
Release files for tracking-numbers 0.1.8
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 | Actions |
|---|---|---|---|---|
| tracking-numbers-0.1.8.tar.gz | 11.1 kB | Without provenance | Details for tracking-numbers-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tracking_numbers-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for tracking_numbers-0.1.8-py3-none-any.whl |
Total release size: 23.5 kB
Release files / tracking-numbers-0.1.8.tar.gz
| Download URL | tracking-numbers-0.1.8.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47df6d3bcd8b66a721e2445c0ca1b1b414cf8c8d0e2be9507e1f499d13c05943
|
|
BLAKE2b-256 checksum How to use checksums |
6930e5bc3a55a328d5821e07fa3cd227bb7b8f95513a2aa273212e781c453288
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.9.15 Darwin/20.6.0
|
Release files / tracking_numbers-0.1.8-py3-none-any.whl
| Download URL | tracking_numbers-0.1.8-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
502c042598fb7443a6817c66f905c3078abf4772c00ec89865105727fcb34a35
|
|
BLAKE2b-256 checksum How to use checksums |
c357c6de67bb0fa057e68f2150fbd09b68cd1b4584b87a6a4d545bc3373535df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.9.15 Darwin/20.6.0
|
Security for tracking-numbers 0.1.8
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.