Package: pyDHL
pyDHLPython module to work with DHL REST Webservice integration.pyDHL as moduleimport pyDHLBy running it as a module pyDHL will expose the following resources.PackageInputs:weight(Mandatory): Package weightlength(Mandatory): Package lengthwidth(Mandatory): Package widthheight(Mandatory): Package heightprice(Optional): Package pricedescription(Optional): Package descriptionreference(Optional): Package referencefrom pyDHL import Package

package = Package(
        weight=<package_weight>,
        length=<package_length>,
        width=<package_width>,
        height=<package_height>
    )]PersonA person is a combination of a Contact and Address information. This class is used for both sender and recipient of the the package.Rate request just needs shipment's Address.AddressInputs:street_lines(Mandatory): Person's address first linecity(Mandatory): Person's citypostal_code(Mandatory): Person's postal codecountry(Mandatory): Person's country, Must oblige to the DHL's country codes.street_lines2(Optional): Person's address second line.'N/A'by default.street_lines3(Optional): Person's address third line.ContactInputs:name(Mandatory): Person's namephone(Mandatory): Person's phoneemail(Optional): Person's email.'null'by defaultcompany(Optional): Person's company.nameby defaultShipmentMandatory inputs:packages: A list of Packagesenderandrecipient: Persons (or Address in rate request)In order to build a correct Shipment, please refer to the documentation. Some parameters are set by default and others such asSERVICE_TYPEare set following
a set of conditions and properties of the Shipment itself.RequestsAll requests will have as input a valid Shipment object or a dict or dict-like structure.In order to send requests to DHL Webservices you must first set credentials:from pyDHL import requests

credentials = {
  'account':  # your account number
  'username':  # your username
  'password':  # your password
}

requests.set_credentials(credentials)Optionally it is possible to set the 'sandbox' environment for testing purposes.requests.set_sandbox([True|False])  # use DHL's sandbox endpointsThe result of every request is either the JSON response of the DHL endpoint or, if the requests was wrong, a JSON-like object if twitherrorandmessagekeys describing the error.Every requests will update the shipment object given by input if the request was successful.Rate RequestRate Request will return DHL’s product capabilities (products, services and estimated delivery time) and prices (where applicable) for a certain set of input data.Input: ShipmentOutput: JSON response. DHL Rate Requestfrom pyDHL.requests import rate

# create a valid shipment
response = rate(shipment)Shipment RequestThe key elements in the response of the Shipment Request will be a base64 encoded PDF label and the Shipment and Piece identification numbers, which you can use for tracking on the DHL web site.Input: ShipmentOutput: JSON response. DHL Shipment Requestfrom pyDHL.requests import shipment

# create a valid shipment
response = shipment(shipment)Update RequestThe updateShipment request allows for additional pieces to be added to a previously created shipment that has not been picked up by DHL Express/had a scan against it.Input: ShipmentOutput: JSON response. DHL Update Requestfrom pyDHL.requests import update

# create a valid shipment
response = update(shipment)Tracking RequestThe resulting response will provide tracking events at both the Shipment and/or Piece events corresponding to the DHL Waybill(s) submitted.Input: ShipmentOutput: JSON response. DHL Tracking Requestfrom pyDHL.requests import tracking

# create a valid shipment
response = tracking(shipment.id, level=[TRACKING_LAST|TRACKING_ALL])pyDHL's Command Line interfaceUse pyDHL as a command line program to set up a quick shipmentpyDHL <option> <shipment_file> [mode]OptionsOptions flag gets mapped with each of the available requests:-r RATE, --rate RATE: Rate Request will return DHL’s product capabilities (products, services and estimated delivery time) and prices (where applicable) for a certain set of input data.-s SHIPMENT, --shipment SHIPMENT: The key elements in the response of the Shipment Request will be a base64 encoded PDF label and the Shipment and Piece identification numbers, which you can use for tracking on the DHL web site.-u UPDATE, --update UPDATE: The updateShipment request allows for additional pieces to be added to a previously created shipment that has not been picked up by DHL Express/had a scan against it.-t TRACK, --track TRACK: The resulting response will provide tracking events at both the Shipment and/or Piece events corresponding to the submitted DHL Waybill (Shipment id).-p PICKUP, --pickup PICKUP: The requestPickup request allows users to request standalone pickup requests for local and remote/import pickups.-o OUTPUT, --output OUTPUT: Output File--sandbox: Set sandbox modeShipment FileFollowing every option there is a shipment file. This is a file that contains all necessary data to build and send requests to DHL. There is an example inshipment.json.ModeBy defaultpyDHLwill use DHL endpoints that will execute real shipments
and other actions. For testing purposes and development there is a "sandbox" mode
that can be activated by adding-snd|--sandboxat the end of the commandTestingIn order to a successful testing, please edittests/config.pyfile with valid
DHL credentials for accessing HTTPS endpoints.pyDHL uses pytest and coverage to execute tests and to check if everything was correctly executed.coverage run -m pytestTests are separated between different kinds of shipments available:National: Shipments with origin and source in the same country.EU: Shipments coming from an country in Europe and with destination to a country in Europe.International: None of the cases above.