Shipping API Python library (USPS, FedEx, UPS and more)
Project description
Shippo API Python wrapper
Modern Shippo API client implementation.
This implementation is not maintained by Shippo, and is a modern rewrite of their Python client. Shippo's documentation specifies that their default implementation is not actively maintained and could be used as a starting point if required. (see https://docs.goshippo.com/docs/guides_general/clientlibraries/) The goal of this project is to fix some issues with the default implementation (mostly obsolete dependencies). We would be happy with the Shippo team taking over this repository and officially maintain it.
About Shippo
Connect with multiple different carriers, get discounted shipping labels, track parcels, and much more with just one integration. You can use your own carrier accounts or take advantage of Shippo's discounted rates with the USPS and DHL Express. Using Shippo makes it easy to deal with multiple carrier integrations, rate shopping, tracking and other parts of the shipping workflow. Shippo provide the API and dashboard for all your shipping needs.
You will first need to register for a Shippo account to use our API. It's free to sign up, free to use the API. Only pay to print a live label, test labels are free.
Shippo API Documentation
Please see https://goshippo.com/docs for complete up-to-date documentation.
Supported Shippo Features
The Shippo API provides in depth support of carrier and shipping functionalities. Here are just some of the features we support through the API:
- Shipping rates & labels - Docs
- Tracking for any shipment with just the tracking number - Docs
- Batch label generation - Docs
- Multi-piece shipments - Docs
- Manifests and SCAN forms - Docs
- Customs declaration and commercial invoicing - Docs
- Address verification - Docs
- Consolidator support including:
- DHL eCommerce
- UPS Mail Innovations
- FedEx Smartpost
- Additional services: cash-on-delivery, certified mail, delivery confirmation, and more - Docs
How to use
pip install modern-shippo
import shippo
shippo.config.api_key = "<API-KEY>"
address1 = shippo.Address.create(
name='John Smith',
street1='6512 Greene Rd.',
street2='',
company='Initech',
phone='+1 234 346 7333',
city='Woodridge',
state='IL',
zip='60517',
country='US',
metadata='Customer ID 123456'
)
print(f'Success with Address 1: {address1!r}')
We've created a number of examples to cover the most common use cases. You can find the sample code files in the examples folder. Some of the use cases we covered include:
- Basic domestic shipment
- International shipment - Custom forms, interntational destinations
- Price estimation matrix
- Retrieve rates, filter by delivery time and purchase cheapest label
- Retrieve rates, purchase label for fastest delivery option
- Retrieve rates so customer can pick preferred shipping method, purchase label
Configuration
import shippo
shippo.config.api_key = "<API-KEY>"
shippo.config.api_version = "2018-02-08"
shippo.config.verify_ssl_certs = True
shippo.config.rates_req_timeout = 30.0
shippo.config.default_timeout = 80
shippo.config.app_name = "Name of your Application" # Not required
shippo.config.app_version = "Version of Application" # Not required
Configuration is read from the environement with the SHIPPO_ prefix See shippo/config.py for details.
Use with Google AppEngine
Google AppEngine applications should use UrlFetch to perform HTTP requests. The Requests module can be monkey-patched to use this HTTP client. The modern-shippo API client checks for requests_toolbelt availability and properly monkey-patch Requests.
pip install requests_toolbelt
import shippo
import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch()
shippo.config.default_timeout = 55 # AppEngine timeout is 60s
This was supported by the original Shippo client implementation, with a much complex http client abstraction. Modern-shippo relies entirely on Python Requests to greatly simplify the code base, and rely on requests-toolbelt to still support AppEngine.
How to setup a development environment
Make sure an Python 3.10+ interpretor is installed and available.
Install hatchling to manage environments, run scripts and build the library.
pip install hatch
With hatchling installed, use the integrated CLI to manage environments, run tests and more:
hatch run test
hatch run lint:style
Available environments and commands are available with:
hatch env show
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file modern_shippo-3.0.1.tar.gz
.
File metadata
- Download URL: modern_shippo-3.0.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55730fa132717ff6ea0e515a2d00c58aa67f5916fdfe891f420b190fb38a36a0 |
|
MD5 | 479f0ade1596b5da8d30aee0b4befda6 |
|
BLAKE2b-256 | 4fb54105f73b286ed298010b4dd32f337205795c5f7433a5e524a6020856cfa7 |
File details
Details for the file modern_shippo-3.0.1-py3-none-any.whl
.
File metadata
- Download URL: modern_shippo-3.0.1-py3-none-any.whl
- Upload date:
- Size: 29.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4b8dcd0cf047c22264513c4785ef920101f1980d913fb38f2e181e12aff78ed |
|
MD5 | e4394bd59f933bc5be16b139d8bc42cb |
|
BLAKE2b-256 | c886e9a107e1014c37a59fae65facbc157d1426d6d0d81c20e735549d429decc |