Skip to main content

Spanish DNI

SD is a library of utilities for the Python programming language that allows validating both NIE and NIF. It also can be used to generate NIF/NIE list.

Installation

Can be installed via PiPI.

pip install spanish-dni

How to use it

Sample code to validate NIF/NIE list.

from spanish_dni.dni import DNI
from spanish_dni.validator.exceptions import NotValidDNIException
from spanish_dni.validator import validate_dni

my_dnis: list[str] = [
    "23414538D",
    "Y2853959H",
    "23418D",
    "U2853959H",
    "23414538T",
]

for dni in my_dnis:
    valid = True
    try:
        dni_parsed: DNI = validate_dni(dni)
        print(f"DNI {dni} is type {dni_parsed.dni_type}")
    except NotValidDNIException:
        valid = False
        print(f"DNI {dni} is not valid")

Sample code to generate random NIF list of 8 elements with no initial characters provided.

from spanish_dni.generator import generate_dni


for _ in range(8):
    print(generate_dni())

Sample code to generate random NIF list of 8 elements which all of them start with number 0.

from spanish_dni.generator import generate_dni


for _ in range(8):
    print(generate_dni(first_characters="0"))

Sample code to generate random NIE list of 8 elements.

from spanish_dni.generator import generate_dni


for _ in range(8):
    print(generate_dni(is_nie=True))

Limitations

For the moment, it can not be used to generate random NIE with first character parameter. If it is tried, it will raise an IncompatibleParametersDNIGeneratorException exception.

Release files for spanish-dni 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spanish-dni 1.0.3
File Size Uploaded
spanish_dni-1.0.3.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spanish-dni 1.0.3
File Interpreter ABI Platform
spanish_dni-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / spanish_dni-1.0.3.tar.gz

Download URL spanish_dni-1.0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c0f2399c94150705f9f287aead57dfcac904093a4005cb59149838850e31cf53
BLAKE2b-256 checksum
How to use checksums
e2e6a050d91407ee916bf199b77ee3c921817dab79d7a4fc870bd745304c143d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.4

Release files / spanish_dni-1.0.3-py3-none-any.whl

Download URL spanish_dni-1.0.3-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8755f7d83e842dfd56c1a339a927cbf58bc6bd03d52077bb278fe615ddeac590
BLAKE2b-256 checksum
How to use checksums
4e3fdff7de35122dccbd41d4468d67f546b1a8084c036a253fc79056c1f097af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page