Skip to content

dabapps/postcodeserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postcodes

A tiny JSON server for getting the latitude and longitude of a UK postcode.

You can see it running at postcodes.herokuapp.com/?postcode=bn11ag.

Created by Jamie Matthews. Follow me on Twitter: @j4mie

running locally

git clone [email protected]:j4mie/postcodeserver.git
cd postcodeserver
python3 -m venv env
env/bin/pip install -r requirements.txt
env/bin/python server.py

using from another program

>>> import requests
>>> requests.get('http://postcodes.herokuapp.com', params={'postcode': 'BN1 1AG'}).json()
{u'lat': 50.82292196340859, u'lng': -0.14287104830145836, u'geohash': u'gcpchspbyz7d', u'postcode': u'BN11AG'}

data source

Loaded with data from here. The original source is the Ordnance Survey Code-Point Open.

rebuilding the trie

The repository includes the postcode database encoded using marisa-trie (the resulting file is approx. 19 MB). To rebuild this, you'll need a CSV file with at least three columns: postcode, latitude, longitude. The file linked above (under Data Source) matches this format:

$ head -5 postcodes.csv 
Postcode,Latitude,Longitude,Easting,Northing,GridRef,County,District,Ward,DistrictCode,WardCode,Country,CountyCode
AB10 1AA,57.148235,-2.096648,394251,806376,NJ942063,"","Aberdeen City","George St/Harbour Ward", S12000033,S13002483,Scotland,
AB10 1AB,57.149079,-2.096964,394232,806470,NJ942064,"","Aberdeen City","George St/Harbour Ward", S12000033,S13002483,Scotland,
AB10 1AF,57.14871,-2.097806,394181,806429,NJ941064,"","Aberdeen City","George St/Harbour Ward", S12000033,S13002483,Scotland,
AB10 1AG,57.148235,-2.096648,394251,806376,NJ942063,"","Aberdeen City","George St/Harbour Ward", S12000033,S13002483,Scotland,

To import this file, run env/bin/python rebuild.py path/to/postcodes.csv

disclaimer

It goes without saying that this software (and the service running on Heroku) comes with no warranties or guarantees to its accuracy, availability or stability. Use at your own risk.

code license

unlicense.org

Code of conduct

For guidelines regarding the code of conduct when contributing to this repository please review https://www.dabapps.com/open-source/code-of-conduct/

About

A tiny JSON server for UK postcode lookups

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •