|
| 1 | +# Postcode.eu API Python Client |
| 2 | + |
| 3 | +A Python client library for the [Postcode.eu API](https://developer.postcode.eu/documentation), providing access to international address autocomplete, Dutch address lookup, and validation services. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +uv add postcode-eu-api-client |
| 9 | +# Or |
| 10 | +pip install postcode-eu-api-client |
| 11 | +``` |
| 12 | + |
| 13 | + |
| 14 | +## Quick Start |
| 15 | + |
| 16 | +```python |
| 17 | +from postcode_eu_api_client import Client |
| 18 | + |
| 19 | +# Initialize the client |
| 20 | +client = Client('your_api_key', 'your_api_secret', 'YourApp/1.0') |
| 21 | + |
| 22 | +# International address autocomplete |
| 23 | +import secrets |
| 24 | +session_id = secrets.token_hex(16) |
| 25 | +result = client.international_autocomplete( |
| 26 | + context='nld', |
| 27 | + term='den', |
| 28 | + session=session_id |
| 29 | +) |
| 30 | + |
| 31 | +# Dutch postcode lookup |
| 32 | +address = client.dutch_address_by_postcode('1012JS', 1) |
| 33 | + |
| 34 | +# Validate international address |
| 35 | +validation = client.validate( |
| 36 | + country='bel', |
| 37 | + postcode='2000', |
| 38 | + locality='antwerpen', |
| 39 | + street='leystraat' |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +## API Methods Overview |
| 44 | + |
| 45 | +### International Addresses |
| 46 | +- `international_autocomplete()` - Autocomplete an address |
| 47 | +- `international_get_details()` - Get address details |
| 48 | +- `international_get_supported_countries()` - List supported countries |
| 49 | + |
| 50 | +### Dutch Address Addresses |
| 51 | +- `dutch_address_by_postcode()` - Lookup by postcode and house number |
| 52 | +- `dutch_address_rd()` - Lookup by RD (Rijksdriehoeksmeting) coordinates |
| 53 | +- `dutch_address_lat_lon()` - Lookup by latitude and longitude |
| 54 | +- `dutch_address_bag_number_designation()` - Lookup by BAG Number Designation ID |
| 55 | +- `dutch_address_bag_addressable_object()` - Lookup by BAG Addressable Object ID |
| 56 | +- `dutch_address_postcode_ranges()` - Lookup streets and house number ranges by postcode |
| 57 | + |
| 58 | +### Validate Addresses |
| 59 | +- `validate()` - Validate international addresses |
| 60 | +- `get_country()` - Get country information |
| 61 | + |
| 62 | +### Accounts |
| 63 | +- `account_info()` - Get account information |
| 64 | +- `create_client_account()` - Create client account (resellers only) |
| 65 | + |
| 66 | +View full documentation at https://developer.postcode.eu/documentation. |
| 67 | + |
| 68 | +## Exception Handling |
| 69 | + |
| 70 | +The client provides specific exceptions for different error conditions: |
| 71 | + |
| 72 | +```python |
| 73 | +from postcode_eu_api_client import Client, InvalidPostcodeException, AuthenticationException |
| 74 | + |
| 75 | +client = Client('key', 'secret', 'platform') |
| 76 | + |
| 77 | +try: |
| 78 | + result = client.dutch_address_by_postcode('invalid', 1) |
| 79 | +except InvalidPostcodeException as e: |
| 80 | + print(f"Invalid postcode format: {e}") |
| 81 | +except AuthenticationException as e: |
| 82 | + print(f"Authentication failed: {e}") |
| 83 | +``` |
| 84 | + |
| 85 | +### Available Exceptions |
| 86 | + |
| 87 | +* `PostcodeEuException` - Base exception for all Postcode.eu API client exceptions |
| 88 | +* `AuthenticationException` - Authentication failed with the API |
| 89 | +* `BadRequestException` - Bad request sent to the API |
| 90 | +* `CurlException` - HTTP request error (equivalent to cURL error in PHP) |
| 91 | +* `CurlNotLoadedException` - HTTP library not available (equivalent to cURL not loaded in PHP) |
| 92 | +* `ForbiddenException` - Access forbidden by the API |
| 93 | +* `InvalidJsonResponseException` - Invalid JSON response received from the API |
| 94 | +* `InvalidPostcodeException` - Invalid postcode format provided |
| 95 | +* `InvalidSessionValueException` - Invalid session value provided |
| 96 | +* `NotFoundException` - Resource not found |
| 97 | +* `ServerUnavailableException` - API server is unavailable |
| 98 | +* `TooManyRequestsException` - Too many requests sent to the API |
| 99 | +* `UnexpectedException` - Unexpected response from the API |
| 100 | + |
| 101 | +## Requirements |
| 102 | + |
| 103 | +- Python 3.10+ |
| 104 | +- A postcode.eu account. Register your account at account.postcode.eu. You can test our service for free. |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +The code is available under the Simplified BSD License, see the included LICENSE file. |
0 commit comments