stdnum.it.codicefiscale

Codice Fiscale (Italian tax code for individuals).

The Codice Fiscale is an alphanumeric code of 16 characters used to identify individuals residing in Italy or 11 digits for non-individuals in which case it matches the Imposta sul valore aggiunto.

The 16 digit 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.

More information:

>>> validate('RCCMNL83S18D969H')  # personal number
'RCCMNL83S18D969H'
>>> validate('RCCMNL83S18D969')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> validate('00743110157')  # company number
'00743110157'
>>> validate('00743110158')  # company number with invalid check digit
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> calc_check_digit('RCCMNL83S18D969')
'H'
stdnum.it.codicefiscale.calc_check_digit(number)

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

stdnum.it.codicefiscale.compact(number)

Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.it.codicefiscale.get_birth_date(number, 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')
datetime.date(1983, 11, 18)
>>> get_birth_date('RCCMNL83S18D969H', minyear=1990)
datetime.date(2083, 11, 18)
stdnum.it.codicefiscale.get_gender(number)

Get the gender of the person’s fiscal code.

>>> get_gender('RCCMNL83S18D969H')
'M'
>>> get_gender('CNTCHR83T41D969D')
'F'
stdnum.it.codicefiscale.is_valid(number)

Check if the given fiscal code is valid.

stdnum.it.codicefiscale.validate(number)

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