Pydantic validators for spanish identification codes: NIF, DNI and NIE.
Project description
spanish-nif
⚠️ 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
InvalidIdentificationsubclass 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7254c5f5cfc62db1bb71a5aa00e748f8505dd15ffeee0a036e0e999c309b5c01
|
|
| MD5 |
c8c08a92d7b8e7681b637f223be9f57d
|
|
| BLAKE2b-256 |
d1704b4691a9ab80998cb04a5a3c2bf246c472f242fac2d0467410e9d40fd4a9
|
Provenance
The following attestation bundles were made for spanish_nif-0.2.0.tar.gz:
Publisher:
publish.yml on haztecaso/spanish-nif
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spanish_nif-0.2.0.tar.gz -
Subject digest:
7254c5f5cfc62db1bb71a5aa00e748f8505dd15ffeee0a036e0e999c309b5c01 - Sigstore transparency entry: 660800157
- Sigstore integration time:
-
Permalink:
haztecaso/spanish-nif@72816d5b673eb36f0a82d43a1a72cdcc9e6edb28 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/haztecaso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@72816d5b673eb36f0a82d43a1a72cdcc9e6edb28 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5b4b740d9ae1261b3fbc9e823221a91588714ce66403c379153ffe6a4e8fd84
|
|
| MD5 |
f8c6b1db40a58ec5981b002f09541316
|
|
| BLAKE2b-256 |
b8f23ecd4a6f2b8db1d0a02b4f486390b41cf8d60f469a02941ebab54cd6c2e2
|
Provenance
The following attestation bundles were made for spanish_nif-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on haztecaso/spanish-nif
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spanish_nif-0.2.0-py3-none-any.whl -
Subject digest:
c5b4b740d9ae1261b3fbc9e823221a91588714ce66403c379153ffe6a4e8fd84 - Sigstore transparency entry: 660800163
- Sigstore integration time:
-
Permalink:
haztecaso/spanish-nif@72816d5b673eb36f0a82d43a1a72cdcc9e6edb28 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/haztecaso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@72816d5b673eb36f0a82d43a1a72cdcc9e6edb28 -
Trigger Event:
push
-
Statement type: