Skip to main content

Multi-carrier shipping API integration with python

Project description

purplship

purplship - The Open Source multi-carrier shipping SDK

CI License: LGPL v3 Code style: black

puprlship is a modern development kit that simplifies the integration of shipping carriers services into an app.

The key features are:

  • Unified API: A standardized set of models representing the common shipping data (Address, Parcel, Shipment...)
  • Intuitive API: A library that abstracts and unifies the typical shipping API services (Rating, Shipping, Tracking...)
  • Multi-carrier: Integrate purplship once and connect to multiple shipping carrier APIs
  • Custom carrier: A framework to integrate a shipping carrier services within hours instead of months

For a complete shipping management REST API with a dashboard checkout purplship-server.

Requirements

Python 3.7+

Installation

# install purplship core
pip install purplship

# install the purplship canadapost extention
pip install purplship.canadapost

Additional extensions:

Available carriers
  • purplship.aramex
  • purplship.australiapost
  • purplship.canadapost
  • purplship.canpar
  • purplship.dhl-express
  • purplship.dhl-universal
  • purplship.dicom
  • purplship.fedex
  • purplship.purolator
  • purplship.royalmail
  • purplship.sendle
  • purplship.sf-express
  • purplship.tnt
  • purplship.ups
  • purplship.usps
  • purplship.usps-international
  • purplship.yanwen
  • purplship.yunexpress

Usage

  • Fetch shipping rates
import purplship
from purplship.core.models import Address, Parcel, RateRequest
from purplship.mappers.canadapost.settings import Settings


# Initialize a carrier gateway
canadapost = purplship.gateway["canadapost"].create(
    Settings(
        username="6e93d53968881714",
        password="0bfa9fcb9853d1f51ee57a",
        customer_number="2004381",
        contract_id="42708517",
        test=True
    )
)

# Fetching shipment rates

# Provide the shipper's address
shipper = Address(
    postal_code="V6M2V9",
    city="Vancouver",
    country_code="CA",
    state_code="BC",
    address_line1="5840 Oak St"
)

# Provide the recipient's address
recipient = Address(
    postal_code="E1C4Z8",
    city="Moncton",
    country_code="CA",
    state_code="NB",
    residential=False,
    address_line1="125 Church St"
)

# Specify your package dimensions and weight
parcel = Parcel(
    height=3.0,
    length=6.0,
    width=3.0,
    weight=0.5,
    weight_unit='KG',
    dimension_unit='CM'
)

# Prepare a rate request
rate_request = RateRequest(
    shipper=shipper,
    recipient=recipient,
    parcels=[parcel],
    services=["canadapost_xpresspost"],
)

# Send a rate request using a carrier gateway
response = purplship.Rating.fetch(rate_request).from_(canadapost)

# Parse the returned response
rates, messages = response.parse()

print(rates)
# [
#     RateDetails(
#         carrier_name="canadapost",
#         carrier_id="canadapost",
#         currency="CAD",
#         transit_days=2,
#         service="canadapost_xpresspost",
#         discount=1.38,
#         base_charge=12.26,
#         total_charge=13.64,
#         duties_and_taxes=0.0,
#         extra_charges=[
#             ChargeDetails(name="Automation discount", amount=-0.37, currency="CAD"),
#             ChargeDetails(name="Fuel surcharge", amount=1.75, currency="CAD"),
#         ],
#         meta=None,
#         id=None,
#     )
# ]

Resources

Contributing

We encourage you to contribute to puprlship! Please check out the Contributing to purplship guide for guidelines about how to proceed. Join the purplship discord channel!

Do you want to extend purplship and integrate a custom carrier, check out Extending purplship

License

This project is licensed under the terms of the LGPL v3 license. Please see LICENSE.md for licensing details.

Authors

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

If you're not sure about the file name format, learn more about wheel file names.

purplship-2021.8-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file purplship-2021.8-py3-none-any.whl.

File metadata

  • Download URL: purplship-2021.8-py3-none-any.whl
  • Upload date:
  • Size: 36.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.6

File hashes

Hashes for purplship-2021.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9bca1d7fb09c4fa9562bc1b702d01256e8d788938b55362323381433f5e29445
MD5 40b631f7a6cc5204cb5716ea8279146e
BLAKE2b-256 7f9ec5e27ce9b9dfe0fa44878df2182d75a1dc3af7dbf46a8518c7d433372e18

See more details on using hashes here.

Supported by

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