Skip to main content

An unofficial tool for generating and verifying Danish CPR-numbers.

Project description

cpr-generator - An Unofficial library and tool for generating and verifying Danish CPR-numbers.

This project contains a library and some CLI-tools for generating, manipulating and verifying Danish CPR-numbers, called "personnummer" or "CPR-nummer" in Danish, as defined by the Danish authority "Det Centrale Personregister".

Disclaimer

This is a community project that is NOT indorsed by the Danish authorities and should not be used as a reference.

Getting Started

This is available on PyPI via. pip which includes both the library and the CLI-tools. Simply install with the command:

pip install -U cpr-generator

Using the Library

The library contains a few different modules. Most important are the cpr_verifier and the generator modules.

The cpr_verifier contains three functions:

  • is_leap_year: takes a year (int) checks whether the year is a leap year.
  • is_cpr_number: takes a potential CPR-number (str) and checks that it fulfills the format: DDMMYY(-)NNNN.
  • satisfies_mod11 takes a potential CPR-number (str), checks that it fulfills both the format: DDMMYY(-)NNNN and the Modulus-11 control condition.

Using the CLI-tools

cpr-gen

This is a simple CLI tool that can generate random CPR-numbers, with or without hyphens.

Example usage:

cpr-gen -n 1000 -m False --hyphen True

The above generates a thousand CPR-numbers with hyphens, not satisfying the Modulus-11 control condition.

cpr-server

This CLI-tools starts a HTTP server (using flask) on port 5000 that can generate random CPR-numbers on demand.

Simply run:

cpr-server

And the server should be available at localhost:5000.

The server has the following available URL endpoints:

  • /: Returns a random CPR-number (no hyphen)
  • /no-mod11/: Returns a random CPR-number (no hyphen), not satisfying Modulus-11.
  • /hyphen/: Returns a random CPR-number (with hyphen)
  • /no-mod11/hyphen/: Returns a random CPR-number (with hyphen), not satisfying Modulus-11.
  • /<int:number>/: Returns number random CPR-numbers (no hyphen)
  • /no-mod11/<int:number>/: Returns number random CPR-numbers (no hyphens), not satisfying Modulus-11.
  • /hyphen/<int:number>/: Returns number random CPR-numbers (with hyphens)
  • /no-mod11/hyphen/<int:number>/: Returns number random CPR-numbers (with hyphens), not satisfying Modulus-11.

cpr-verify

This CLI-tool can be used to check the input fulfills the format of a CPR-number, with or without hyphen, and whether or not the input satisfies the Modulus-11 control condition.

Example usage:

cpr-verify 111111-1118  # --> True

The above verifies that the input 111111-1118 fulfills the CPR-number format.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpr_generator-0.2.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cpr_generator-0.2.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file cpr_generator-0.2.2.tar.gz.

File metadata

  • Download URL: cpr_generator-0.2.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cpr_generator-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7a1f5d2a10c97eac43aeed89b445f49a325e6b60e092e13b72bb5054c78ae77c
MD5 40a0176c61d0d97ec694489719011b9b
BLAKE2b-256 42d9867bd1c11848f57876bb8d16e94d8a9e8f16bd406818561a49a54cd5ba07

See more details on using hashes here.

File details

Details for the file cpr_generator-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: cpr_generator-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cpr_generator-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a0cb6e606bf712f782513651fcee8f763ab28f9df1471b12b4c050689a777b7d
MD5 6dd770d1ec8ce9fcac05db835cc982cc
BLAKE2b-256 4365793a56351f31c084f59826908ecb29d50c3b3fd146fe208a9fb9e9de70b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page