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.0b2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for aiosmartpost-0.4.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 82b9ab91832750037c381aeb88805c8eeb126e9155339c15f414bb171a6878ce
MD5 7c455f5fa503fd8e1508de89b65587d1
BLAKE2b-256 591a415d40dc0d94c8d3bd568fefcf545baefa08abe3af8864401389f2b220c6

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