Remix.run Logo
pseudosavant 3 days ago

For those that may be interested, this is my project to easily get a list of every zipcode + city/state combo. It is available as JSON you can easily directly work with, or even try a service like this: https://usps-zip-codes.deno.dev/90210.

I have a pet peeve for having to enter my zip code after I've already had to type in the city and state. There wasn't any easily downloadable file that had every ZIP code though. I keep hoping more sites will ask for ZIP first and then just auto fill it using data like this. /wishfulthinking

https://github.com/pseudosavant/usps-zip-codes

stackskipton 3 days ago | parent | next [-]

Someone who deals with this, reason you type in the Zip Code is its rudimentary checksum to make sure someone put in right information.

> There wasn't any easily downloadable file that had every ZIP code though

Post Service says what? https://postalpro.usps.com/ZIP_Locale_Detail (Heads up, it's Excel document)

BrandoElFollito 2 days ago | parent | next [-]

> reason you type in the Zip Code is its rudimentary checksum to make sure someone put in right information.

I did not know you had a checksum in US zipcodes (I am French, oir zip codes are for the most part "region number"+"number that may tell about the importance of the city or carry a completely different meaning".

78000 is Versailles, which would make the city the "most important" city of the 78 "region", one of the ones around Paris.

78140 is another city, and 78142 (a mde up number) would be some internal numbering in the city, usually linked to a post office and usually unknown to the everyday Joe.

How this gets complicated is fascinating.

samtheDamned 15 hours ago | parent [-]

I believe what the OP you replied to meant was that when entering your address in a form, the zip code allows for verification that the address was all entered correctly. Lets say someone wants to buy a book and they put their address in as 154 Broad Street, Philadelphia PA but they actually live in a neighboring county, when they put in their zip code the system will be able to see that the address was slightly incorrect and can be adjusted to ensure a smoother delivery.

I know where I live what "city" you live in can be a complex situation because of unusual classifications of cities compared to the rest of the country so I can see this being a useful system to have.

BrandoElFollito 12 hours ago | parent [-]

Ah thank you - I get it now.

We wouldn't have that problem in France where the cities are clearly separated. The concept of "city" (commune) is the basis for the topography classification of the country since 1789.

So when I input an address, a suggestion system will give me several choices with several distinct cities and zips. If I input a zip code, I can get several choices of "places" under one zip.

A situation where your address is in the neighbour city should not happen (I put "should" because this is France :))

pseudosavant 3 days ago | parent | prev | next [-]

Nice find! Looks like something they recently added. Before I made this project I was looking for exactly something like that and I couldn't find it anywhere.

xnx 3 days ago | parent [-]

That page has been there 2021.

pseudosavant 3 days ago | parent [-]

I first made this script in 2017, so recent is a relative term I guess.

3 days ago | parent [-]
[deleted]
Spooky23 3 days ago | parent | prev [-]

The only gotcha with the zip code reverse lookup is that there is a many to one relationship between city and zip. Look at Albany, NY (12201-12209) in the list you posted. There are a few with two cities, and iirc there are at least 3 other acceptable cities for 12203 that aren’t listed in that source.

dreamcompiler 3 days ago | parent | next [-]

My zip code maps to two different cities in two different counties. This causes endless problems with registering my car because the state wants to know what county my car is in and the webpage was programmed with the false assumption "every zip code exists entirely within one county."

USPS doesn't much care about counties. They assign postal routes based on geographical convenience, not political borders.

stackskipton 3 days ago | parent | prev [-]

ON systems I work with, we run entire Street, City, State into Zip code lookup and compare with Zip code provided. If it's within postal code, we may present it to be corrected. If it's way off, we say "Umm, something is way off here, please try again." and flag it for fraud check.

pseudosavant 3 days ago | parent | prev | next [-]

Thanks for the heads up on the newer https://postalpro.usps.com/ZIP_Locale_Detail file. I converted my script over to being a Python script that uses ZIP_Locale_Detail.xlsx as the source and doesn't require API access anymore.

My new file contains all of the ZIP + city/state combo from that file now.

dfxm12 3 days ago | parent | prev | next [-]

I have a pet peeve for having to enter my zip code after I've already had to type in the city and state.

What else would you expect? Typing my zip is way easier than going through a list of zipcodes in a dropdown, many of which will be off by one digit in different spots. (ETA: I reread your comment and see what you are expecting)

I like the experience of autocomplete while I'm typing out my street address.

boilerupnc 3 days ago | parent | next [-]

I think the sentiment for the pet peeve is commentary on the perceived inefficient sequence of the data input and a hope for reducing the number of fields entered from 3 to 1.

>I have a pet peeve for having to enter my zip code AFTER I've already had to type in the city and state.

The city and state can be derived from the zipcode - so why not simply ask for the zipcode to be typed and then auto-populate the associated city and state.

cwmma 3 days ago | parent | next [-]

There are multiple zip codes in my state (Massachusetts) that cover multiple towns some examples include 01002 which is Pelham and much of Amherst, 01027 which is both Easthampton and Westhampton (different towns) etc.

pseudosavant 3 days ago | parent [-]

Thanks for the heads up. It definitely used to include the 0xxxx ZIP codes. It is supposed to just naively fetch everything between 00000 and 99999 and record the USPS response. I'll have to re-run it and update it.

dfxm12 3 days ago | parent | prev | next [-]

The city and state can be derived from the zipcode

A few comments here suggest this isn't true.

If you want to reduce input to one field, the autocomplete based on the street address that I brought up is the best experience I've come across.

shagmin 3 days ago | parent [-]

I'm in a zip code that spans two cities and I can think of other ways it gets complicated in different scenarios. There are places where I can throw a ball across multiple zip codes, sales tax jurisdictions, municipal lines, county lines, etc., with varying degrees of overlap.

The problem I've anecdotally seen with autocomplete is there's another property with the same street address as mine but in a different city and different zip code (granted only last digit is different IIRC) about ~15 miles away and on more than one occasion it's caused a few mix-ups.

jandrewrogers 3 days ago | parent | prev [-]

> The city and state can be derived from the zipcode

False. Some ZIP codes even cover multiple States.

pseudosavant 3 days ago | parent | prev [-]

I like the autocomplete too. Probably the best pattern, but it does usually do that by leveraging paid Google Maps APIs I believe.

I was frustrated that this seemingly open data wasn't openly available. Anything that asks for city+state+zipcode can ask for zip code first, auto populate the rest. For the edge cases where the city is wrong, the person can still type in the city like they would have needed to anyway.

It is worth noting that a package would never get delivered to the wrong place because the city wasn't correct but the ZIP code was. The USPS routes based on ZIP codes, not city/state.

uptown 3 days ago | parent | prev | next [-]

Your list is very incomplete. It seems to be missing all zip codes with a leading zero.

sib 3 days ago | parent | prev | next [-]

I'm a little confused by your peeve:

There are ZIP codes that represent more than one city (town) - and that cross state boundaries.

And there are cities (towns) that have more than one ZIP code.

SAI_Peregrinus 3 days ago | parent | prev | next [-]

Zip+4 is needed to fill in city+state automatically. But I'd still rather type that first & have city + state auto-fill!

GuinansEyebrows 3 days ago | parent | prev | next [-]

i prefer my device to autofill data i've chosen to save for that purpose into a dumb form 99% of the time over the "start typing your address to locate..." functionality i see on checkout screens these days. maybe someday when they're faster/more transparent, sure, but for now the functionality you reference exists and is not great.

3 days ago | parent | prev | next [-]
[deleted]
jayknight 3 days ago | parent | prev [-]

It doesn't contain my zipcode/city combination. My zip code spans across a city line, and the json file only has the OTHER city in it.

pseudosavant 3 days ago | parent [-]

For what it is worth, this is the ZIP code data as according to the USPS. The scripts simply create the JSON file for you by calling the USPS API for every zip code between 00000 and 99999 (plenty of holes in there) and recording the response if there is one.