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.

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.0.tar.gz (96.9 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.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spanish_nif-0.3.0.tar.gz
  • Upload date:
  • Size: 96.9 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.0.tar.gz
Algorithm Hash digest
SHA256 8903fddac57a8cfcc182aca6f190b491433d712faddc94a86351cc92b9b30d82
MD5 ba2dbd09ddafa4dbc0ff6b514bc18deb
BLAKE2b-256 d12626f346e9bb140ae6529ebbe3667870cc6f4a26f54fe99bbe5f80a3fdbd3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanish_nif-0.3.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: spanish_nif-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2da5e4f1375ad3c9dfa2228222fd6dc881d0ee3da7254c7af9f10c96398a2d1a
MD5 d1d8e997a569ab5972c171cad50d7cdc
BLAKE2b-256 e0973c2c19968648616a9e89c15befb08fd2ef84fea51c11a7e88e015ef28dcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for spanish_nif-0.3.0-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