Developer interface¶
Main Interface¶
Examples for the most relevant api functions can be viewed in the test file. get_vat_eu’s API uses type hints instead of assertions to check input and output types.
-
get_vat_eu.
request_vat_information
(vat_number: str, country_code: str = 'IT') → dict¶ Make a SOAP request and expect a response.
Parameters: - vat_number (str) – the vat number identifier.
- country_code (str) – a two letter uppercase country identifier.
Returns: a data structure containing the SOAP response.
Return type: dict
Raises: VIESServiceError or a built-in exception.
-
get_vat_eu.
parse_address_string
(address_string: str, country_code: str = 'IT') → dict¶ Get relevant information from the address string.
Parameters: - address_string (str) – a string containing all the address information.
- country_code (str) – a two letter uppercase country identifier.
Returns: a data structure with keys differing from country code to country code.
Return type: dict
Raises: AddressStringNotCorrespondingToExpectedFormat or a built-in exception.
-
get_vat_eu.
vat_adheres_to_specifications
(vat_number: str, country_code: str = 'IT') → bool¶ Check that the VAT number corresponds to the specifications.
Parameters: - vat_number (str) – the vat number identifier.
- country_code (str) – a two letter uppercase country identifier.
Returns: True
if the VAT number adheres to the specifications,False
otherwise.Return type: bool
Raises: a built-in exception.
-
get_vat_eu.
parse_response
(response: dict, vat_number: str, country_code: str = 'IT') → dict¶ Parses the response and get the relevant fields.
Parameters: - response (dict) – a data structure containing the SOAP response.
- vat_number (str) – the vat number identifier.
- country_code (str) – a two letter uppercase country identifier.
Returns: a data structure with keys differing from country code to country code.
Return type: dict
Raises: ResponseIOError, ResponseVatNumberNotConforming, CannotGetTraderName, CannotGetTraderAddress, CountryCodeNotImplemented, VatNotValid, or a built-in exception.
-
get_vat_eu.
prettify_trader_information
(information: dict, country_code: str = 'IT')¶ Capitalize the first letter of each word in the fields.
Parameters: - information (dict) – a data structure containing the trader information.
- country_code (str) – a two letter uppercase country identifier.
Returns: None
Return type: None
Raises: a built-in exception.
-
get_vat_eu.
pipeline
(vat_number: str, country_code: str = 'IT', trader_information_pretty=True, show_input=True) → str¶ Execute the pipeline.
Parameters: - vat_number (str) – the vat number identifier.
- country_code (str) – a two letter uppercase country identifier.
- trader_information_pretty (bool) – change the capitalization of the elements to something more human readable.
- show_input (bool) – return the country code and the vat number along with the normal output.
Returns: a data structure with all the relevant fields.
Return type: dict
Raises: a built-in exception.
Exceptions¶
-
exception
get_vat_eu.
VIESServiceError
¶ The remote API is fauly for some reason.
-
exception
get_vat_eu.
ResponseIOError
¶ Input and expected output differ.
-
exception
get_vat_eu.
ResponseVatNumberNotConforming
¶ The VAT number returned by the API does not conform to specifications.
-
exception
get_vat_eu.
CannotGetTraderName
¶ The API does not know what the address.
-
exception
get_vat_eu.
CannotGetTraderAddress
¶ The API does not know what the address is.
-
exception
get_vat_eu.
VatNotValid
¶ The input VAT is not valid.
-
exception
get_vat_eu.
AddressStringNotCorrespondingToExpectedFormat
¶ The address string does not correspond to the expected format.
-
exception
get_vat_eu.
CountryCodeNotImplemented
¶ The specified country has no implementation yet.