forked from SwoopSearch/pyaddress
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME
127 lines (77 loc) · 4.08 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
address
=========
address is an address parsing library, taking the guesswork out of using addresses in your applications. We use it as part of our apartment search and apartment spider applications.
Installation
------------
`pip install address`
Example
-------
First, we create an AddressParser. AddressParser allows us to feed in lists of cities, streets, and address suffixes. Then we call
parse_address on our address string, which returns an Address instance with all the attributes filled out. From there, we can
print parts of the address, change them, validate them, create a database model to store them, or anything else.
```python
from address import AddressParser, Address
ap = AddressParser()
address = ap.parse_address('123 West Mifflin Street, Madison, WI, 53703')
print "Address is: {0} {1} {2} {3}".format(address.house_number, address.street_prefix, address.street, address.street_suffix)
> Address is: 123 W. Mifflin St.
```
AddressParser
-------------
`AddressParser(self, suffixes=None, cities=None, streets=None)`
suffixes, cities, and streets all accept lists as arguments. If you leave them as none, they will read default files
from the package, namely suffixes.csv, cities.csv, and streets.csv. Streets is intentionally blank.
You can provide lists of acceptable suffixes, cities, and streets to lower your false positives. If you know all
the addresses you are processing are in a small area, you can provide a list of the cities in the area and should
get more accurate results. If you are only doing one city, you could provide that single city in a list, and a list
of all streets in that city.
Address
-------
Addresses get returned by AddressParser.parser_address(). They have the following attributes:
`house_number`
The number on a house. This is required for all valid addresses. E.g. __123__ W. Mifflin St.
`street_prefix`
The direction before the street name. Always represented as one or two letters followed by a period. Not required.
E.g. 123 __W.__ Mifflin St.
`street`
The name of the street. Potentially multiple words. This is required for a valid address. E.g. 123 W. __Mifflin__ St.
`street_suffix`
The ending of a street. This will always be the USPS abbreviation followed by a period. Not required, but highly recommended.
E.g. 123 W. Mifflin __St.__
`apartment`
Apartment number or unit style or any number of things signifying a specific part of an address. Not required. E.g. 123
W. Mifflin St. __Apt 10__
`buiding`
Sometimes addresses are grouped into buildings, or are more commonly known as by building names. Not required, and often
in parathenses. E.g. 123 W. Mifflin St. Apt 10 __(The Estates)__
`city`
The city part of the address, preferably following a comma. E.g. 123 W. Mifflin St., __Madison__, WI 53703
`state`
The state of the address, preferably following the city and a comma. Always two capitalized letters. E.g. 123 W. Mifflin St., Madison, __WI__ 53703
`zip`
The 5 or 9 digit zip code of the address, preferably following the state. Supported 9 digit zips format is (xxxxx-xxxx). E.g. 123 W. Mifflin St., Madison, WI __53703__
`full_address()`
Returns a human readable version of the address for display. Follows the same style rules as the above attributes.
Example return: (The Estates) 123 W. Mifflin St. Apt 10, Madison, WI 53703
Todo
----
* Add verification of an address through Google Maps API, given an API key.
* Allow custom validation conditions in AddressParser for what counts as a correct address or not.
* Add exceptions for incorrect addresses instead of silent failing and letting user validate.
1.2
----
* Added handling of 9 digit zip codes
* Updated city database to National Weather Service file from 8 August 2012
* Forked original address repository and continuing work at https://github.com/pcsforeducation/pyaddress
GitHub
------
File support requests and obtain the source from https://github.com/pcsforeducation/pyaddress
Authors
-------
* Josh Gachnang
* Rob Jauquet
License and Copyright
-------
Copyright (c) 2013 Swoop Search LLC.
Copyright (c) 2013, Josh Gachnang.
This library is released under the New BSD License.