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

python -m 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.2.0.tar.gz (96.6 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.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spanish_nif-0.2.0.tar.gz
  • Upload date:
  • Size: 96.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 7254c5f5cfc62db1bb71a5aa00e748f8505dd15ffeee0a036e0e999c309b5c01
MD5 c8c08a92d7b8e7681b637f223be9f57d
BLAKE2b-256 d1704b4691a9ab80998cb04a5a3c2bf246c472f242fac2d0467410e9d40fd4a9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: spanish_nif-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5b4b740d9ae1261b3fbc9e823221a91588714ce66403c379153ffe6a4e8fd84
MD5 f8c6b1db40a58ec5981b002f09541316
BLAKE2b-256 b8f23ecd4a6f2b8db1d0a02b4f486390b41cf8d60f469a02941ebab54cd6c2e2

See more details on using hashes here.

Provenance

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