api calls

python functions wrapping address-to-uprn matching api calls

functions


source

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

source

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

source

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*