Skip to main content

library for handling Estonian national identity numbers

Project description

Python library for working with Estonian national identity numbers.

Install

Use pip to install:

pip install estnin

Documentation

Full documentation is at https://estnin.readthedocs.io/

Runnig tests

python setup.py test

Usage

Create a new estnin instance:

>>> from estnin import estnin
>>> person = estnin(37001011233)
>>> print(person.sequence)
>>> 123
>>> print(estnin(estnin.MIN))
>>> 10001010002
>>> person = estnin.create(estnin.MALE, date(1970, 1, 1), 1)
>>> print(person)
>>> 37001010018

str()

>>> assert estnin(37001010018) == "37001010018"

int()

>>> assert estnin(37001010018) == 37001010018

<, ==, >

>>> assert estnin(37001011233) < estnin(estnin.MAX)
>>> assert estnin(37001011233) > estnin(estnin.MIN)
>>> assert estnin(37001011233) == estnin(37001011233)

negation

Negation is defined as changing the sex from male to female or vice verca.

>>> assert -estnin(37001011233) == estnin(47001011234)

addition and substraction

Adding an integer increments the sequence value by given amount. If the sum of the sequence and the number given is greater than 999, then the day is incremented and the remainder is set as the new sequence value. The day, month and year values are incremented in chronological order until the defined maximum value is reached. If the year crosses the century boundary, then the century digit is also properly set.

>>> assert estnin(37001011244) == estnin(37001011233)+1
>>> assert estnin(37001011244) == estnin(37001011255)-1
>>> # Create new person
>>> person = estnin.create(estnin.MALE, date(1999, 12, 31), 999)
>>> print(person)
>>> 39912319997
>>> assert estnin(50001010006) == person+1

iteration

Iterating over a given estnin instance creates new objects.

>>> people = [p for _, p in zip(range(3), estnin(37001011233))]
>>> print(' '.join(map(str, people)))
>>> 37001011233 37001011244 37001011255

Iterating in a reverse order can be done by using the method reversed():

>>> people = [p for _, p in zip(range(3), reversed(estnin(37001011233)))]
>>> print(' '.join(map(str, people)))
>>> 37001011233 37001011222 37001011211

properties

>>> person = estnin.create(estnin.MALE, date(1970, 1, 2), 3)
>>> person
37001020036
>>> person.century
3
>>> person.year
1970
>>> person.month
1
>>> person.day
2
>>> person.sequence
3
>>> person.checksum
6
>>> person.date
datetime.date(1970, 1, 2)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

estnin-1.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file estnin-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: estnin-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2

File hashes

Hashes for estnin-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9136519771adaf743b2dfa7b548d828cb33789a0e8276d37b2f86a49ad236d8
MD5 677a7379437f260bf69053ad8c315d93
BLAKE2b-256 62c77d7594cb3edc55fd5f22aec379e469cd02fab3cdd42cceb6ddc22af6d9fd

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