Skip to main content

SmartShip API

Python library to interact with the Posti SmartShip / Unifaun Online API.

TODO

  • Docs

  • Implement remaining attributes in Shipment as per schema

  • Add logging where necessary

Compatibility

  • Python 2.7+ or Python 3.4+

Usage

Creating shipments

This API supports the Smartship Shipments api for creating shipments and then downloading the generated PDF’s.

Carriers

There are methods for certain carriers like Posti to cover more common use cases. To create a shipment for the Posti carrier, for example:

from smartship.carriers.posti import create_shipment
receiver = {
    "name": "Anders Innovations",
    "city": "Helsinki",
    "country": "FI",
    "address1": "Iso Roobertinkatu 20-22",
    "zipcode": "00120"
}
sender = {
    "quickId": "1",
}
agent = {
    "quickId": "2",
}
shipment = create_shipment(
    "12345",  # Posti customer number
    "PO2102",  # Service ID
    receiver,
    sender,
    [{"copies": 1}],  # Parcels
    agent=agent,  # Optional pickup point
    pdf_config=pdf_config,  # Optional custom PDF config
 )

See more documentation in smartship.carriers.posti module.

PDF Config

If you want to pass a custom pdf_config, it should have the following structure:

{
"target1Media": "laser-a5",
"target1YOffset": 0,
"target1XOffset": 0
}

With "target1Media" being one of the following options:

"laser-a5"
"laser-2a5"
"laser-ste"
"thermo-se"
"thermo-225"

You can customize the offset with "target1YOffset" and "target1XOffset" parameters.

Client

To send shipments and use other API resources, you need a client. Initialize the client as follows with username and secret tokens. Create your API tokens in the Unifaun Online portal.

from smartship import Client
client = Client("username", "secret")

Sending shipments

Send a shipment as follows:

response = client.send_shipment(shipment)

Response will be a special ShipmentResponse wrapping a HttpResponse object with response code and JSON content in response.data.

Status codes:

  • 201 - Shipment was created OK

  • 422 - Validation error with the data. Raises a ShipmentResponseError.

For errors see error.response.json() for details from Unifaun Online API.

Shipment address PDF slips

Once you have the response retrieve associated PDF data as follows:

data = response.get_pdfs(client)  # Client needed in case of additional fetching
pdf_data = data[0][0]  # Simplest case with a single shipment with a single parcel

Agents

Retrieve a list of agents (pickup points) as follows:

agents = client.get_agents("FI", "ITELLASP", "Iso Roobertinkatu 20-22", "00120")

Response will be an Agents object that can be iterated over for individual agent data.

Locations

As the above agents method is a paid service we also provide an interface to the Posti location service API.

from smartship.carriers.posti import get_locations
locations = get_locations(country_code="FI", zipcode="00120")

Response will be a Locations object that can be iterated over for individual location data.

Advanced usage

See full Smartship API documentation for a full list of attributes that shipments can be given. All of these are supported when using smartship.shipments.Shipment directly. Import the relevant objects from smartship.objects and pass them to the Shipment object.

Development

Requirements

Install the requirements to a virtual environment with:

pip install -U setuptools pip  # These should be up to date
pip install -r requirements-dev.txt

Tests

To test in the current virtual environment, run:

py.test

To check the coding style, run:

flake8

To test all supported environments, run:

tox

Building documentation

Build the documentation with:

sphinx-build -b html docs docs/_build

Metadata

Release files for smartship 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smartship 2.0.0
File Size Uploaded Provenance Actions
smartship-2.0.0.tar.gz 17.0 kB Without provenance Details for smartship-2.0.0.tar.gz

Release files / smartship-2.0.0.tar.gz

Download URL smartship-2.0.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
552325f3bd5383464e416591412803dda4efb21d070a27427accafd50e07dbca
BLAKE2b-256 checksum
How to use checksums
3d66027618b8a358f443feb3a898870df706402da6b40b2ba54923ff23f21b94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.7

Security for smartship 2.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page