Skip to content

eurovalidate/django-vat-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django EU VAT Validation

EuroValidate

Add EU VAT number validation to your Django app. Includes a form validator, view, and template with real-time VIES lookup.

Quick Start

  1. Get your API key at eurovalidate.com
  2. Clone and install
    git clone https://github.com/eurovalidate/django-vat-validation.git
    cd django-vat-validation
    python -m venv venv && source venv/bin/activate
    pip install -r requirements.txt
  3. Configure environment
    cp .env.example .env
    # Edit .env with your EuroValidate API key
  4. Run
    python manage.py runserver
    # Open http://localhost:8000

What This Does

  • Django Form (vat_app/forms.py) with client-side format validation (country prefix, length, EU country codes)
  • View (vat_app/views.py) that calls EuroValidate API on form submit
  • Template (vat_app/templates/validate.html) showing VAT status, company name, address, and confidence level

Key Code

Form with VAT validation (vat_app/forms.py):

class VATForm(forms.Form):
    vat_number = forms.CharField(max_length=20)

    def clean_vat_number(self):
        vat = self.cleaned_data["vat_number"].strip().upper()
        # Validates format: country prefix, length, EU country codes
        return vat

View calling EuroValidate (vat_app/views.py):

from eurovalidate import EuroValidate

client = EuroValidate(api_key=settings.EUROVALIDATE_API_KEY)
response = client.vat.validate(vat_number)

result = {
    "valid": response.data.valid,
    "company_name": response.data.company_name,
    "company_address": response.data.company_address,
    "confidence": response.meta.confidence,
}

API Response

{
  "success": true,
  "data": {
    "valid": true,
    "vat_number": "NL820646660B01",
    "country_code": "NL",
    "company_name": "COOLBLUE B.V.",
    "company_address": "WEENA 00664 3012CN ROTTERDAM"
  },
  "meta": {
    "confidence": "HIGH",
    "source": "vies_live",
    "cached": false,
    "response_time_ms": 47
  }
}

Test VAT Numbers

VAT Number Country Company
NL820646660B01 Netherlands Coolblue B.V.
FR40303265045 France Google France

Links

License

MIT

About

Django form validator and view for EU VAT number validation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors