Registry / serialization / ukpostcodeparser

ukpostcodeparser

JSON →
library1.1.2pypypi✓ verified 86d ago

A Python library for parsing and validating UK postcodes. Supports all common format types including inward/outward codes, GiroBank, BFPO, and special postcodes. Version 1.1.2 is current; the library is stable and receives infrequent updates.

pip install ukpostcodeparser
INSTALL
IMPORT
SIG · UKPOSTCODEPARSER
U
ukpostcodeparser
serializationpythonv1.1.2
Install
1.5s avg
Import
18ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.018s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.018s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse_uk_postcode
from ukpostcodeparser import parse_uk_postcode
parse_gb_postcode
from ukpostcodeparser import parse_gb_postcode

Parse a UK postcode into its outward and inward components.

from ukpostcodeparser import parse_uk_postcode postcode = parse_uk_postcode('SW1A 1AA') if postcode: print(postcode) # ParsedPostcode(outward='SW1A', inward='1AA', postcode='SW1A 1AA') else: print('Invalid postcode')
Debug
Known issues
deprecatedThe function `validate_uk_postcode` is deprecated in version 1.1.0+; use `parse_uk_postcode` instead and check if it returns None.
fix
Replace `validate_uk_postcode(p)` with `parse_uk_postcode(p) is not None`.
affects: >=1.1.0
gotchaThe function `parse_uk_postcode` accepts formatted postcode strings with or without space (e.g., 'SW1A1AA' and 'SW1A 1AA' both work). However, output always contains a space in the postcode field. Input validation is permissive: non-standard formats may be accepted as valid.
fix
Test with your expected input formats and validate using the parsed components if strict adherence to a specific format is needed.
affects: all
gotchaThis library does not validate that a postcode exists in the Royal Mail database; it only checks structural validity. It will accept some patterns that are structurally valid but not actually assigned.
fix
Use the parsed postcode with an external validation service (e.g., Ordnance Survey API) for existence checks.
affects: all
Errors
Common errors & fixes
ImportError: No module named 'ukpostcodeparser'
Library not installed or installed in a different environment.
fix
Run `pip install ukpostcodeparser` in the correct Python environment.
AttributeError: module 'ukpostcodeparser' has no attribute 'validate'
Attempting to call a non-existent function named `validate` that may have existed in an older version or never existed.
fix
Use `parse_uk_postcode` instead of `validate`. Check return value for None to indicate invalid postcode.
TypeError: parse_uk_postcode() missing 1 required positional argument: 'postcode'
Calling the function without passing a postcode string.
fix
Pass a string argument, e.g., `parse_uk_postcode('M1 1AE')`.
Upgrade
Version history
1.1.2latest on PyPI · released Sep 4, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
ukpostcodeparser — pip install ukpostcodeparser · libregistry