personnummer

Validate Swedish personal identity numbers


Keywords
hacktoberfest, personal-identity-number, personnummer, python, social-security-number, validation
License
MIT
Install
pip install personnummer==3.0.3

Documentation

personnummer Build Status

Validate Swedish personal identity numbers. Version 3+ only supports Python 3.

Installation

pip install personnummer

or

pip3 install personnummer

Examples

  • All examples that uses personnummer.Personnumer([params]), can be replaced with personnummer.parse([params]).

Validation

from personnummer import personnummer

personnummer.valid("8507099805")
# => True

personnummer.valid("198507099805")
# => True

Format

from personnummer import personnummer

# Short format
pn = personnummer.Personnummer(8507099805)
pn.format()
# => '850709-9805'

# Long format
pn = personnummer.Personnummer('8507099805')
pn.format(True)
# => '198507099805'

Get Age

from personnummer import personnummer

pn = personnummer.Personnummer("19121212+1212")
pn.get_age()
# => 106

See personnummer/tests/test_personnummer.py for more examples.

License

MIT