python中的可用ups集成
ClassicUPS的Python项目详细描述
Classicups是一个Apache2许可的包装器,用于创建 运送标签并获取包裹的跟踪状态。这个图书馆不是 means包含所有ups功能,但它适用于 最常见的与运输相关的常见任务。
功能
- 跟踪跟踪号的交货状态
- 以gif或epl(热敏打印机)格式创建预付运费标签
安装
安装很简单:
$ pip install ClassicUPS
classicups依赖于libxml2和libxslt。在ubuntu上,包是 libxml2-dev和libxslt-dev。
快速启动
创建upsconnection对象,使您可以访问常见的ups方法:
fromClassicUPSimportUPSConnection# Credentials obtained from the UPS websiteups=UPSConnection(license_number,user_id,password,shipper_number,# Optional if you are not creating a shipmentdebug=True)# Use the UPS sandbox API rather than prod
检查包裹的交货日期。
tracking=ups.tracking_info('1Z12345E0291980793')printtracking.in_transitprinttracking.delivered
创建发货并将发货标签保存为gif文件:
from_addr={'name':'Google','address1':'1600 Amphitheatre Parkway','city':'Mountain View','state':'CA','country':'US','postal_code':'94043','phone':'6502530000'}to_addr={'name':'President','address1':'1600 Pennsylvania Ave','city':'Washington','state':'DC','country':'US','postal_code':'20500','phone':'2024561111'}dimensions={# in inches'length':1,'width':4,'height':9}weight=10# in lbs# Create the shipment. Use file_format='EPL' for a thermal-printer-compatible EPLshipment=ups.create_shipment(from_addr,to_addr,dimensions,weight,file_format='GIF')# Print information about our shipmentprintshipment.costprintshipment.tracking_number# Save the shipping label to print, email, etcshipment.save_label(open('label.gif','wb'))