Postcode Lookup Tool
This repository contains a simple Python package for looking up UK postcodes to obtain their easting/northing coordinates and corresponding latitude/longitude values. The package reads data from CSV files based on the postcode prefix and uses this data to perform lookups efficiently.
Features
- Lookup eastings and northings for a given UK postcode.
- Convert the easting and northing coordinates to latitude and longitude.
- Efficient caching using
functools.lru_cacheto improve performance for repeated postcode prefix lookups.
Installation
You can install this package directly from PyPI using pip:
pip install uklookup
Usage
Command Line Usage
Once installed, you can use the package directly from the command line to look up the easting, northing, latitude, and longitude for a UK postcode:
python -m uklookup "SW1A 1AA"
Example output:
Postcode: SW1A 1AA
Easting: 530046, Northing: 179386
Latitude: 51.501009, Longitude: -0.141588
Programmatic Usage
You can also import the package and use it in your own Python scripts.
Example:
from uklookup import lookup_postcode_lat_long
postcode = "SW1A 1AA"
lat_long = lookup_postcode_lat_long(postcode)
if lat_long:
lat, long = lat_long
print(f"Latitude: {lat}, Longitude: {long}")
else:
print("Postcode not found.")
Functions
lookup_postcode(postcode: str) -> Optional[Tuple[int, int]]
Looks up the easting and northing for a given UK postcode. Returns a tuple of integers (easting, northing) if found, or None if the postcode is not in the dataset.
lookup_postcode_lat_long(postcode: str) -> Optional[Tuple[float, float]]
Looks up the latitude and longitude for a given UK postcode. Returns a tuple of floats (latitude, longitude) if found, or None if the postcode is not in the dataset.
Dependencies
numpyconvertbng(for converting eastings/northings to latitudes/longitudes)
License
This project is licensed under the MIT License.
Acknowledgements
This project uses data from the Code-Point Open dataset provided by Ordnance Survey. The data is available under the Open Government Licence v3.0.
Other Projects
A much more comprehensive postcode lookup tool is available at postcodes.io. This project is a simple alternative for basic postcode lookups in an offline setting.
pgeocode looks like a much more advanced, multi-country, higher detail version of this tool. So if you are looking for a high power tool in offline setting check that out.
Metadata
Release files for uklookup 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| uklookup-0.0.4.tar.gz | 13.9 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| uklookup-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.9 MB
Release files / uklookup-0.0.4.tar.gz
| Download URL | uklookup-0.0.4.tar.gz |
|---|---|
| Size | 13.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1dddc9af013a55e289a7456f6629c4ce9030704ed0fda984172241b149e582e
|
|
BLAKE2b-256 checksum How to use checksums |
fb92c3d4f392ee97936a002567adbd28d76b1e3d80388f4dbda2395aaa967c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2025.
Transparency logRelease files / uklookup-0.0.4-py3-none-any.whl
| Download URL | uklookup-0.0.4-py3-none-any.whl |
|---|---|
| Size | 13.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
910e615c004c33201ea3d3eac68b1b8e399c1f63e7d886ec0241369da67e0436
|
|
BLAKE2b-256 checksum How to use checksums |
af74d36cedab89cd2300b2d470612651fa6573338eeaf5d3ea5eda0651edcfad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2025.
Transparency log