Skip to main content

Complete 100% 1:1 Python FFI Wrapper for the libpostal C Library - Direct C function calls with zero abstraction for maximum address parsing precision

Project description

PostalKit

PyPI version Downloads Python Versions License: MIT Wheel Status

Zero-setup, one-command install Python package for libpostal. Designed as a strict 1:1 C-FFI wrapper.

Parsing international street addresses shouldn't require a Ph.D. in C compilation. postalkit provides the ultimate zero-friction environment to run the amazing libpostal C library natively in Python, without abstracting away its raw power.

Like FFI implementations in PHP, this exposes the exact C structs, constants, and functions so that you can port C logic directly to Python.

✨ Why PostalKit?

The standard postal package requires you to manually compile C code, install autoconf, make, pkg-config, and manually download a ~2GB machine learning model.

PostalKit handles everything automatically:

  • Zero C compilation: Downloads pre-compiled libpostal shared binaries for your OS and architecture.
  • Auto-downloads models: Fetches the required libpostal ML models transparently on first use.
  • Strict 1:1 C Mapping: Exposes libpostal_parse_address, libpostal_expand_address, and all ctypes structs exactly as defined in libpostal.h.
  • Cross-platform: Works on Linux (x86_64, arm64), macOS (Intel, Apple Silicon), and Windows.

📦 Installation

pip install postalkit

🚀 Quickstart

Because this is a true 1:1 FFI wrapper, you use the exact function names and C-structs defined in the upstream libpostal C headers. Memory is managed precisely as it is in C.

import ctypes
import postalkit

# 1. Get the C-struct for parser options
options = postalkit.libpostal_get_address_parser_default_options()

# 2. Call the C-function directly (strings must be passed as bytes)
address = b"221B Baker St London"
response_ptr = postalkit.libpostal_parse_address(address, options)

# 3. Access the raw C-arrays
response = response_ptr.contents
for i in range(response.num_components):
    component = response.components[i].decode('utf-8')
    label = response.labels[i].decode('utf-8')
    print(f"{label}: {component}")

# 4. Manually destroy the C pointer to free memory, exactly as in C!
postalkit.libpostal_address_parser_response_destroy(response_ptr)

🧠 True 1:1 FFI Coverage

This package leaves absolutely nothing behind. It natively exposes:

  • All 46 C functions (libpostal_tokenize, libpostal_classify_language, libpostal_is_name_duplicate_fuzzy, etc.)
  • All 10 C Structs (libpostal_normalize_options_t, libpostal_duplicate_options_t, etc.)
  • All 42 C Constants & Bitwise Flags (LIBPOSTAL_ADDRESS_HOUSE_NUMBER, LIBPOSTAL_NORMALIZE_TOKEN_DELETE_HYPHENS, etc.)

You can directly port any libpostal C/C++ tutorial code into Python line-by-line.

🛠️ Advanced Usage

Pre-downloading assets (e.g., for Docker images or CI):

from postalkit.data.manager import ensure_all_assets
ensure_all_assets()

📄 License

MIT License. Developed with 💙 by Jayesh Mepani.

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

postalkit-1.0.7.tar.gz (8.8 MB view details)

Uploaded Source

Built Distribution

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

postalkit-1.0.7-py3-none-any.whl (8.9 MB view details)

Uploaded Python 3

File details

Details for the file postalkit-1.0.7.tar.gz.

File metadata

  • Download URL: postalkit-1.0.7.tar.gz
  • Upload date:
  • Size: 8.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for postalkit-1.0.7.tar.gz
Algorithm Hash digest
SHA256 2acf45c50ff45262097aa9ae449257b2a33e11b827fee1fff8ae2631e5c4cdb3
MD5 64a6a44525756e1117d751a9684e5d9e
BLAKE2b-256 cc86339dc1a14ddf5782ffb2a6827e5537294e70481224ca81b4f5ce68401ba1

See more details on using hashes here.

Provenance

The following attestation bundles were made for postalkit-1.0.7.tar.gz:

Publisher: release-prebuilt-libs.yml on jayeshmepani/libpostal-ffi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file postalkit-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: postalkit-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for postalkit-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8b20f376fc94fed393450f086cbf318580fe2da288cddb83c25b4d078cb59dae
MD5 e6ce5dd4467f1a0b416060a2de5c3be6
BLAKE2b-256 f8640e9b9074ff9a19f42bea9948f8d70c29d93287a4b990880fd2be0e4e7700

See more details on using hashes here.

Provenance

The following attestation bundles were made for postalkit-1.0.7-py3-none-any.whl:

Publisher: release-prebuilt-libs.yml on jayeshmepani/libpostal-ffi-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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