Skip to main content

Itella SmartPost API wrapper for humans 📦

Project description

aiosmartpost - Itella SmartPost NEW API wrapper for humans 📦

WORK IN PROGRESS! NOT READY FOR PRODUCTION USE

Official NEW SmartPost API Docs

This solution:

  • has both async and sync API
  • has 100% type-annotated code
  • is tested in real-world project in Estonia

Quickstart

Examples use async version of Client. At the moment sync version is not implemented for new API.

Fetch list of available Estonian destinations:

>>> from smartpost import Client
>>> client = Client("API-...-KEY")
>>> await client.get_ee_terminals()
[Place(place_id='01007225', name='Tallinna Arsenali Keskus', city='Tallinn', ...), ...]

Add new shipment order and get A5 PDF with label for it:

>>> from smartpost import Client
>>> from smartpost.errors import ShipmentOrderError
>>> from smartpost.models import Recipient, EETerminalDestination, ShipmentOrder
>>> client = Client("API-...-KEY")
>>> order_id = 547
>>> order = ShipmentOrder(
>>>     source={"country": "ee"},
>>>     recipient={"name": "John Doe", "phone": "+358400953521", "email": "client-mail@example.org"},
>>>     destination={"country": "ee", "place_id" : '01007225'},
>>>     additionalservices={"labelprinted": True},
>>>     reference=str(order_id)
>>> )
>>> try:
>>>     new_orders = await client.add_shipment_orders([order], ["report-email@example.org"])
>>> except ShipmentOrderError as exc:
>>>     print("Failed to add shipment order:")
>>>     for error_details in exc.errors:
>>>         print(f"Order #{error_details['reference']} error: {str(error_details)}")
>>>
>>>     raise
>>>
>>> new_orders
[Order(barcode='XXXXXXXXXXXXXXXX', reference=None, sender=None)]


>>> pdf_bytes = await client.get_labels_pdf("A5", [new_orders[0].barcode])
>>> with open("/tmp/test.pdf", "wb") as file:
...   file.write(pdf_bytes)
... 
57226

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aiosmartpost-0.4.0b1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file aiosmartpost-0.4.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiosmartpost-0.4.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 e29334f72795434a2c6955215c0b37b7e99941c566029c18adda7ba53876b59c
MD5 dfd0a0466c301aec198a7d7e9b45342b
BLAKE2b-256 ad8197ed8391ba03191a94ea50e02a8d1c559ac3fe767d17fe1d43530f5078b1

See more details on using hashes here.

Supported by

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