Skip to main content

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 UKPostcode with 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 FormatStyle or JSON-ready dictionaries via to_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 pytest or make test (which also reports coverage).
  • Type-check and lint: make mypy and make 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

wojtek_uk_postcodes-0.1.1.tar.gz (115.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wojtek_uk_postcodes-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file wojtek_uk_postcodes-0.1.1.tar.gz.

File metadata

  • Download URL: wojtek_uk_postcodes-0.1.1.tar.gz
  • Upload date:
  • Size: 115.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.23

File hashes

Hashes for wojtek_uk_postcodes-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e59afee9d3e50b437a038b512ce9e23c44153a3080aadddfae54bdf5d7e91f9e
MD5 67c96404c86605e989ab40db713db11d
BLAKE2b-256 4f6901f2a952b64fa5d682296fb8006271b5d6e32601befe0246428718bb952a

See more details on using hashes here.

File details

Details for the file wojtek_uk_postcodes-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wojtek_uk_postcodes-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2049b9654075e3b64802458bb4692d40862ece51c6639c12c2de04cb68de650
MD5 23e91f8d02b5d6542a2a658777fcca50
BLAKE2b-256 3adb0de2795a406a5d74a5f0fb1428e832c5d9f6e72f9b8e8c1ff43abfb3b1ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page