Skip to main content

Validate Swedish personal identity numbers

Project description

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 Date

New in version 3.2.0

from personnummer import personnummer

pn = personnummer.Personnummer('19121212+1212')
pn.get_date()
# => datetime.date(1912, 12, 12)

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

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

personnummer-3.2.1.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

personnummer-3.2.1-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

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