没有sqlite美国zipcode验证python包,可以在aws lambda中使用
zipcodes的Python项目详细描述
邮政编码
python(2和3)的轻量级美国邮政编码验证包。 这个包是作为 zipcode提供的太多 功能并依赖于sqlite3,这在 平台,如aws lambda。而增加额外的 邮政编码,这个包提供邮政编码的基本功能 具有较少依赖性和最小工作逻辑的验证。
欢迎投稿!
安装
$ pip install zipcodes
概要
下面是这个包的预期用途以及 支持的功能。
>>>frompprintimportpprint>>>importzipcodes>>># Simple zip-code matching.>>>pprint(zipcodes.matching('77429'))[{'zip_code':'77429','zip_code_type':'STANDARD','city':'CYPRESS','state':'TX','lat':29.96,'long':-95.69,'world_region':'NA','country':'US','active':True}]>>># Handles of Zip+4 zip-codes nicely. :)>>>pprint(zipcodes.matching('77429-1145'))[{'zip_code':'77429','zip_code_type':'STANDARD','city':'CYPRESS','state':'TX','lat':29.96,'long':-95.69,'world_region':'NA','country':'US','active':True}]>>># Will try to handle invalid zip-codes gracefully...>>>print(zipcodes.matching('06463'))[]>>># Until it cannot.>>>zipcodes.matching('0646a')Traceback(mostrecentcalllast):...TypeError:Invalidcharacters,zipcodemayonlycontaindigitsand"-".>>>zipcodes.matching('064690')Traceback(mostrecentcalllast):...TypeError:Invalidformat,zipcodemustbeoftheformat:"#####"or"#####-####">>>zipcodes.matching(None)Traceback(mostrecentcalllast):...TypeError:Invalidtype,zipcodemustbeastring.>>># Whether the zip-code exists within the database.>>>print(zipcodes.is_real('06463'))False>>># How handy!>>>print(zipcodes.is_real('06469'))True>>># Search for zipcodes that begin with a pattern.>>>pprint(zipcodes.similar_to('0643'))[{'active':True,'city':'GUILFORD','country':'US','lat':41.28,'long':-72.67,'state':'CT','world_region':'NA','zip_code':'06437','zip_code_type':'STANDARD'},{'active':True,'city':'HADDAM','country':'US','lat':41.45,'long':-72.5,'state':'CT','world_region':'NA','zip_code':'06438','zip_code_type':'STANDARD'},...# remaining results truncated for readability...]>>># Use filter_by to filter a list of zip-codes by specific attribute->value pairs.>>>pprint(zipcodes.filter_by(city="WINDSOR",state="CT"))[{"zip_code":"06006","zip_code_type":"UNIQUE","city":"WINDSOR","state":"CT","lat":41.85,"long":-72.65,"world_region":"NA","country":"US","active":True},{"zip_code":"06095","zip_code_type":"STANDARD","city":"WINDSOR","state":"CT","lat":41.85,"long":-72.65,"world_region":"NA","country":"US","active":True},],>>># Arbitrary nesting of similar_to and filter_by calls, allowing for great precision while filtering.>>>pprint(zipcodes.similar_to('2',zips=zipcodes.filter_by(active=True,city='WINDSOR')))[{'active':True,'city':'WINDSOR','country':'US','lat':33.48,'long':-81.51,'state':'SC','world_region':'NA','zip_code':'29856','zip_code_type':'STANDARD'},{'active':True,'city':'WINDSOR','country':'US','lat':36.8,'long':-76.73,'state':'VA','world_region':'NA','zip_code':'23487','zip_code_type':'STANDARD'},{'active':True,'city':'WINDSOR','country':'US','lat':36.0,'long':-76.94,'state':'NC','world_region':'NA','zip_code':'27983','zip_code_type':'STANDARD'}]>>># Have any other ideas? Make a pull request and start contributing today!>>># Made with love by Sean Pianka