Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Matthew Proctor Postcodes Client

Async, typed Python 3.12+ client for Matthew Proctor Australian and New Zealand postcode CSV datasets.

Python UV Hatchling Ruff Pytest PyPI

Package CI Package CD

Quick Start

Install the package:

pip install matthew-proctor-postcodes-client

Use the async clients:

import asyncio

from matthew_proctor_postcodes_client import AUSMatthewProctorPostcodesClient


async def main() -> None:
    client = AUSMatthewProctorPostcodesClient()
    entries = await client.lookup("3004")

    for entry in entries:
        print(entry["locality"], entry.get("RA_2021_NAME"))


asyncio.run(main())

Install development dependencies:

uv sync --refresh

Run local checks:

make lint
make test

Format code:

make format

Behaviour

  • AUSMatthewProctorPostcodesClient returns AUSMatthewProctorPostcodeInfo rows.
  • NZLMatthewProctorPostcodesClient returns NZLMatthewProctorPostcodeInfo rows.
  • lookup() returns every locality for a postcode.
  • Unknown but well-formed postcodes return an empty list.
  • Postcodes are normalized to four decimal digits, so "110" is looked up as "0110".
  • Invalid postcodes raise InvalidPostcodeError; values must be one to four decimal digits.
  • Choose the country-specific client explicitly (AUSMatthewProctorPostcodesClient or NZLMatthewProctorPostcodesClient).
  • A local CSV is preferred; a missing CSV is downloaded from GitHub and saved atomically.
  • The parsed postcode index is cached by aiocache.cached(noself=True).
  • Row models are lightweight TypedDict types that use the known source CSV headers.

Installation

pip install matthew-proctor-postcodes-client

For local development from a checkout:

uv sync --refresh

Storage

Set MATTHEW_PROCTOR_DATA_DIR to control where files are read and downloaded:

export MATTHEW_PROCTOR_DATA_DIR=data/matthewproctor

This produces:

data/matthewproctor/australian_postcodes.csv
data/matthewproctor/newzealand_postcodes.csv

If the environment variable is absent, the default is data/matthewproctor relative to the current working directory.

For an enterprise image, bake either CSV into that path and configure download_if_missing=False.

Usage

import asyncio

from matthew_proctor_postcodes_client import (
    AUSMatthewProctorPostcodesClient,
    NZLMatthewProctorPostcodesClient,
)


async def main() -> None:
    aus_client = AUSMatthewProctorPostcodesClient()
    nz_client = NZLMatthewProctorPostcodesClient()

    aus_entries = await aus_client.lookup("3004")
    nz_entries = await nz_client.lookup("110")

    print([entry["locality"] for entry in aus_entries])
    print([entry["locality"] for entry in nz_entries])


asyncio.run(main())

Client Configuration

Concrete clients accept these keyword arguments:

  • request_timeout_seconds: HTTP timeout used when a missing CSV must be downloaded. Defaults to 30.0.
  • download_if_missing: whether to download the source CSV when it is not already present locally. Defaults to True.

Storage is configured with MATTHEW_PROCTOR_DATA_DIR, not a constructor argument:

import os

from matthew_proctor_postcodes_client import AUSMatthewProctorPostcodesClient

os.environ["MATTHEW_PROCTOR_DATA_DIR"] = "/app/data/matthewproctor"

client = AUSMatthewProctorPostcodesClient(
    request_timeout_seconds=10.0,
    download_if_missing=False,
)

Select the concrete client when the country is only known at runtime:

from matthew_proctor_postcodes_client import (
    AUSMatthewProctorPostcodesClient,
    NZLMatthewProctorPostcodesClient,
)

client = {
    "AUS": AUSMatthewProctorPostcodesClient,
    "NZL": NZLMatthewProctorPostcodesClient,
}[country]()

The package also exports normalize_postcode, default_data_dir, MatthewProctorDatabaseType, and the package exception classes:

from matthew_proctor_postcodes_client import (
    DatasetFormatError,
    DatasetUnavailableError,
    InvalidPostcodeError,
    normalize_postcode,
)

Source Schemas

The Australian CSV is australian_postcodes.csv. It includes the prescribed Australia Post postcode ranges for NSW, ACT, VIC, QLD, SA, WA, TAS, and NT, including LVR and PO Box ranges.

Common Australian fields include:

id,postcode,locality,state,long,lat,dc,type,status,sa3,sa3name,sa4,sa4name,region,
Lat_precise,Long_precise,SA1_CODE_2021,SA1_NAME_2021,SA2_CODE_2021,SA2_NAME_2021,
SA3_CODE_2021,SA3_NAME_2021,SA4_CODE_2021,SA4_NAME_2021,RA_2011,RA_2016,RA_2021,
RA_2021_NAME,MMM_2015,MMM_2019,ced,altitude,chargezone,phn_code,phn_name,
lgaregion,lgacode,electorate,electoraterating,sed_code,sed_name

The New Zealand CSV is newzealand_postcodes.csv and currently uses:

postcode,locality,region,long,lat,territory,island

The source datasets may add fields over time. Unknown extra CSV fields are preserved in returned row dictionaries, while the exported TypedDict models document the fields known by this package.

Development

This package uses uv, ruff, pytest, and hatchling. It targets Python 3.12 or newer.

CI/CD

Package CI runs on pull requests and pushes to main with:

uv run ruff format --check .
uv run ruff check .
uv run pytest -vv

Package publishing is handled by .github/workflows/package-cd.yaml. Run it manually or publish a GitHub Release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matthew_proctor_postcodes_client-1.0.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file matthew_proctor_postcodes_client-1.0.0.tar.gz.

File metadata

  • Download URL: matthew_proctor_postcodes_client-1.0.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for matthew_proctor_postcodes_client-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ff1775c09ab42d82a6c2ab3dda283b5151b7c68a437e8b32114c5e29a25dc58c
MD5 378940bc3f81c41632702f85c09ac1e0
BLAKE2b-256 253f12f2e049a87dd46421a152b316be7473db91138c52471b37b38d3d780dbd

See more details on using hashes here.

File details

Details for the file matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3d0dee85e1007a0e2a85881263d8317a3d8ef73969294b87cef1771597916e6
MD5 d9828e5c387c3f5e9351f841ebdf817f
BLAKE2b-256 59c34e5bf1d79c6f2031487a52b659e75ca32bc2f77674d6a66238fd662a24fa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

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