顺丰 Python SDK
基于顺丰官网开放平台2.0 API开发的Python SDK
版本:2.1.0.0
功能概述
目前已经开发完成的接口列表:
- 下订单接口
- 订单确认/取消接口-速运类API
- 订单结果查询接口
- 路由查询接口接口-速运类API
- 订单筛选接口-速运类API
- 时效标准及价格查询接口-速运类API
- 产品推荐接口-速运类API
- 预估总费用接口-国际件API
- 清单运费查询接口-速运类API
其他接口正在陆续对接中...
安装
pip install sf-sdk
使用示例
clientcode和checkword是在顺丰官网注册后得到的用户编码和校验码
from sf.api import SF
sf = SF("clientcode","checkword")
sf.order.create_order(clientid,..)
下单
contacts = []
sender = ContactInfo("北京市昌平区回龙观天慧园",company="测试公司",mobile="18512345678",contactType=1)
receiver = ContactInfo("北京市海淀区新中关大厦A座",company="新东方",mobile="18511223344",contactType=2)
contacts.append(sender)
contacts.append(receiver)
cargo_detail = CargoDetail("测试货物")
res = self.sf.order.create_order(self.order_no, contacts,[cargo_detail])
订单查询
res = self.sf.order.get_order(self.order_no)
确认/取消订单
res = self.sf.order.confirm_order(self.order_no, dealType=2)
路由信息
res = self.sf.order.get_route_info(self.order_no)
判断是否可以派单
res = self.sf.order.can_delivery(self.order_no)
打印电子面单
res = self.sf.order.get_order(self.order_no)
documents = [
{
"masterWaybillNo": res['msgData']['waybillNoInfoList'][0]['waybillNo'],
}
]
res = self.sf.sheet.sync_print(f"fm_150_standard_QXH",documents)
产品推荐与预估费用
产品推荐接口需要先开通 EXP_RECE_PSDS_PRODUCT_RECOMMEND 权限。返回值中的
msgData.productList 会包含 totalFee、currency 和 serviceFeeList;其中
燃油附加费的服务代码为 IN15。
res = sf.order.recommend_products(
srcProvince="香港",
srcCity="香港",
destProvince="澳门",
destCity="澳门",
sendTime="2026-09-04 12:00:00",
weight=1,
paymentTerms="1",
srcAddress="香港葵涌永建路",
destAddress="澳门半岛南湾大马路",
monthlyCard="your-monthly-card",
commodityNameList=["文件"],
)
国际件预估总费用接口会返回 currency、totalFee 和 feeInfoList,需要单独
申请对应的国际接口权限。
res = sf.order.estimate_total_fee(
customerCode="your-international-customer-code",
interProductCode="INT0001",
senderInfo={"country": "HK", "postCode": "999077", "address": "Kwai Chung"},
receiverInfo={"country": "MO", "postCode": "999078", "address": "Macau"},
parcelQuantity=1,
parcelTotalWeight=1,
)
清单运费查询
trackingType 为 1 时按客户订单号查询,为 2 时按顺丰运单号查询。
返回值中的 msgData.waybillFeeList 是实际费用明细,燃油附加费的费用类型为
14。
res = sf.order.query_waybill_fee(
trackingType=2,
trackingNum="SF1234567890",
)
沙箱联调
实时沙箱测试默认跳过。需要运行时通过环境变量提供凭据,凭据不会写入代码:
export SF_SANDBOX_CLIENT_CODE="your-client-code"
export SF_SANDBOX_CHECKWORD="your-checkword"
pytest
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sf_sdk-2.1.0.0.tar.gz.
File metadata
- Download URL: sf_sdk-2.1.0.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f70570075ff3e5ade678a526dc491867fd2c58c70ff39b111eb1364ef3fba616
|
|
| MD5 |
96c9e5421861c974f7754120b6ae6c40
|
|
| BLAKE2b-256 |
90ed7b8564ed5199641357a24b522ff09b29c73d8627980c450626b6012bc473
|
File details
Details for the file sf_sdk-2.1.0.0-py3-none-any.whl.
File metadata
- Download URL: sf_sdk-2.1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/4.0.2 CPython/3.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b7ee98e15ad5b7230f4e84f4b64d37e4cab8992845a7b742573e97fb69e5c9b
|
|
| MD5 |
6f154780f3b8c4154cc11d48b057b591
|
|
| BLAKE2b-256 |
37987a3ef1910a9383e8b54e572d6d85d38bd3eb5ea5ebbd5f4b54e20aaf5d13
|