stdnum.dk.cpr¶
CPR (personnummer, the Danish citizen number).
The CPR is the national number to identify Danish citizens and is stored in the Det Centrale Personregister (Civil Registration System). The number consists of 10 digits in the format DDMMYY-SSSS where the first part represents the birth date and the second a sequence number. The first digit of the sequence number indicates the century.
The numbers used to validate using a checksum but since the sequence numbers ran out this was abandoned in 2007. It is also not possible to use the checksum only for numbers that have a birth date before that because the numbers are also assigned to immigrants.
More information:
>>> validate('211062-5629')
'2110625629'
>>> checksum('2110625629')
0
>>> validate('511062-5629') # invalid date
Traceback (most recent call last):
...
InvalidComponent: ...
>>> validate('2110525629')
Traceback (most recent call last):
...
InvalidComponent: The birth date information is valid, but this person has not been born yet.
>>> get_birth_date('2110620629')
datetime.date(1962, 10, 21)
>>> format('2110625629')
'211062-5629'
- stdnum.dk.cpr.checksum(number)¶
Calculate the checksum. Note that the checksum isn’t actually used any more. Valid numbers used to have a checksum of 0.
- stdnum.dk.cpr.compact(number)¶
Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.
- stdnum.dk.cpr.format(number)¶
Reformat the number to the standard presentation format.
- stdnum.dk.cpr.get_birth_date(number)¶
Split the date parts from the number and return the birth date.
- stdnum.dk.cpr.is_valid(number)¶
Check if the number provided is a valid CPR number. This checks the length, formatting, embedded date and check digit.
- stdnum.dk.cpr.validate(number)¶
Check if the number provided is a valid CPR number. This checks the length, formatting, embedded date and check digit.