Package: smartship
Python library to interact with the Posti SmartShip / Unifaun Online API.TODODocsImplement remaining attributes in Shipment as per schemaAdd logging where necessaryCompatibilityPython 2.7+ or Python 3.4+UsageCreating shipmentsThis API supports the Smartship Shipments api for creating shipments and
then downloading the generated PDF’s.CarriersThere are methods for certain carriers like Posti to cover more common use
cases. To create a shipment for the Posti carrier, for example:fromsmartship.carriers.postiimportcreate_shipmentreceiver={"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 IDreceiver,sender,[{"copies":1}],# Parcelsagent=agent,# Optional pickup pointpdf_config=pdf_config,# Optional custom PDF config)See more documentation insmartship.carriers.postimodule.PDF ConfigIf you want to pass a custompdf_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.ClientTo 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 theUnifaun Online portal.fromsmartshipimportClientclient=Client("username","secret")Sending shipmentsSend a shipment as follows:response=client.send_shipment(shipment)Response will be a specialShipmentResponsewrapping aHttpResponseobject with response code and
JSON content inresponse.data.Status codes:201 - Shipment was created OK422 - Validation error with the data. Raises aShipmentResponseError.For errors seeerror.response.json()for details from Unifaun Online API.Shipment address PDF slipsOnce you have the response retrieve associated PDF data as follows:data=response.get_pdfs(client)# Client needed in case of additional fetchingpdf_data=data[0][0]# Simplest case with a single shipment with a single parcelAgentsRetrieve a list of agents (pickup points) as follows:agents=client.get_agents("FI","ITELLASP","Iso Roobertinkatu 20-22","00120")Response will be anAgentsobject that can be iterated over for individual agent data.LocationsAs the above agents method is a paid service we also provide an interface to the Posti location service API.fromsmartship.carriers.postiimportget_locationslocations=get_locations(country_code="FI",zipcode="00120")Response will be aLocationsobject that can be iterated over for individual location data.Advanced usageSee full SmartshipAPI documentationfor a full list of attributes
that shipments can be given.  All of these are supported when usingsmartship.shipments.Shipmentdirectly.  Import the relevant objects
fromsmartship.objectsand pass them to theShipmentobject.DevelopmentRequirementsInstall the requirements to a virtual environment with:pip install -U setuptools pip  # These should be up to date
pip install -r requirements-dev.txtTestsTo test in the current virtual environment, run:py.testTo check the coding style, run:flake8To test all supported environments, run:toxBuilding documentationBuild the documentation with:sphinx-build -b html docs docs/_build