用于python的easypost shipping api客户端库
easypost的Python项目详细描述
EasyPost Python客户端库
easypost是简单的装运api。你可以在https://easypost.com注册一个帐户。
要求
正在为另一种语言查找客户端库?签出https://www.easypost.com/docs/libraries。
安装
您可以使用以下命令通过pip安装easypost:
pip install easypost
或者,您可以克隆easypost python客户机存储库:
git clone https://github.com/EasyPost/easypost-python
安装:
python setup.py install
导入EasyPost客户端:
importeasypost
示例
importeasyposteasypost.api_key='<YOUR API KEY FROM https://www.easypost.com/account/api-keys>'# create and verify addressesto_address=easypost.Address.create(verify=["delivery"],name="Dr. Steve Brule",street1="179 N Harbor Dr",street2="",city="Redondo Beach",state="CA",zip="90277",country="US",phone="310-808-5243")from_address=easypost.Address.create(verify=["delivery"],name="EasyPost",street1="118 2nd Street",street2="4th Floor",city="San Francisco",state="CA",zip="94105",country="US",phone="415-456-7890")# create parceltry:parcel=easypost.Parcel.create(predefined_package="Parcel",weight=21.2)excepteasypost.Errorase:print(str(e))ife.paramisnotNone:print('Specifically an invalid param: %r'%e.param)parcel=easypost.Parcel.create(length=10.2,width=7.8,height=4.3,weight=21.2)# create customs_info form for intl shippingcustoms_item=easypost.CustomsItem.create(description="EasyPost t-shirts",hs_tariff_number=123456,origin_country="US",quantity=2,value=96.27,weight=21.1)customs_info=easypost.CustomsInfo.create(customs_certify=1,customs_signer="Hector Hammerfall",contents_type="gift",contents_explanation="",eel_pfc="NOEEI 30.37(a)",non_delivery_option="return",restriction_type="none",restriction_comments="",customs_items=[customs_item])# create shipmentshipment=easypost.Shipment.create(to_address=to_address,from_address=from_address,parcel=parcel,customs_info=customs_info)# buy postage label with one of the rate objectsshipment.buy(rate=shipment.rates[0])# alternatively: shipment.buy(rate = shipment.lowest_rate())print(shipment.tracking_code)print(shipment.postage_label.label_url)# Insure the shipment for the valueshipment.insure(amount=100)print(shipment.insurance)
文件
最新文档位于:https://www.easypost.com/docs
客户端库开发
释放
- 向CHANGELOG.md添加新功能
- 在
VERSION
- 创建git标记
- 用
python setup.py sdist upload
推到pypi
运行测试
运行测试:
- 为您的python版本创建一个virtualenv(例如,
python2.7 -m virtualenv venv
) - 在该虚拟机中安装依赖项(
./venv/bin/pip install requests six
) - 安装测试依赖项(
./venv/bin/pip install -r requirements-tests.txt
) - 使用
py.test
(./venv/bin/py.test -vs tests
)运行测试