send_the_raven.validator.Validator#

class send_the_raven.validator.Validator[source]#

Bases: Addresses

Class to validate addresses to USPS database.

Parameters:
  • data (Addresses) – Addresses to validate.

  • usps_id (str) – USPS ID to use for validation. Get it here.

  • request_limit (int) – Maximum number of requests per second.

data#

full address.

Type:

list[Address]

results#

validated addresses.

Type:

list[Addresses]

errors#

addresses with errors.

Type:

list[tuple[Address, Exception]]

Example

>>> addresses = [
    {"street": "123 Main St", "city": "Anytown", "state": "CA", "zip": "12345"},
    {"street": "456 Oak Rd", "city": "Forest", "state": "VT", "zip": "67890"}
]
>>> validator = Validator(addresses, usps_id="MY_ID")
>>> valid_addresses = validator()
>>> for addr in valid_addresses:
>>>     print(addr.street, addr.city, addr.state, addr.zip_code)
__init__(addresses, usps_id, request_limit=10, field_mapping={'address_line_2': 'address_line_2', 'city': 'city', 'full_address': 'full_address', 'id': 'id', 'state': 'state', 'street': 'street', 'zip_code': 'zip_code'})[source]#
Parameters:
__call__()[source]#

Start validation process. Will return after all async process are completed.

Returns:

validated addresses.

Return type:

Addresses

Methods

__eq__(value, /)

Return self==value.

__getitem__(index)

__init__(addresses, usps_id[, ...])

__iter__()

__len__()

normalize_parallel([number_of_proccesses])

Normalize all addresses in parallel.

start_validation()

Initialize aiohttp TCPConnector with limit and ClientSession.

validate(data, client)

Request validation data to USPS database

__init__(addresses, usps_id, request_limit=10, field_mapping={'address_line_2': 'address_line_2', 'city': 'city', 'full_address': 'full_address', 'id': 'id', 'state': 'state', 'street': 'street', 'zip_code': 'zip_code'})[source]#
Parameters:
normalize_parallel(number_of_proccesses=None)#

Normalize all addresses in parallel. Uses multiprocessing.Pool.map().

Parameters:

number_of_proccesses (int) – number of process

async start_validation()[source]#

Initialize aiohttp TCPConnector with limit and ClientSession. Start validation in asyncio.

async validate(data, client)[source]#

Request validation data to USPS database

Parameters: