Codice Fiscale (Italian tax code for individuals).

The Codice Fiscale is an alphanumeric code of 16 characters used to identify individuals residing in Italy. The number consists of three characters derived from the person’s last name, three from the person’s first name, five that hold information on the person’s gender and birth date, four that represent the person’s place of birth and one check digit.

>>> validate('RCCMNL83S18D969H')
>>> validate('RCCMNL83S18D969')
Traceback (most recent call last):
InvalidLength: ...
>>> calc_check_digit('RCCMNL83S18D969')

Compute the control code for the given number. The passed number should be the first 15 characters of a fiscal code.

Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace., minyear=1920)

Get the birth date from the person’s fiscal code.

Only the last two digits of the year are stored in the number. The dates will be returned in the range from minyear to minyear + 100.

>>> get_birth_date('RCCMNL83S18D969H'), 11, 18)
>>> get_birth_date('RCCMNL83S18D969H', minyear=1990), 11, 18)

Get the gender of the person’s fiscal code.

>>> get_gender('RCCMNL83S18D969H')
>>> get_gender('CNTCHR83T41D969D')

Check if the given fiscal code is valid.

Check if the given fiscal code is valid. This checks the length and whether the check digit is correct.