-
Notifications
You must be signed in to change notification settings - Fork 125
/
README.rst
executable file
·391 lines (275 loc) · 16 KB
/
README.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
MRZ Generator & MRZ Checker
===========================
Description:
------------
Machine Readable Zone generator and checker for official travel
documents sizes 1, 2, 3, MRVA and MRVB (Passports, Visas, national id
cards and other travel documents)
MRZ Generator and MRZ Checker are built according to International Civil
Aviation Organization specifications (ICAO 9303):
- `Specifications Common to all Machine Readable Travel Documents
(MRTDs) <https://www.icao.int/publications/Documents/9303_p3_cons_en.pdf>`__
- `Specifications for Machine Readable Passports
(MRPs) <https://www.icao.int/publications/Documents/9303_p4_cons_en.pdf>`__
- `Specifications for TD1 Size Machine Readable Official Travel
Documents
(MROTDs) <https://www.icao.int/publications/Documents/9303_p5_cons_en.pdf>`__
- `Specifications for TD2 Size Machine Readable Official Travel
Documents
(MROTDs) <https://www.icao.int/publications/Documents/9303_p6_cons_en.pdf>`__
- `Specifications for Machine Readable Visas
(MRV) <https://www.icao.int/publications/Documents/9303_p7_cons_en.pdf>`__
See all 9303 ICAO docs (`البيت العربي <https://github.com/Arg0s1080/mrz/tree/master/docs/ICAO9303/Arab/Files_ar.rst>`__, `中文 <https://github.com/Arg0s1080/mrz/tree/master/docs/ICAO9303/Chinese/Files_zh.rst>`__, `English <https://github.com/Arg0s1080/mrz/tree/master/docs/ICAO9303/English/Files_en.rst>`__, `Français <https://github.com/Arg0s1080/mrz/tree/master/docs/ICAO9303/French/Files_fr.rst>`__, `Русский <https://github.com/Arg0s1080/mrz/tree/master/docs/ICAO9303/Russian/Files_ru.rst>`__ and `Español <https://github.com/Arg0s1080/mrz/tree/master/docs/ICAO9303/Spanish/Files_es.rst>`__)
Fields Distribution of Official Travel Documents:
-------------------------------------------------
.. figure:: https://raw.githubusercontent.com/Arg0s1080/mrz/master/docs/Fields_Distribution.png
:alt: image
image
Usage Generator:
----------------
TD1’s (id cards):
^^^^^^^^^^^^^^^^^
::
Params: Case insensitive
document_type (str): The first letter shall be 'I', 'A' or 'C'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
document_number (str): Document number
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
nationality (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Holder primary identifier(s). This field will be transliterated
given_names (str): Holder secondary identifier(s). This field will be transliterated
optional_data1 (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default
optional_data2 (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
TD2
^^^
::
Params: Case insensitive
document_type (str): The first letter shall be 'I', 'A' or 'C'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Holder primary identifier(s). This field will be transliterated.
given_names (str): Holder secondary identifier(s). This field will be transliterated.
document_number (str): Document number.
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional_data (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
TD3 (Passports)
^^^^^^^^^^^^^^^
::
Params: Case insensitive
document_type (str): Normally 'P' for passport
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Primary identifier(s)
given_names (str): Secondary identifier(s)
document_number (str): Document number
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional data (str): Personal number. In some countries non-mandatory field. Empty string by default
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
MRVA (Visas type A)
^^^^^^^^^^^^^^^^^^^
::
Params: Case insensitive
document_type (str): The First letter must be 'V'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Primary identifier(s)
given_names (str): Secondary identifier(s)
document_number (str): Document number
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional_data (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default.
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
MRVB (Visas type B)
^^^^^^^^^^^^^^^^^^^
::
Params: Case insensitive
document_type (str): The First letter must be 'V'
country_code (str): 3 letters code (ISO 3166-1) or country name (in English)
surname (str): Primary identifier(s)
given_names (str): Secondary identifier(s)
document_number (str): Document number
nationality (str): 3 letters code (ISO 3166-1) or country name
birth_date (str): YYMMDD
sex (str): Genre. Male: 'M', Female: 'F' or Undefined: 'X', "<" or ""
expiry_date (str): YYMMDD
optional_data (str): Optional personal data at the discretion of the issuing State.
Non-mandatory field. Empty string by default.
transliteration (dict): Transliteration dictionary for non-ascii chars. Latin based by default
force (bool): Disables checks for country, nationality and document_type fields.
Allows to use 3-letter-codes not included in the countries dictionary
and to use document_type codes without restrictions.
Passport generator example (ICAO9303 Specimen):
'''''''''''''''''''''''''''''''''''''''''''''''
.. figure:: https://raw.githubusercontent.com/Arg0s1080/mrz/master/docs/images/passports/ICAO_Example.png
:alt: image
image
TD3CodeGenerator -> str:
''''''''''''''''''''''''
.. code:: python
from mrz.generator.td3 import TD3CodeGenerator
code = TD3CodeGenerator("P", "UTO", "Eriksson", "Anna María", "L898902C3", "UTO", "740812", "F", "120415","ZE184226B")
print(code)
Output:
'''''''
::
P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<
L898902C36UTO7408122F1204159ZE184226B<<<<<10
Note: See other uses in `mrz.generator examples folder <https://github.com/Arg0s1080/mrz/tree/master/examples/mrz_generator_samples>`__
Usage Checker:
--------------
.. _td1s-id-cards-1:
TD1’s (id cards):
^^^^^^^^^^^^^^^^^
::
Params:
mrz_string (str): MRZ string of TD1. Must be 90 uppercase characters long (3 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
.. _td2-1:
TD2:
^^^^
::
Params:
mrz_string (str): MRZ string of TD2. Must be 72 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
.. _td3-passports-1:
TD3 (Passports):
^^^^^^^^^^^^^^^^
::
Params:
mrz_string (str): MRZ string of TD3. Must be 88 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
MRVA:
^^^^^
::
Params:
mrz_string (str): MRZ string of Visas type A. Must be 88 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
MRVB:
^^^^^
::
Params:
mrz_string (str): MRZ string of Visas type B. Must be 72 characters long (uppercase) (2 lines)
check_expiry (bool): If it's set to True, it is verified and reported as warning that the
document is not expired and that expiry_date is not greater than 10 years
compute_warnings (bool): If it's set True, warnings compute as False
Id Card Checker example
'''''''''''''''''''''''
.. figure:: https://raw.githubusercontent.com/Arg0s1080/mrz/master/docs/images/id_cards/Sweden.png
:alt: image
image
TD1CodeChecker -> bool
''''''''''''''''''''''
.. code:: python
from mrz.checker.td1 import TD1CodeChecker
check = TD1CodeChecker("I<SWE59000002<8198703142391<<<\n"
"8703145M1701027SWE<<<<<<<<<<<8\n"
"SPECIMEN<<SVEN<<<<<<<<<<<<<<<<")
result = bool(check)
print(result)
.. _output-1:
Output
''''''
::
True
Note: See other uses in `mrz.checker examples folder <https://github.com/Arg0s1080/mrz/tree/master/examples/mrz_checker_samples>`__
Fields extraction example (valid for td1, td2, td3 and visas)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
.. code:: python
from mrz.checker.td1 import TD1CodeChecker, get_country
td1_check = TD1CodeChecker("IDLIEID98754015<<<<<<<<<<<<<<<\n"
"8205122M1906224LIE<<<<<<<<<<<6\n"
"OSPELT<BECK<<MARISA<<<<<<<<<<<")
fields = td1_check.fields()
print(fields.name, fields.surname)
print(get_country(fields.country))
.. _output-2:
Output
''''''
::
MARISA OSPELT BECK
Liechtenstein
Note: See other uses in `mrz.checker examples folder <https://github.com/Arg0s1080/mrz/tree/master/examples/mrz_checker_samples>`__ and `this issue <https://github.com/Arg0s1080/mrz/issues/6>`__
Installation:
-------------
From `Pypi repo <https://pypi.org/project/mrz/>`__ (It may not be the latest version):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
pip install mrz
Cloning this repo (It may not work fine):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
git clone https://github.com/Arg0s1080/mrz.git
cd mrz
sudo python3 setup.py install
Features:
---------
- [x] Transliteration of special Latin characters (acutes, tildes,
diaeresis, graves, circumflex, etc)
- [x] Arabic chars transliteration
- [x] Several variations of Cyrillic added: Serbian, Macedonian,
Belarusian, Ukrainian and Bulgarian
- [x] Transliteration of modern Greek (experimental)
- [x] Transliteration of modern Hebrew (without vowels) (experimental)
- [x] Generation of the country code from its name in English (Ex.:
“Netherlands” -> “NLD”)
- [x] Name truncation detection
- [x] Error report, warnings report and full report in Checker.
- [x] Possibility that warnings compute as errors using
compute_warnings keyword in Checker.
- [x] Possibility of disabling checks for country code, nationality and
type of document, allowing to use 3-letter-codes not included in the
countries dictionary and to use document_type codes without
restrictions in Generator.
- [x] Added new checks for periods of time in Checker.
- [x] Visas support
- [x] Fields extraction in checker (name, surname, country, sex, etc)
(version 0.5.0)
TODO:
- [ ] Automatic name truncation in Generator
- [ ] Possibility of disabling checks for country code, nationality,
type of document and the others fields in Checker.
- [ ] Add logging
IMPORTANT:
~~~~~~~~~~
- MRZ is a Python module to be used as library in other programs. So,
its intended audience are developers. **MRZ will never have a user
interface nor will have CLI support.** (Of course.. if someone wants,
can do it) However, **if someone is curious and wants to generate or
check the mrz code of a passport or ID card, can modify any of
the**\ `examples <https://github.com/Arg0s1080/mrz/tree/master/examples>`__.
- Right now I am very busy and have very little free time. Please,
before creating an issue or consulting by email, read `this
issue <https://github.com/Arg0s1080/mrz/issues/31>`__