Autocomplete
find_address turns a partial address into suggestions as the user types. resolve_address turns the chosen suggestion into a full address.
from ideal_postcodes import IdealPostcodes
with IdealPostcodes("ak_test") as client:
hits = client.find_address(query="9 Malyons Road", limit=5).hits
if hits:
address = client.resolve_address(hits[0].id)
print(address.line_1, address.post_town, address.postcode)
else:
print("No matches")
Find suggestions
Call find_address with the partial address as query. The result holds hits, a list of suggestions, each with an id and a suggestion to show the user. An empty list means nothing matched. Show each suggestion as it is: the API may change its format, so do not parse it.
It takes every other find_address keyword too: limit, context to search another country and the filters and biases in filter and bias, such as postcode_outward or bias_post_town.
The SDK runs on your server. Have the browser send each keystroke to an endpoint of yours that calls find_address, so your key never leaves the server. The SDK neither debounces nor caches, so wait for a short pause in typing before you call it.
Switch country
key_availability lists the countries a key can search. It needs only the API key and costs nothing.
from ideal_postcodes import IdealPostcodes
with IdealPostcodes("ak_test") as client:
key = client.key_availability("ak_test")
for country in key.contexts:
print(country.emoji, country.description, country.iso_3)
context = key.context or key.contexts[0].iso_3
hits = client.find_address(query="9 Malyons Road", context=context).hits
Each entry in contexts has iso_3 (the context code), iso_2, description and emoji. context is the licensed country that best matches the IP address the request came from, or an empty string when none does. When the SDK runs on your server, that is your server's address, so prefer the country your user picks.
Resolve a suggestion
Pass the hit's id to resolve_address. The result is an Address with line_1, line_2, line_3, post_town, postcode, uprn and the other standard fields. dataset names the source, and native holds the source dataset's raw record when the API returns one.
Cost
Suggestions are free. Each resolve_address costs one lookup. The API rate limits, then suspends, integrations that request suggestions without resolving any. The default limit is 3,000 suggestion requests per 5 minutes for each key and IP address.
Errors
An HTTP error raises APIError or a subclass, and a failed connection raises TransportError. See error handling. See resolve_address for its parameters.