Skip to main content

Pydantic validators for spanish identification codes: NIF, DNI and NIE.

Project description

spanish-nif

Pydantic validators for spanish identification codes: NIF, DNI and NIE.

Documentation


⚠️ AI-generated library: This library may contain severe vulnerabilities and should not be trusted for critical workflows. Use at your own risk; it was produced with the Codex AI assistant.

This library turns Spanish identification numbers into first-class Python types. Each class (NIF, DNI, NIE) subclasses str, validates its control letter on construction, and plugs straight into Pydantic so you can drop it into your data models without writing bespoke validators.

Installation

  • pip

    python -m pip install spanish-nif
    
  • uv

    uv pip install spanish-nif
    

Quick examples

from spanish_nif import DNI, NIE, NIF

DNI("12345678Z")          # returns a validated DNI string
NIE.is_valid("X1234567L") # -> True
NIF("K0867756N").variant  # -> "legacy"
from pydantic import BaseModel
from spanish_nif import NIF

class TaxPayer(BaseModel):
    nif: NIF

tax_payer = TaxPayer(nif="12345678Z")
assert tax_payer.nif == "12345678Z"
  • Invalid inputs raise an InvalidIdentification subclass with a helpful message.
  • Normalisation uppercases the value and validates the control-letter sequence; inputs must already be correctly formatted.

Related Projects

  • validarnif – Python module exposing procedural validators for NIF/NIE/CIF and optional preprocessing utilities; spanish-nif instead wraps those rules in reusable string subclasses with Pydantic/JSON Schema integration.
  • spanish-dni – Python package with validator functions and generators focused on list processing; our library prioritises strong typing and schema metadata for application models.
  • spain-id – TypeScript/Node toolkit validating NIF/NIE/CIF in browser and server environments, whereas spanish-nif targets Python workflows.
  • ulabox/nif-validator – PHP utility offering static isValid* helpers for CIF, DNI and NIE; our package emphasises typed models and Pydantic interoperability rather than imperative checks.
  • criptalia/spanish_dni_validator – Go port of the ulabox/NIF validator covering DNI, NIE and CIF with IsValid* helpers; spanish-nif instead provides Python string subclasses with declarative Pydantic integration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spanish_nif-0.3.1.tar.gz (98.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spanish_nif-0.3.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file spanish_nif-0.3.1.tar.gz.

File metadata

  • Download URL: spanish_nif-0.3.1.tar.gz
  • Upload date:
  • Size: 98.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spanish_nif-0.3.1.tar.gz
Algorithm Hash digest
SHA256 09959341df611e51086b8d421e9879421b71f82ddf15ff5e62320bf4319a9dab
MD5 bd91b8ce069cb38a5607fe4306d2f198
BLAKE2b-256 31dde1739dbe793bf93d828fd70f761ff80c6bbb39d67c3f7e60ea73ed1e8db1

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanish_nif-0.3.1.tar.gz:

Publisher: publish.yml on haztecaso/spanish-nif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spanish_nif-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: spanish_nif-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spanish_nif-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe6eb9d241c1fe41d56a7cf4b231e150ab254a5b9e806a98a40da0e4d847b4eb
MD5 678146f51425fa0e4406180bc559e686
BLAKE2b-256 ada301618138d4996c82fa1bdd69a9a7563a8f293c30d9bf03b9037696144e82

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanish_nif-0.3.1-py3-none-any.whl:

Publisher: publish.yml on haztecaso/spanish-nif

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page