Py-canada-post
Python written wrapper to interact with Canada Post API.
Table of contents
Why was it created?
There is no public Python library/wrapper to interact with Canada Post API, so an idea was born and brought to life.
How to use?
Essential steps:
Before you start using this wrapper, you should perform these essential steps:
-
Create a virtual environment:
-
Using python:
python -m venv .venv source .venv/bin/activate
-
Using uv:
uv python pin 3.11 uv init uv sync
-
-
Create .env and put your customer number, contract id and api key in there as followed:
CUSTOMER_NUMBER=12345667 CONTRACT_ID=12344556 API_KEY=ewfghui34hto34ghui34g:ewghui234h23oih34uigh423
To test this app, you will need some test credentials. You can get them here.
If you would like to obtain your own, you can register your business and join the Developer Program.
Quick start
To use this wrapper, you will need 3.11+ python version and pip.
Install from PyPi
pip install py-canada-post
or
uv add py-canada-post
Install from source
-
Clone the repository:
git clone https://github.com/joludyaster/py-canada-post.git
-
Run:
pip install .
or
uv pip install .
Getting started
You could define the client object yourself:
import os
from py_canada_post.client import PyCanadaPost
from py_canada_post.services.rating import Destination, DomesticDestination, ParcelCharacteristics
from dotenv import load_dotenv
load_dotenv()
customer_number = os.getenv("CUSTOMER_NUMBER", 0)
api_key = os.getenv("API_KEY", "")
contract_id = os.getenv("CONTRACT_ID", 0)
def main():
py_canada_post_client = PyCanadaPost(
customer_number=customer_number,
api_key=api_key,
contract_id=contract_id
)
rates = py_canada_post_client.rating.rates.get_rates(
origin_postal_code="E4M8S3",
destination=Destination(
domestic=DomesticDestination("T3Z1C8")
),
parcel_characteristics=ParcelCharacteristics(
weight=13.2
)
)
print(rates)
if __name__ == "__main__":
main()
Or you could use a shortcut:
from py_canada_post.client import PyCanadaPost
from py_canada_post.services.rating import Destination, DomesticDestination, ParcelCharacteristics
def main():
py_canada_post_client = PyCanadaPost.from_env()
rates = py_canada_post_client.rating.rates.get_rates(
origin_postal_code="E4M8S3",
destination=Destination(
domestic=DomesticDestination("T3Z1C8")
),
parcel_characteristics=ParcelCharacteristics(
weight=13.2
)
)
print(rates)
if __name__ == "__main__":
main()
See the documentation to learn more.
CLI
Usage:
py-canada-post [-v] [-h]
py-canada-post rating get-rates ORIGIN-POSTAL-CODE [ARGS]
py-canada-post rating discover-services COUNTRY-CODE [ARGS]
py-canada-post rating get-service SERVICE-CODE [ARGS]
more to come...
Options:
rating Command to contain all rating-related commands (e.g. get_rates, discover_services etc.). │
--help (-h) Display this message and exit. │
--version (-v) Display application version.
See the CLI documentation to learn more.
Roadmap
-
-
Shipping service
-
Manifest service
-
Customer information services
-
Metadata
Release files for py-canada-post 1.1.2
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 |
|---|---|---|---|---|
| py_canada_post-1.1.2.tar.gz | 407.4 kB | Without provenance | Details for py_canada_post-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_canada_post-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for py_canada_post-1.1.2-py3-none-any.whl |
Total release size: 443.2 kB
Release files / py_canada_post-1.1.2.tar.gz
| Download URL | py_canada_post-1.1.2.tar.gz |
|---|---|
| Size | 407.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab44955968eb9783a0d218d865d49fb58c2e44d33a85f9ad3ad7d519a74a1af0
|
|
BLAKE2b-256 checksum How to use checksums |
7d6ca9ea4ec40fe7783857a286e2229ec4cd2e61c875c348b6eabb3f72cdb760
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / py_canada_post-1.1.2-py3-none-any.whl
| Download URL | py_canada_post-1.1.2-py3-none-any.whl |
|---|---|
| Size | 35.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f51e2e32c5e0a49a668dbea11d639a16bf8447cd87036cbf2a4aef04a7bdf85
|
|
BLAKE2b-256 checksum How to use checksums |
dffa8cd0ea5a3701ce9f85127a93ab45a1235c1687598d4559a87f0405fd4a28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for py-canada-post 1.1.2
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.