蟒蛇对美国经济的影响
pyusps的Python项目详细描述
说明
pyusps是usps电子商务api的pythonic包装。 目前,只支持地址信息api。
安装
使用pip安装:
pip install pyusps
或简易安装:
easy_install pyusps
地址信息API
此API可通过pyusps.address_信息获得。请验证 功能。它接受USPS给你的用户ID 以及要验证的地址的可变长度列表。
请求
每个地址都是一个dict,包含以下必需的键:
address: The street address city: The city state: The state zip_code: The zip code in one the following formats: xxxxx, xxxxx-xxxx, or xxxxxxxxx
只需要一个州或邮政编码
以下键是可选的:
firm_name: The company name, e.g., XYZ Corp. Although the API documentation says this field is required, tests show that it isn’t. address_extended: An apartment, suite number, etc urbanization: For Puerto Rico addresses only
反应
如果请求一个地址,则响应将是dict, 或者一个dict列表,如果请求了多个地址。每个地址 将始终包含以下键:
address: The street address city: The city state: The state zip5: The first five numbers of the zip code zip4: The last four numbers of the zip code
每个地址都可以选择包含以下键:
firm_name: The company name, e.g., XYZ Corp. address_extended: An apartment, suite number, etc urbanization: For Puerto Rico addresses only returntext: Additional information about the address, usually a warning, e.g., “The address you entered was found but more information is needed (such as an apartment, suite, or box number) to match to a specific address.”
公司名称、地址扩展和城市化将返回值 如果API找不到匹配项,则请求。
对于多个地址,地址的顺序 在请求中指定的将保留在响应中。
错误
如果存在一般性错误,将引发ValueError,例如。, 无效的用户ID,或者如果单个地址请求生成错误。 除了一般性错误外,多个地址请求不会引发错误。 相反,如果其中一个地址生成错误,则 valueerror对象与其余结果一起返回。
示例
单一地址请求:
from pyusps import address_information addr = dict([ ('address', '6406 Ivy Lane'), ('city', 'Greenbelt'), ('state', 'MD'), ]) address_information.verify('foo_id', addr) dict([ ('address', '6406 IVY LN'), ('city', 'GREENBELT'), ('state', 'MD'), ('zip5', '20770'), ('zip4', '1441'), ])
多个地址请求:
from pyusps import address_information addrs = [ dict([ ('address', '6406 Ivy Lane'), ('city', 'Greenbelt'), ('state', 'MD'), ]), dict([ ('address', '8 Wildwood Drive'), ('city', 'Old Lyme'), ('state', 'CT'), ]), ] address_information.verify('foo_id', *addrs) [ dict([ ('address', '6406 IVY LN'), ('city', 'GREENBELT'), ('state', 'MD'), ('zip5', '20770'), ('zip4', '1441'), ]), dict([ ('address', '8 WILDWOOD DR'), ('city', 'OLD LYME'), ('state', 'CT'), ('zip5', '06371'), ('zip4', '1844'), ]), ]
多个地址错误:
from pyusps import address_information addrs = [ dict([ ('address', '6406 Ivy Lane'), ('city', 'Greenbelt'), ('state', 'MD'), ]), dict([ ('address', '8 Wildwood Drive'), ('city', 'Old Lyme'), ('state', 'NJ'), ]), ] address_information.verify('foo_id', *addrs) [ dict([ ('address', '6406 IVY LN'), ('city', 'GREENBELT'), ('state', 'MD'), ('zip5', '20770'), ('zip4', '1441'), ]), ValueError('-2147219400: Invalid City. '), ]
参考值
有关地址信息api的更多信息,请访问https://www.usps.com/business/web-tools-apis/address-information-api.htm
开发
外部依赖性
- libxml2-dev
- libxslt1-dev
- build-essential
- python-dev or python3-dev
- python-setuptools or python3-setuptools
- python-virtualenv
设置
要开始开发,请从项目的基础运行以下命令 目录。你可以从 https://github.com/thelinuxkid/pyusps:
# I like to install the virtual environment in a hidden repo. virtualenv .virtual # I leave the magic to Ruby developers (.virtual/bin/activate) .virtual/bin/python setup.py develop # At this point, pyusps will already be in easy-install.pth. # So, pip will not attempt to download it .virtual/bin/pip install pyusps[test]
如果您想使用ipython,可以将其与dev一起安装 要求:
.virtual/bin/pip install pyusps[dev]
测试
要运行单元测试,请从项目的 基本目录:
.virtual/bin/nosetests