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.

Metadata

Release files for matthew-proctor-postcodes-client 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for matthew-proctor-postcodes-client 1.0.0
File Size Uploaded Provenance Actions
matthew_proctor_postcodes_client-1.0.0.tar.gz 10.2 kB Without provenance Details for matthew_proctor_postcodes_client-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for matthew-proctor-postcodes-client 1.0.0
File Interpreter ABI Platform Actions
matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl Python 3 none any Details for matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl

Total release size: 23.2 kB

Release files / matthew_proctor_postcodes_client-1.0.0.tar.gz

Download URL matthew_proctor_postcodes_client-1.0.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ff1775c09ab42d82a6c2ab3dda283b5151b7c68a437e8b32114c5e29a25dc58c
BLAKE2b-256 checksum
How to use checksums
253f12f2e049a87dd46421a152b316be7473db91138c52471b37b38d3d780dbd
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl

Download URL matthew_proctor_postcodes_client-1.0.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3d0dee85e1007a0e2a85881263d8317a3d8ef73969294b87cef1771597916e6
BLAKE2b-256 checksum
How to use checksums
59c34e5bf1d79c6f2031487a52b659e75ca32bc2f77674d6a66238fd662a24fa
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for matthew-proctor-postcodes-client 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page