I needed mappings of city names to zip codes for a project. When I searched around the 'net, I found a number of companies that would sell that information, or let me subscribe to it on a monthly basis. I didn't want to spend money on something that I thought should be piblic information. And, to be fair, most of them included other almanac information that I didn't need: lat/lon, population, county, etc.
It also turns out that the US Post Office, which obviously has all this information electronically, does not make it available to the public as a collection. Rather, they have a web-based form that will let you query a given city name or zip code. In their FAQ, they state that:
ZIP+4 Look-Up is intended for interactive use, not automated script processing. Although we do not intend to impose a limit on the number of address inquiries we allow a customer to request in a given session, if we determine that our open-access policy is being abused or overburdened, we will have to review it. Regardless, we do not intend to offer batch processing capabilities via this service.(http://www.usps.com/ncsc/lookups/zip_faqs.htm#a1, as of 27 April 2002).
As I read it, this is not an explicit restriction on the gathering of zip codes via a script. Just a request to do it responsibly.
To that end, I will cull data monthly, and make it available here, until such time that I am told that this is not acceptable. I figure that, as a taxpayer, I paid for these numbers to be generated -- I shouldn't have to pay twice if I want to use them!
Clicking the link below will take you to a directory of snagged files. There are two kinds of files: Preferred Zips, which contain only the officially designated city names for a given zip ("Preferred name" in the Post Office parlance), and All Zips, which contain all of the acceptable city names for a given zip code. Interestingly, the Post Office lists names which are not acceptable for a given zip code -- restricting this list to the common errors, one assumes. The file type can be identified by whether the name begins with "SnaggedZipsPreferredOnly" or "SnaggedZips".
The files are further identified by the date they were harvested, using the format YYYY-MM-DD-HHMMSS.
The files are GZIPed to reduce file size for transfer.
Internally, the files are tab-delimited text files with the following format:
| Zip Code | City Name | State Code | Code |
| Home | Art Terrorism | Poetic Justice | Ravings | Technology | Schwag |