Python SDK for the PostalDataPI global postal code API
Project description
PostalDataPI Python SDK
Official Python client for the PostalDataPI global postal code API. Look up, validate, and search postal codes across 70+ countries with sub-10ms response times.
Installation
pip install postaldatapi
Quick Start
from postaldatapi import PostalDataPI
client = PostalDataPI(api_key="your-api-key")
# Look up a US ZIP code
result = client.lookup("90210")
print(result.city) # Beverly Hills
print(result.state_abbreviation) # CA
# Look up a German postal code
result = client.lookup("10115", country="DE")
print(result.city) # Berlin
# Validate a UK postcode
result = client.validate("SW1A", country="GB")
print(result.valid) # True
# Search by city name
results = client.search_city("Beverly Hills", state="CA")
print(results.postal_codes) # ['90209', '90210', '90211', ...]
# Get rich metadata
meta = client.metazip("90210")
print(meta.meta["county"]) # Los Angeles County
print(meta.meta["timezone"]) # America/Los_Angeles
print(meta.latitude) # 34.1031
print(meta.longitude) # -118.4163
API Methods
client.lookup(postal_code, *, country="US")
Returns city and state for a postal code.
client.validate(postal_code, *, country="US")
Checks whether a postal code exists. Returns ValidateResult with .valid boolean.
client.search_city(city, *, state=None, country="US")
Finds postal codes matching a city name. State is required for US queries.
client.metazip(postal_code, *, country="US")
Returns rich metadata: coordinates, county (US), timezone (US), and all available data source fields.
Country Support
Pass any ISO 3166-1 alpha-2 country code: US, GB, DE, FR, CA, JP, AU, and 60+ more. Country defaults to US if omitted.
Error Handling
from postaldatapi import PostalDataPI, NotFoundError, AuthenticationError
client = PostalDataPI(api_key="your-api-key")
try:
result = client.lookup("00000")
except NotFoundError:
print("Postal code not found")
except AuthenticationError:
print("Invalid API key")
Exception classes: AuthenticationError (401), NotFoundError (404), ValidationError (400), RateLimitError (429), InsufficientBalanceError (402), ServerError (5xx).
Configuration
# Custom base URL (for staging or self-hosted)
client = PostalDataPI(
api_key="your-key",
base_url="https://staging.postaldatapi.com",
timeout=30, # seconds
)
Account Balance
Every response includes your current account balance:
result = client.lookup("90210")
print(f"Remaining balance: ${result.balance:.2f}")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file postaldatapi-0.2.0.tar.gz.
File metadata
- Download URL: postaldatapi-0.2.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e9f2320fe8a6c849593e2425b4ef9ac3250e5aba3ace77bc19a80914b0d1e1
|
|
| MD5 |
31ef879e0b418197850c8efe218ccf78
|
|
| BLAKE2b-256 |
2348881e95ae28a133686906ca3d1fb69c26885ca3401a84e1d49269862161c6
|
File details
Details for the file postaldatapi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: postaldatapi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf5837c1d71511dfaa280b892b132a311de407e32c5540d974b6d4a259c658f5
|
|
| MD5 |
e27c8cfc0b6edb0f86cbc0f924efa974
|
|
| BLAKE2b-256 |
97f58b7b06c131097964d07c82c6d4aa9a362bc7dd6429c090509af07b2a9934
|