Python wrapper to interact with Canada Post API.
Project description
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]
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
-
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_canada_post-1.0.1.tar.gz.
File metadata
- Download URL: py_canada_post-1.0.1.tar.gz
- Upload date:
- Size: 403.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
945a3cee57a98872dc032cef98cc45d1596d659212fbe3a6759577d1d993ae2c
|
|
| MD5 |
794a8a34786ae53c7405801ddfaa6bcd
|
|
| BLAKE2b-256 |
254dfe344de8831319a526416daaff8d762f3586589b20fce743f0eb8ac8937e
|
File details
Details for the file py_canada_post-1.0.1-py3-none-any.whl.
File metadata
- Download URL: py_canada_post-1.0.1-py3-none-any.whl
- Upload date:
- Size: 27.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f5a24cb86f3a6b6e478c954530fbe1c928e0ca8a7befd8ff9ae613759df3867
|
|
| MD5 |
1c8b0c024c047dc3e74ace1d8dcaa430
|
|
| BLAKE2b-256 |
208a28d64e92ddcd329a8fffd233e0dca32117be4b9dd75a59e2f7de73d47571
|