GithubHelp home page GithubHelp logo

dnplkndll / python-ship Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benweatherman/python-ship

0.0 2.0 0.0 879 KB

A Python interface to common shipping APIs (UPS, USPS, FedEx)

Python 100.00%

python-ship's Introduction

This is my extremely early version of providing a shipment API in Python.

UPS: Ground shipping almost complete USPS: Rate query complete, delivery confirmation almost complete FedEx: Not implemented

ups_config and fedex_config dictionaries:

  fedex_config = {
    'meter_number': 'FedEx Meter Number', 
    'password': 'FedEx API password', 
    'account_number': 'FedEx Account Number', 
    'key': 'FedEx API Key'
  }
     
  ups_config = {
    'username': 'UPS Online Username',
    'password': 'UPS Online Password', 
    'shipper_number': 'UPS Shipper Number',
    'access_license': 'UPS API License'
  }

USPS Domestic Shipping Rate Example

The USPS module uses Endicia to calculate shipping rates and generate labels. For this example, we'll need to import the Package and Endicia classes from the endicia module and the Address class from the shipping module:

from endicia import Package, Endicia
from shipping import Address

To calculate shipping or generate a label, you have to first create a Package object:

# Separate variables for the sake of clarity.
mail_class = Package.shipment_types[0] # "Priority"
weight_in_oz = 20
packaging_shape = Package.shapes[1] # "MediumFlatRateBox"
length = 10 # inches
width = 10 # inches
height = 10 # inches

package = Package(mail_class, weight_in_oz, packaging_shape, length, width, height)

You also need to create Address objects to represent the address you are shipping from and the address you are shipping to:

shipper = Address('Microsoft', "1 157th Ave NE", 'Redmond', 'WA', 98052, 'US')
recipient = Address("Apple", "1 Infinite Loop", 'Cupertino', 'CA', 95014, 'US')

And finally, you need to create an Endicia object and pass your authentication info, package, and addresses to it:

api = Endicia({
    "partner_id": "<your partner ID goes here>",
    "account_id": "000000", # Your account ID. Has to be a six-digit value.
    "passphrase": "<your passphrase goes here>"
})

Then you are free to call whatever API functions on the Endicia object you like. In this example, we want the rate function:

shipping_rate = api.rate([package], package.shape, shipper, recipient, debug=True) 

Which should put something like this in shipping_rate:

{
    'status': 0,
    'info': [
        {
            'delivery_day': '', 
            'cost': 11.3, 
            'service': Priority Mail Medium Flat Rate Box,
            'package': Priority
        },
        {
            'delivery_day': '',
            'cost': 39.95,
            'service': Priority Mail Express Flat Rate Box,
            'package': Express
        }
    ]
}

python-ship's People

Contributors

benweatherman avatar htristan avatar r3dfish avatar tedshroyer avatar winkervsbecks avatar

Watchers

 avatar  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.