api calls
functions
AssignAPIClient
AssignAPIClient (dotenv_path:str='.env')
*A client for interacting with the ASSIGN API. Handles environment setup and provides methods for address search, upload, and download.
Args: dotenv_path (str): Path to the .env file. Defaults to ‘.env’
Returns: an instance of the AssignAPIClient class
Example:
client = AssignAPIClient(dotenv_path = '.env')*
AssignAPIClient.address_search
AssignAPIClient.address_search (address:str)
*Search for a UPRN by address.
Args: address (str): An address on a single line, each element separated with a comma.
Returns: requests.Response: JSON representation of the matching AddressBase Premium record.
Example:
> response = client.address_search('10 Downing St,Westminster,London,SW1A2AA')
> response.json()
{'Address_format': 'good',
'Postcode_quality': 'good',
'Matched': True,
'BestMatch': {'UPRN': '100023336956',
'Qualifier': 'Property',
'LogicalStatus': '1',
'Classification': 'RD04',
'ClassTerm': 'Terraced',
'Algorithm': '10-match1',
'ABPAddress': {'Number': '10',
'Street': 'Downing Street',
'Town': 'City Of Westminster',
'Postcode': 'SW1A 2AA'},
'Match_pattern': {'Postcode': 'equivalent',
'Street': 'equivalent',
'Number': 'equivalent',
'Building': 'equivalent',
'Flat': 'equivalent'}}}*
AssignAPIClient.upload
AssignAPIClient.upload (infilepath:str)
*Upload a text file of TSV address records to the ASSIGN API, or upload an encrypted salt.
For address uploads, format is two columns: id and address, e.g.:
1 ⭾ 10 Downing St,Westminster,London,SW1A2AA
2 ⭾ Bridge Street,London,SW1A 2LW
3 ⭾ 221b Baker St,Marylebone,London,NW1 6XE
4 ⭾ 3 Abbey Rd,St Johns Wood,London,NW8 9AY
Args: infilepath (str): Filepath containing multiple addresses to upload.
Returns: requests.Response: API response confirming whether upload was successful.
Example addresses file upload:
> infilepath='../data/external/test-addresses.txt'
> client.upload(infilepath=infilepath).json()
{'upload': {'status': 'OK'}}
Example salt file upload (optional)
> infilepath='../data/external/test.EncryptedSalt'
> client.upload(infilepath=infilepath).json()
{"upload": { "status": "SALTOK"}}*
AssignAPIClient.download
AssignAPIClient.download (infilepath:str, outfilepath:str='../data/processed/assign- uprn.tsv')
*Download TSV data matching a previously uploaded file of TSV addresses.
Args: infilepath (str): Filename of the previously uploaded file. outfilepath (str): Filepath to store the response in, defaults to ‘../data/processed/assign-uprn.tsv’
Returns: requests.Response: API response containing content to output to TSV file.
Example:
> infilepath = '../data/external/test-addresses.txt'
> outfilepath = '../data/processed/assign-uprn.tsv'
> client.download(infilepath, outfilepath).status_code
200*