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.2.tar.gz (115.4 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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for wojtek_uk_postcodes-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4b4fa89a6e2d3beb5c60c5866573a82c957589503f546d10a46fad06037eb558
MD5 d1c3ff3d3cbf7961b4bc552cbd210339
BLAKE2b-256 b849bfac65519f1089f686290416cfb8868b4eca34e79a54fe8f41aab33f6350

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wojtek_uk_postcodes-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 767bfe72fe4972dee838b0cc10dff943d299c6f25f78dac6926eb7c8b4a5316e
MD5 172d94dfa6b92ac8b46534f3efe5b3e0
BLAKE2b-256 bb8004083c01b3b7aa2522d0345f7b01bf7ae03c4d61ba808f8d65890e61b2c0

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