跳转到主要内容

查询邮政编码和位置数据

项目描述

简介

本包将允许您获取邮政编码信息。本包使用的数据可从https://web.archive.org/web/20101126192032/http://pablotron.org/files/zipcodes-csv-10-Aug-2004.zip

pyzipcode 使用本地sqlite数据库运行。您可以通过一些努力用您自己的其他存储机制替换它。

以下是基本用法...

>>> from pyzipcode import ZipCodeDatabase
>>> zcdb = ZipCodeDatabase()

>>> zcdb[54115]
ZipCode(zip='54115', city='De Pere', state='WI', longitude=-88.07896, latitude=44.42042, timezone=-6, dst=1)
>>> zcdb[210]
ZipCode(zip='00210', city='Portsmouth', state='NH', longitude=-71.013202, latitude=43.005895, timezone=-5, dst=1)

搜索邮政编码...

>>> from pyzipcode import ZipCodeDatabase
>>> zcdb = ZipCodeDatabase()
>>> len(zcdb.find_zip(city="Oshkosh"))
7
>>> len(zcdb.find_zip(city="O%"))  # all cities starting with "O" using SQL wildcard
60
>>> len(zcdb.find_zip(city="Doesn't Exist"))  # returns None
>>> 

获取围绕邮政编码半径的邮政编码列表(这实际上搜索的是一个正方形区域)

>>> from pyzipcode import ZipCodeDatabase
>>> zcdb = ZipCodeDatabase()
>>> [z.zip for z in zcdb.get_zipcodes_around_radius('54901', 10)]
['54901', '54902', '54903', '54904', '54906', '54927', '54952', '54956', '54957', '54979', '54985']

数据

以下是从 zipcodes-csv-10-Aug-2004.zip 的原始README文件

CivicSpace US ZIP Code Database
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
written by Schuyler Erle <schuyler@geocoder.us>
5 August 2004

corrected total count and removed sql table definition
Neil Drumm <neil@civicspacelabs.org>
10 August 2004

The ZIP code database contained in 'zipcode.csv' contains 43191 ZIP
codes for the continetal United States, Alaska, Hawaii, Puerto Rico,
and American Samoa. The database is in comma separated value format,
with columns for ZIP code, city, state, latitude, longitude, timezone
(offset from GMT), and daylight savings time flag (1 if DST is observed
in this ZIP code and 0 if not).

This database was composed using ZIP code gazetteers from the US Census
Bureau from 1999 and 2000, augmented with additional ZIP code information
from the Census Bureau's TIGER/Line 2003 data set. Timezone information
was added using cartographic data sets from nationalatlas.gov. The
database is guaranteed to exclusively contain information gathered from
sources in the public domain, and thus be legal to redistribute.

The database is believed to contain over 98% of the ZIP Codes in current
use in the United States. The remaining ZIP Codes absent from this
database are entirely PO Box or Firm ZIP codes added in the last five
years, which are no longer published by the Census Bureau, but in any
event serve a very small minority of the population (probably on the
order of .1% or less). Although every attempt has been made to filter
them out, this data set may contain up to .5% false positives, that is,
ZIP codes that do not exist or are no longer in use but are included due
to erroneous data sources. The latitude and longitude given for each ZIP
code is typically (though not always) the geographic centroid of the ZIP
code; in any event, the location given can generally be expected to lie
somewhere within the ZIP code's "boundaries".

The database andthis README are copyright 2004 CivicSpace Labs, Inc.,
and are published under a Creative Commons Attribution-ShareAlike
license, which requires that all updates must be released under the same
license. See http://creativecommons.org/licenses/by-sa/2.0/ for more
details. Please contact schuyler@geocoder.us if you are interested in
receiving updates to this database as they become available.

-=- 30 -=-

Visit http://civicspacelabs.org/zipcodedb for latest information.

变更日志

3.0.1 (2021-03-03)

  • 修复发布

3.0.0 (2021-03-03)

  • ZipCodeDatabase对象现在表现得像字典

    • 查找不存在的邮政编码会引发KeyError而不是IndexError
    • .get()现在返回一个ZipCode对象,而不是包含一个ZipCode对象的列表
    • 它们现在有len(),可以迭代和反转
    • 它们现在有.keys() .values()和.items()方法
  • 通过传递多个参数(每个值一个参数)而不是元组来创建ZipCode对象

  • 支持查找4位和3位邮政编码作为整数

  • 放弃Python 2支持

    2.0.3(未发布)


  • 尚未有任何变化。

2.0.2 (2021-02-28)

  • 许可证更新

2.0.1 (2021-02-25)

  • 修复未知邮政编码的错误信息[mpcusack]

2.0.0 (2020-04-07)

  • 更新为支持 Python 3 [David Schneider]

    1.0 (2016-01-20)


  • 修复导入代码,使其在导入模块时(例如,在构建 Sphinx API 文档时)不会运行。

  • 将 import.py 模块重命名为 import_zipcode.py,因为 import 是 Python 的保留关键字。

  • 记录 import_zipcode 模块。

    0.4


0.3

  • 使用字符串而不是整数来存储邮编,因为邮编可以以零开头。

0.2

  • 捕获 sqlite 数据库文件读取错误,并在另一个进程同时尝试访问文件时继续尝试。

0.1

  • 首次发布

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分发

pyzipcode-3.0.1.tar.gz (1.9 MB 查看哈希值)

上传时间

支持