Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI EU VAT Validation

EuroValidate

Validate EU VAT numbers with FastAPI and auto-generated Swagger docs. Uses dependency injection for clean, testable code.

Quick Start

  1. Get your API key at eurovalidate.com
  2. Clone and install
    git clone https://github.com/eurovalidate/fastapi-vat-example.git
    cd fastapi-vat-example
    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 main.py
    # Open http://localhost:8000/docs for Swagger UI

What This Does

  • GET /validate?vat_number=NL820646660B01 -- validate a single VAT number
  • POST /validate/batch -- validate up to 10 VAT numbers in one request
  • Auto-generated Swagger UI at /docs with example values and response models
  • Dependency injection keeps the EuroValidate client clean and testable

Key Code

EuroValidate as a FastAPI dependency:

from eurovalidate import EuroValidate

def get_eurovalidate() -> EuroValidate:
    return EuroValidate(api_key=os.environ["EUROVALIDATE_API_KEY"])

EuroValidateClient = Annotated[EuroValidate, Depends(get_eurovalidate)]

@app.get("/validate")
async def validate_vat(
    vat_number: str,
    client: EuroValidateClient,
):
    result = client.vat.validate(vat_number)
    return result

Try It

# Single validation
curl "http://localhost:8000/validate?vat_number=NL820646660B01"

# Batch validation
curl -X POST http://localhost:8000/validate/batch \
  -H "Content-Type: application/json" \
  -d '{"items": [{"vat_number": "NL820646660B01"}, {"vat_number": "FR40303265045"}]}'

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
  },
  "request_id": "req_abc123"
}

Test VAT Numbers

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

Links

License

MIT

About

FastAPI dependency injection example for EU VAT validation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages