Skip to main content

Parse tracking numbers from couriers with no external dependencies

Project description

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.

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.

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

tracking-numbers-0.1.1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tracking_numbers-0.1.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file tracking-numbers-0.1.1.tar.gz.

File metadata

  • Download URL: tracking-numbers-0.1.1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.9.12 Darwin/20.6.0

File hashes

Hashes for tracking-numbers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 809b2c534ac26c4f3bf81564184031e33833623ef107d906f697730c31c13970
MD5 1d2294cc93fa0c3535545e12ea9dd38c
BLAKE2b-256 9379a8d7d07d97268f651fb2424a710ef0e14072e915cdc626ba31acad01fff6

See more details on using hashes here.

File details

Details for the file tracking_numbers-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tracking_numbers-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.9.12 Darwin/20.6.0

File hashes

Hashes for tracking_numbers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0e138e182ccc6a9037898631c200b51b631571fa224777258070e733025f0a13
MD5 27676f48ce4cb347572605e14abdec12
BLAKE2b-256 e449a20b3d6128d02b422db937f067c878338a8967758a39cc314996a7b444f7

See more details on using hashes here.

Supported by

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