UK Postcodes validator package - under `wojtek` namespace
Project description
wojtek-uk-postcodes
Small, typed utilities for working with UK postcodes. It ships with a strict parser that produces
a structured UKPostcode value object and companion helpers for validation and formatting.
Features
- Parse raw strings into a frozen
UKPostcodewith outward/inward, area, district, sector, and unit parts. - Validate standard postcodes and optional special cases such as BFPO, GIR, Overseas Territories, and Santa codes.
- Produce formatted strings with
FormatStyleor JSON-ready dictionaries viato_dict(). - Pure Python, zero external runtime dependencies, requires Python 3.10+.
Validation scope and limitations
Validation checks only that inputs match UK postcode formats using regular-expression patterns (including known special-case rules). It does not verify whether a postcode actually exists, is allocated, is currently valid, or is deliverable.
Installation
Install the package from PyPI:
pip install wojtek-uk-postcodes
Quick start
from wojtek.uk_postcodes import FormatStyle, parse_postcode, is_valid_postcode
postcode = parse_postcode("SW1A 1AA")
print(postcode.outward) # 'SW1A'
print(postcode.format()) # 'SW1A 1AA'
print(postcode.format(FormatStyle.NO_SPACES)) # 'SW1A1AA'
is_valid_postcode("GIR 0AA", allow_special=True) # True
postcode.to_dict()
Development
- Run the test suite:
uv run pytestormake test(which also reports coverage). - Type-check and lint:
make mypyandmake format.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wojtek_uk_postcodes-0.1.3.tar.gz.
File metadata
- Download URL: wojtek_uk_postcodes-0.1.3.tar.gz
- Upload date:
- Size: 116.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4a8e0df50e1d7da4ebba97fe3c16ed2e4a3e2249d5d13c2f3a1fc37ac8fd377
|
|
| MD5 |
555a7ef46336c081fccceb88bb689d22
|
|
| BLAKE2b-256 |
96d9f2ef25a6f9916ff83d4d1a27caf1606b3cc7380bced033c7993beb9d420a
|
File details
Details for the file wojtek_uk_postcodes-0.1.3-py3-none-any.whl.
File metadata
- Download URL: wojtek_uk_postcodes-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4eaac25fd2f067eefd8b41681fbb1221b17f014f1533c61ca4da2d6f9b3a1dc
|
|
| MD5 |
af72923fb3106793258735888a0f1260
|
|
| BLAKE2b-256 |
d07b9993de23b818a1372f311ea1291763476b4acb92a6fd4d04c37035d57552
|