A Python client library for the Postcode.eu API, providing access to international address autocomplete, Dutch address lookup, and validation services.
uv add postcode-eu-api-client
# Or
pip install postcode-eu-api-clientfrom postcode_eu_api_client import Client
# Initialize the client
client = Client('your_api_key', 'your_api_secret', 'YourApp/1.0')
# International address autocomplete
import secrets
session_id = secrets.token_hex(16)
result = client.international_autocomplete(
context='nld',
term='den',
session=session_id
)
# Dutch postcode lookup
address = client.dutch_address_by_postcode('1012JS', 1)
# Validate international address
validation = client.validate(
country='bel',
postcode='2000',
locality='antwerpen',
street='leystraat'
)international_autocomplete()- Autocomplete an addressinternational_get_details()- Get address detailsinternational_get_supported_countries()- List supported countries
dutch_address_by_postcode()- Lookup by postcode and house numberdutch_address_rd()- Lookup by RD (Rijksdriehoeksmeting) coordinatesdutch_address_lat_lon()- Lookup by latitude and longitudedutch_address_bag_number_designation()- Lookup by BAG Number Designation IDdutch_address_bag_addressable_object()- Lookup by BAG Addressable Object IDdutch_address_postcode_ranges()- Lookup streets and house number ranges by postcode
validate()- Validate international addressesget_country()- Get country information
account_info()- Get account informationcreate_client_account()- Create client account (resellers only)
View full documentation at https://developer.postcode.eu/documentation.
The client provides specific exceptions for different error conditions:
from postcode_eu_api_client import Client, InvalidPostcodeException, AuthenticationException
client = Client('key', 'secret', 'platform')
try:
result = client.dutch_address_by_postcode('invalid', 1)
except InvalidPostcodeException as e:
print(f"Invalid postcode format: {e}")
except AuthenticationException as e:
print(f"Authentication failed: {e}")PostcodeEuException- Base exception for all Postcode.eu API client exceptionsAuthenticationException- Authentication failed with the APIBadRequestException- Bad request sent to the APICurlException- HTTP request error (equivalent to cURL error in PHP)CurlNotLoadedException- HTTP library not available (equivalent to cURL not loaded in PHP)ForbiddenException- Access forbidden by the APIInvalidJsonResponseException- Invalid JSON response received from the APIInvalidPostcodeException- Invalid postcode format providedInvalidSessionValueException- Invalid session value providedNotFoundException- Resource not foundServerUnavailableException- API server is unavailableTooManyRequestsException- Too many requests sent to the APIUnexpectedException- Unexpected response from the API
- Python 3.10+
- A postcode.eu account. Register your account at account.postcode.eu. You can test our service for free.
This repository includes examples for each API method. See examples/README.md for usage.
The code is available under the Simplified BSD License, see the included LICENSE file.