Skip to main content

pyusps - An API library for USPS, written in Python

pyUSPS is a full-featured, type annotated API client written in Python for the USPS APIs.

This library has been developed with the intention of making the USPS APIs simple and accessible to non-coders while allowing experienced coders to utilize all features the API has to offer without the boilerplate.

Features:

  • 100% API Coverage. All endpoints and response models.
  • Non-coder friendly. 100% annotated for full IDE auto-completion. Clients handle requests and authentication - just plug the right details in and go!
  • Fully annotated. This library has a strong focus on type safety and type hinting. Models are declared and parsed using Pydantic

pyUSPS is currently in development.

Known Issues:

  • As this project is still a WIP, documentation or code commentary may not always align.

Road Map:

How-to:

Install

Open a terminal and run pip install pyusps

Initializing the API Clients

USPS API

from pyusps import USPSAPIClient

# init client
usps_api_client = USPSAPIClient(
  # your api private key,
)

Working with Endpoints

Endpoints are 1:1 to what's available for USPS.

For more information, check out the following resources:

Get many

# sends GET request to /company/companies endpoint
companies = usps_api_client.company.companies.get()

Get one

# sends GET request to /company/companies/{id} endpoint
accounts = usps_api_client.accounts.id("abc123").get()

Get with params

# sends GET request to /company/companies with a conditions query string
conditional_company = usps_api_client.company.companies.get(params={
  'conditions': 'company/id=250'
})

Pagination

To make working with paginated data easy, Endpoints that implement a GET response with an array also supply a paginated() method. Under the hood this wraps a GET or POST request as required, but does a lot of neat stuff to make working with pages easier.

Working with pagination

# initialize a PaginatedResponse instance for /agents, starting on page 1 with a pageSize of 100
paginated_agents = sat_api_client.agents.paginated(1,100)

# access the data from the current page using the .data field
page_one_data = paginated_agents.data

# if there's a next page, retrieve the next page worth of data
paginated_agents.get_next_page()

# if there's a previous page, retrieve the previous page worth of data
paginated_agents.get_previous_page()

# iterate over all companies on the current page
for agent in paginated_agents:
  # ... do things ...

# iterate over all companies in all pages
# this works by yielding every item on the page, then fetching the next page and continuing until there's no data left
for agent in paginated_agents.all():
  # ... do things ...

Contributing

Contributions to the project are welcome. If you find any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request.

Supporting the project

:heart:

Inspiration and Stolen Code

The premise behind this came from the pyConnectWise package and I stole most of the code and adapted it to the USPS API endpoints.

How to Build

python -m build python -m twine upload dist/*

Metadata

Release files for pyuspostalservice 0.1.1

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

Source distribution (sdist)

Source distribution for pyuspostalservice 0.1.1
File Size Uploaded
pyuspostalservice-0.1.1.tar.gz 31.2 kB Details

Built distribution (wheel)

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

Total release size: 83.0 kB

Release files / pyuspostalservice-0.1.1.tar.gz

Download URL pyuspostalservice-0.1.1.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fae6bd20a5e995e66d77aa91024777c400023c8f13d10ad37f1118c23e664e86
BLAKE2b-256 checksum
How to use checksums
e1fbd68fb097fbe8f67cc20affa54c02df2c5fda73cf4f67679fa06509517eb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / pyuspostalservice-0.1.1-py3-none-any.whl

Download URL pyuspostalservice-0.1.1-py3-none-any.whl
Size 51.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd3648d98506492098d2c83063c041b2fc8b7ce19e5b12444d0c7ed66ea3eb55
BLAKE2b-256 checksum
How to use checksums
80e6cbb6f2c7ccd9c4a61ff92c1adf1c75215c821001ad6652ccfff4a1d33e4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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