vat_validator.countries

vat_validator.countries.EU_COUNTRY_CODES = {'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'EL', 'ES', 'FI', 'FR', 'GB', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SK', 'SL'}

Set of European Union country code

vat_validator.inspectors

vat_validator.validators

This module contains a set of functions to validate a VAT number according to a country VAT format rules. Besides the general regex match, the validation functions perform some country specific calculations on the digits using algorithms such as MOD 11 or Lunh’s algorithm.

All of these functions are in the format vat_is_valid_XX where XX is the IS0 3166 country code. They receive a string representing a VAT number in that country format and return True or False whether that code is valid or not.

Usage:

>>> vat_is_valid_pt('PT980405319')
True
>>> vat_is_valid_pt('PT-980 405 319')
True
>>> vat_is_valid_pt('980405319')
False

Each function is responsible to sanitize the input (remove preceding country code, spaces, punctuation, etc…)

See also

The list of VAT validation algorithms are published here: https://ec.europa.eu/taxation_customs/tin/

This wikipedia page contains a great overview of the different formats: https://en.wikipedia.org/wiki/VAT_identification_number

vat_validator.vies

This module allows interaction with VIES (VAT Information Exchange Service) web service. It can be used to validate VAT codes and fetch other information from the entity with that VAT.

Usage:

>>> check_vat('PT', '502011378')
CheckVATResult(country_code='PT',
               vat='502011378',
               request_date=2019-08-01 00:00:00+02:00,
               valid=True,
               name='UNIVERSIDADE DO MINHO',
               address='LG DO PACO\nBRAGA\n4700-320 BRAGA')

See also

VIES on the European Comission website: http://ec.europa.eu/taxation_customs/vies/

The functions hereby described operate on this WSDL url: http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

class vat_validator.vies.CheckVATResult(country_code, vat, request_date, valid, name, address)[source]

Represents the result obtained by running the function check_vat().

Parameters
  • country_code (str) – IS0 3166 country code.

  • vat (str) – VAT number.

  • request_date (Optional[date]) – date when this result was queried.

  • valid (bool) – whether this VAT is valid or not.

  • name (Optional[str]) – optional name of the entity associated with this VAT.

  • address (Optional[str]) – optional address of the entity associated with this VAT.

vat_validator.vies.check_vat(country_code, vat)[source]

Checks if given VAT code is valid and (if possible) fetches the name and address of the entity with that code.

Parameters
  • country_code (str) – valid IS0 3166 country code.

  • vat (str) – VAT number to check.

Return type

CheckVATResult

Returns

instance of CheckVATResult.

Raises

ValueError – when the country code is invalid or the VAT is empty.