Reference
API Reference¶
Comprehensive reference for the library types, generated with mkdocstrings.
DNI¶
Bases: PydanticStringID
Validated Spanish DNI string.
A DNI comprises 8 digits followed by a control letter. The letter is derived from the numeric part modulo 23 and mapped to the sequence TRWAGMYFPDXBNJZSQVHLCKE.
Source code in src/spanish_nif/dni.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
digits property ¶
Return the zero-padded 8-digit numeric part.
letter property ¶
Return the control letter.
number property ¶
Return the numeric portion of the DNI as an integer.
is_valid(value) classmethod ¶
Return True when value is a valid DNI.
Source code in src/spanish_nif/dni.py
78 79 80 81 82 83 84 85 86 | |
random(rng=None) classmethod ¶
Return a random, valid DNI instance.
Source code in src/spanish_nif/dni.py
35 36 37 38 39 40 41 42 43 | |
Bases: InvalidIdentification
Raised when a DNI does not comply with format or control-letter rules.
Source code in src/spanish_nif/dni.py
12 13 | |
NIE¶
Bases: PydanticStringID
Validated Spanish NIE string.
Source code in src/spanish_nif/nie.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
digits property ¶
Return the 7-digit numeric part.
letter property ¶
Return the control letter.
number property ¶
Return the numeric representation used in the control-letter computation.
prefix property ¶
Return the leading status letter (X, Y or Z).
is_valid(value) classmethod ¶
Return True when value is a valid NIE.
Source code in src/spanish_nif/nie.py
83 84 85 86 87 88 89 90 91 | |
random(rng=None) classmethod ¶
Return a random, valid NIE instance.
Source code in src/spanish_nif/nie.py
31 32 33 34 35 36 37 38 39 40 41 | |
Bases: InvalidIdentification
Raised when an NIE does not comply with format or control-letter rules.
Source code in src/spanish_nif/nie.py
12 13 | |
NIF¶
Bases: PydanticStringID
Validated Spanish NIF string.
This covers natural-person identifiers: standard DNI numbers, NIE numbers (foreign residents), and K/L/M prefixes.
Source code in src/spanish_nif/nif.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
digits property ¶
Return the digits used to compute the control letter.
letter property ¶
Return the control letter.
number property ¶
Return the numeric component that drives the control letter.
variant property ¶
Return the identifier variant: dni, nie or klm.
is_valid(value) classmethod ¶
Return True when value is a valid NIF.
Source code in src/spanish_nif/nif.py
130 131 132 133 134 135 136 137 138 | |
random(rng=None, *, variant=None) classmethod ¶
Return a random, valid NIF instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rng | Random | None | Optional pseudo-random generator to use. Defaults to the module-level :mod: | None |
variant | str | None | Optional variant selector: | None |
Source code in src/spanish_nif/nif.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |