PostalKit is a Python ctypes binding and runtime loader for the native libpostal address-processing library. It provides direct access to the mapped C interfaces while managing the platform library and model-data setup.
- Prebuilt libpostal runtime discovery/download for supported operating systems and architectures.
- Automatic management of libpostal model assets.
- Direct C-style access to address parsing, expansion, normalization, tokenization, language classification, and duplicate-detection functions.
- ctypes structures and constants corresponding to the mapped libpostal headers.
- Explicit pointer ownership and destroy functions for returned C data.
- Runtime asset pre-download support for containers and CI environments.
The current postalkit/core/ffi.py implementation contains:
- 43 bound libpostal function symbols
- 10 ctypes structure definitions
- 87
LIBPOSTAL_*constants and option flags
These are counts of the current Python binding source, not a claim that every function, structure, or macro available in every upstream libpostal release is exposed. The binding surface can change as the upstream API and this package evolve. The source module is the definitive inventory.
The loader supports the following OS/architecture identifiers:
- Linux x64
- Linux ARM64
- macOS x64 (Intel)
- macOS ARM64 (Apple Silicon)
- Windows x64
Prebuilt binaries are loaded from the package when available or retrieved through the package's runtime download path. The libpostal model data is separate from the native runtime binaries and may require a substantial download on first initialization.
pip install postalkitimport postalkit
# Initialize libpostal and its parser data.
postalkit.initialize()
options = postalkit.libpostal_get_address_parser_default_options()
response_ptr = postalkit.libpostal_parse_address(
b"221B Baker Street, London",
options,
)
if response_ptr:
try:
response = response_ptr.contents
for index in range(response.num_components):
component = response.components[index].decode("utf-8")
label = response.labels[index].decode("utf-8")
print(f"{label}: {component}")
finally:
postalkit.libpostal_address_parser_response_destroy(response_ptr)The API follows C ownership rules: callers must use the corresponding destroy/free functions for allocated responses and arrays. Consult the upstream libpostal API and the binding source before using lower-level functions.
For Docker images, CI, or controlled deployment workflows:
from postalkit.data.manager import ensure_all_assets
ensure_all_assets()python -m pip install -e ".[dev]"
pytestSee postalkit/runtime/ for platform detection, library loading, and runtime asset handling, and build/ for prebuilt-library tooling.
PostalKit wraps openvenues/libpostal. The native project provides the address-parsing and normalization algorithms; PostalKit supplies Python FFI bindings and runtime distribution support.
MIT. See LICENSE.