Coder Social home page Coder Social logo

python-canada-post's Introduction

python-canada-post

This package aims to be a python interface to the Canada Post Developer Program REST API (via HTTP Post requests with XML data)

It's a W.I.P. and any and all contributions are welcome.

Usage

Example usage

from canada_post import api, DEV, PROD
from canada_post.util.parcel import Parcel
from canada_post.util.address import Origin, Destination
cpa = api.CanadaPostAPI(customer_number, api_username, api_password,
                        contract_number, dev=DEV if DEBUG else PROD)
parcel = Parcel(weight=2, length=100, width=60, height=30)
origin = Origin(province=myprovince, address=myaddress, phone=myphone,
                        city=mycity,  postal_code=myposcode, company=company_name)
dest =  Destination(country_code=dest_code, postal_code=dest_pc, province=dest_prov,
                            city=dest_city, address=dest_address)
services = cpa.get_rates(parcel, origin, dest)
# this returns a list of Service objects, with a bunch of data, say you select the one you want
#  from the list somehow
service = select_service(services)
# group_name is a string, it creates a shipment group, the whole group gets sent together,
#  so if you need to send a bunch of parcels together, pass the same string as the group param
shipment = cpa.create_shipment(parcel, origin, dest, service, group_name)
print shipment.id, shipment.status, shipment.tracking_pin
print shipment.links['label']

Plese notice that the API is less than stable yet (for example, the create_shipment interface that's been implemented is just for the Contract Shipment service, so it should probably be under a sublayer something like cpa.contract.create_shipment).

The links object is a dict of

rel -> { 'href':...,
         'index':...,
         'rel':...,
         'media-type':...
       }

(it could be different depending on the rel, see the response part of https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/shippingmanifest/createshipment.jsf for details). A better solution for this might be created in the near future, I'll try to be very clear about any changes.

Changelog

  • 0.0.3-2: Changed name from create_shipping to create_shipment
  • 0.0.4: created void_shipment service for contract shipping
  • 0.0.4-1: bugfixes: error on super() call, and change VoidOrder's request method to DELETE

python-canada-post's People

Contributors

lacrymology avatar iiijjjii avatar scasagrande avatar merwok avatar rcrossf avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.