How to validate a VAT number in Python

Let’s take a quick look at how to apply a Cloudmersive API to validation of VAT numbers. For Python users, the first step is to add the API client to your pip installer:

pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.Validate.git

Next we call the function vat_vat_lookup:

from __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Apikey'] = 'Bearer'
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.VatApi(cloudmersive_validate_api_client.ApiClient(configuration))
input = cloudmersive_validate_api_client.VatLookupRequest() # VatLookupRequest | Input VAT code
try:
# Lookup a VAT code
api_response = api_instance.vat_vat_lookup(input)
pprint(api_response)
except ApiException as e:
print("Exception when calling VatApi->vat_vat_lookup: %s\n" % e)

And boom, we are done. The function will return a bevy of useful information about the VAT number in question along with its validity: the name of the company, its physical address, and the code of the country in which it is located.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store