# stdnum.fr.nir

NIR (French personal identification number).

The NIR (Numero d’Inscription au Repertoire national d’identification des personnes physiques) is used to identify persons in France. It is popularly known as the “social security number” and sometimes referred to as an INSEE number. All persons born in France are registered in the Repertoire national d’identification des personnes physiques (RNIPP) and assigned a NIR.

The number consists of 15 digits: the first digit indicates the gender, followed by 2 digits for the year or birth, 2 for the month of birth, 5 for the location of birth (COG), 3 for a serial and 2 check digits.

More information:

- https://www.insee.fr/en/metadonnees/definition/c1409

- https://en.wikipedia.org/wiki/INSEE_code

- http://resoo.org/docs/_docs/regles-numero-insee.pdf

- https://fr.wikipedia.org/wiki/Numéro_de_sécurité_sociale_en_France

- https://xml.insee.fr/schema/nir.html

    >>> validate('2 95 10 99 126 111 93')
    '295109912611193'
    >>> validate('295109912611199')  # invalid check digit
    Traceback (most recent call last):
        ...
    InvalidChecksum: ...
    >>> validate('253072B07300470')
    '253072B07300470'
    >>> validate('253072A07300443')
    '253072A07300443'
    >>> validate('253072C07300443')
    Traceback (most recent call last):
        ...
    InvalidFormat: ...
    >>> validate('6546546546546703')
    Traceback (most recent call last):
        ...
    InvalidLength: ...
    >>> format('295109912611193')
    '2 95 10 99 126 111 93'

stdnum.fr.nir.calc_check_digits(number)

  Calculate the check digits for the number.

stdnum.fr.nir.compact(number)

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

stdnum.fr.nir.format(number, separator=' ')

  Reformat the number to the standard presentation format.

stdnum.fr.nir.is_valid(number)

  Check if the number provided is valid.

stdnum.fr.nir.validate(number)

  Check if the number provided is valid. This checks the length and check digits.