Skip to main content

Filter and bias

Filters restrict address suggestions to matching addresses. Biases rank matching addresses first but still return the rest. Both are keyword arguments to find_address, alongside query. See autocomplete for the rest of the flow.

Filter to an area​

Add a filter, such as postcode_outward.

filter.pypython
from ideal_postcodes import IdealPostcodes

with IdealPostcodes("ak_test") as client:
result = client.find_address(query="malyons road", postcode_outward="BR8")
for hit in result.hits:
print(hit.suggestion)

An invalid filter term returns an empty list.

Bias towards an area​

Add a bias, such as bias_post_town. Addresses outside the post town still appear, ranked lower.

bias.pypython
result = client.find_address(query="high street", bias_post_town="Edinburgh")

To favour addresses near a point, pass bias_lonlat as longitude, latitude and radius in metres.

bias_location.pypython
result = client.find_address(query="high street", bias_lonlat="-0.12767,51.503541,5000")

bias_ip="true" favours addresses near the IP address that sends the request. The SDK runs on your server, so that is your server's location, not your user's. Use bias_lonlat with your user's location instead.

An invalid bias term has no effect.

Filters​

FilterRestricts suggestions toExample
postcodeA full postcodeBR8 7RE
postcode_outwardAn outward code, the first half of a postcodeBR8
postcode_areaA postcode area, the leading letters of a postcodeBR
postcode_sectorA postcode sector, the outward code plus the first digit of the inward codeBR8 7
post_townA Royal Mail post town, city or localityLondon
uprnOne UPRN. Takes an int and accepts a single term only50002012147
countryA country: England, Scotland, Wales, Northern Ireland, Jersey, Guernsey or Isle of ManScotland
postcode_typeRoyal Mail postcode user type: S small user, L large userL

country never takes United Kingdom. Pass one of the seven values above.

A small user postcode covers a group of delivery points, 19 on average and never more than 100. A large user postcode belongs to one address, because of the volume of mail it receives or because it has a PO Box or Selectapost service.

Biases​

BiasRanks firstExample
bias_postcodeA full postcodeBR8 7RE
bias_postcode_outwardAn outward codeBR8
bias_post_townA post town, city or localityManchester
bias_lonlatA circle given as longitude,latitude,radius, radius in metres up to 50000-2.095,57.15,100
bias_ipThe approximate location of the requesting IP address. Takes "true" only"true"

Multiple terms​

Separate terms with commas to match any of them, such as postcode_area="SW,SE". Separate filters combine, so each one narrows the list further.

The API accepts at most 8 filter terms and 5 bias terms per request. uprn takes one term, and bias_lonlat takes one circle.

Cost​

Filters and biases do not change the cost: suggestions are free, and each resolve_address costs one lookup.

See find_address for every parameter and the API reference for the underlying request.