stdnum.se.personnummer

Personnummer (Swedish personal identity number).

The Swedish Personnummer is assigned at birth to all Swedish nationals and to immigrants for tax and identification purposes. The number consists of 10 or 12 digits and starts with the birth date, followed by a serial and a check digit.

More information:

>>> validate('880320-0016')
'880320-0016'
>>> validate('880320-0018')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> get_gender('890102-3286')
'F'
>>> get_birth_date('811228-9841')
datetime.date(1981, 12, 28)
>>> format('8803200016')
'880320-0016'
stdnum.se.personnummer.compact(number)

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

stdnum.se.personnummer.format(number)

Reformat the number to the standard presentation format.

stdnum.se.personnummer.get_birth_date(number)

Determine the birth date from the number.

For people aged 100 and up, the minus/dash in the personnummer is changed to a plus on New Year’s Eve the year they turn 100.

See Folkbokföringslagen (1991:481), §18.

stdnum.se.personnummer.get_gender(number)

Get the person’s birth gender (‘M’ or ‘F’).

stdnum.se.personnummer.is_valid(number)

Check if the number is a valid identity number.

stdnum.se.personnummer.validate(number)

Check if the number is a valid identity number.