Skip to main content

Python client for the Postcode.eu API

Project description

Postcode.eu API Python Client

A Python client library for the Postcode.eu API, providing access to international address autocomplete, Dutch address lookup, and validation services.

Installation

uv add postcode-eu-api-client
# Or
pip install postcode-eu-api-client

Quick Start

from 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'
)

API Methods Overview

International Addresses

  • international_autocomplete() - Autocomplete an address
  • international_get_details() - Get address details
  • international_get_supported_countries() - List supported countries

Dutch Address Addresses

  • dutch_address_by_postcode() - Lookup by postcode and house number
  • dutch_address_rd() - Lookup by RD (Rijksdriehoeksmeting) coordinates
  • dutch_address_lat_lon() - Lookup by latitude and longitude
  • dutch_address_bag_number_designation() - Lookup by BAG Number Designation ID
  • dutch_address_bag_addressable_object() - Lookup by BAG Addressable Object ID
  • dutch_address_postcode_ranges() - Lookup streets and house number ranges by postcode

Validate Addresses

  • validate() - Validate international addresses
  • get_country() - Get country information

Accounts

  • account_info() - Get account information
  • create_client_account() - Create client account (resellers only)

View full documentation at https://developer.postcode.eu/documentation.

Exception Handling

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}")

Available Exceptions

  • PostcodeEuException - Base exception for all Postcode.eu API client exceptions
  • AuthenticationException - Authentication failed with the API
  • BadRequestException - Bad request sent to the API
  • CurlException - 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 API
  • InvalidJsonResponseException - Invalid JSON response received from the API
  • InvalidPostcodeException - Invalid postcode format provided
  • InvalidSessionValueException - Invalid session value provided
  • NotFoundException - Resource not found
  • ServerUnavailableException - API server is unavailable
  • TooManyRequestsException - Too many requests sent to the API
  • UnexpectedException - Unexpected response from the API

Requirements

  • Python 3.10+
  • A postcode.eu account. Register your account at account.postcode.eu. You can test our service for free.

Examples

This repository includes examples for each API method. See examples/README.md for usage.

License

The code is available under the Simplified BSD License, see the included LICENSE file.

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

postcode_eu_api_client-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

postcode_eu_api_client-1.0.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file postcode_eu_api_client-1.0.1.tar.gz.

File metadata

File hashes

Hashes for postcode_eu_api_client-1.0.1.tar.gz
Algorithm Hash digest
SHA256 442509d76b3f457ca3865085995b7029a4c80be9142d8c30f5496356c499d219
MD5 faadfdc908ab6fefd55572775f8730a7
BLAKE2b-256 06c20cddbf90335fde80b2c961d83182200c286a3d1cdf1d3e9c89240857643c

See more details on using hashes here.

File details

Details for the file postcode_eu_api_client-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for postcode_eu_api_client-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cebeced3e3e2a24dca57141780657d5555795e657088607ab78209ecb3c3355e
MD5 85372c1992ea1bc448c90f5542ddc2a5
BLAKE2b-256 029e975944cf63b65ccded69e19496149e3d4beef30be5f9133eb89b26ed6841

See more details on using hashes here.

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