Package: isikukood
IsikukoodSmall Estonian social security number library (I know they're not really SSNs but I don't have a better English name for them)InstallationSimply run the following:pipinstallisikukoodTable of Contentsfunctionsordernumber_from_ssngender_from_ssngender_markerbirthdate_from_ssninsert_checksumcalculate_checksumenumisikukoodIsikukoodfrom_ssnconstructconstructconstructassertionsassert_ordernumber_rangeassert_numericassert_genderassert_first_digitassert_year_rangeassert_existing_dateassert_constructor_listassert_valid_ssnassert_correct_checksumassert_enum_argumentsfunctionsordernumber_from_ssndefordernumber_from_ssn(ssn:str)->intExtract the order number from the given SSN.Examples:>>>isikukood.ordernumber_from_ssn('50001010006')0>>>isikukood.ordernumber_from_ssn('50001010105')10gender_from_ssndefgender_from_ssn(ssn:str)->strExtract the gender from the given SSN.Examples:>>>isikukood.gender_from_ssn('50001010006')'m'>>>isikukood.gender_from_ssn('60001010007')'f'Returns:str- Either 'm' or 'f'.gender_markerdefgender_marker(yyyy:int,gender:str)->strFind the suitable gender marker (first digit), given gender and year of birth.Examples:>>>isikukood.gender_marker(2000,'m')'5'>>>isikukood.gender_marker(1999,'m')'3'Arguments:yyyyint- Year of birth.genderstr- Either 'm' or 'f'.Returns:int- A number between 1 and 8 (inclusive).Raises:ValueError- When either one of the arguments is invalid.birthdate_from_ssndefbirthdate_from_ssn(ssn:str)->strFind the birthdate, given an SSN.Examples:>>>isikukood.birthdate_from_ssn('50001010006')'2000-01-01'Arguments:ssnstr- Estonian SSN.Returns:str- Corresponding birthdate in ISO 8601 (yyyy-mm-dd).insert_checksumdefinsert_checksum(ssn:str)->strExamples:>>>isikukood.insert_checksum('5000101000x')'50001010006'Arguments:ssnstr- Estonian SSN, can be either 10 or 11 digits.Returns:str- The given SSN but with the 11th digit replaced with a newly calculated checksum.Raises:ValueError- When the given SSN is not 10 or 11 digits in length.calculate_checksumdefcalculate_checksum(ssn:str)->intCalculate the given SSN's checksum as perhttps://et.wikipedia.org/wiki/Isikukood#KontrollnumberExamples:>>>isikukood.calculate_checksum('5000101000')6Arguments:ssnstr- Estonian SSN. May or may not already contain the checksum digit (can be either 10 or 11 digits).Returns:int- Corresponding checksum.enumdefenum(genders:List[str]=None,days:List[int]=None,months:List[int]=None,years:List[int]=None,onums:List[int]=None)->List[str]Generate all valid Estonian SSNs possible with the given arguments.Examples:>>>isikukood.enum(days=[1],months=[1],years=[2000],onums=[0,1,2])['50001010006','50001010017','50001010028','60001010007','60001010018','60001010029']Arguments:gendersList[str]- A list in which each element is either 'm' or 'f'. Defaults to ['m', 'f'].daysList[int]- Days of the month, such as [5, 6, 7, 8, 9]. Defaults to [1; 31].monthsList[int]- Months of the year, such as [9, 10, 11, 12]. Defaults to [1; 12].yearsList[int]- Years, such as [2000, 2001, 2002]. Defaults to the current year.onumsList[int]- Order numbers, such as [371, 372, ..., 420]. Defaults to [0; 999].Returns:List[str]- List of SSNs.Raises:ValueError- When any of the given arguments is invalid.isikukoodIsikukood ObjectsclassIsikukood()from_ssn@classmethoddeffrom_ssn(cls,ssn:str)Instantiate the class from an already existing SSN.Examples:>>>isikukood.Isikukood.from_ssn('50001010006')Raises:ValueError- When the given SSN is invalid.construct@multimethoddefconstruct()->List[str]Generate all possible SSNs with the instance's gender and birthdate.Examples:>>>isikukood.Isikukood('m','2000-01-01').construct()['50001010006','50001010017','50001010028',...]Returns:List[str]- List of SSNs.construct@multimethoddefconstruct(ordernumber:int)->strGenerate an SSN with the instance's gender and birthdate and the order number that was given as an argument.Examples:>>>isikukood.Isikukood('m','2000-01-01').construct(111)'50001011112'Raises:ValueError- When the given order number is invalid.construct@multimethoddefconstruct(ordernumbers:List[int])->List[str]Generate all possible SSNs with the instance's gender and birthdate
and with all the order numbers that were given as an argument.Examples:>>>isikukood.Isikukood('m','2000-01-01').construct([111,222,333])['50001011112','50001012229','50001013335']Arguments:ordernumbersList[int]- List of order numbers.Returns:List[str]- List of SSNs.Raises:ValueError- When any of the given order numbers is invalid.assertionsassert_ordernumber_rangedefassert_ordernumber_range(ordernumber:int)->NoneAssert that the given argument is between 0 and 999 (inclusive).Raises:AssertionError- When the assertion fails.assert_numericdefassert_numeric(arg:str)->NoneAssert that the given argument is numeric.Raises:AssertionError- When the assertion fails.assert_genderdefassert_gender(gender:str)->NoneAssert that the given argument is either 'm' or 'f'.Raises:AssertionError- When the assertion fails.assert_first_digitdefassert_first_digit(ssn:str)->NoneAssert that the first character of the given argument is between 1 and 8 (inclusive).Raises:AssertionError- When the assertion fails.assert_year_rangedefassert_year_range(yyyy:int)->NoneAssert that the given argument is between 1800 and 2199 (inclusive).Raises:AssertionError- When the assertion fails.assert_existing_datedefassert_existing_date(date:str)->NoneAssert that the given date exists (no February 29th on non-leap years, no April 31st, etc.).Arguments:datestr- Date in ISO 8601 (YYYY-MM-DD).Raises:AssertionError- When the assertion fails.assert_constructor_listdefassert_constructor_list(ssns:List[str])->NoneSanity check called by SSN constructors.
Asserts that the given argument contains no duplicates and that every one of its elements is a valid Estonian SSN.Arguments:ssnsList[str]- List of SSNs coming from Isikukood.construct().Raises:AssertionError- When any of the assertions fail.assert_valid_ssndefassert_valid_ssn(ssn:str)->NoneAssert that the given argument is a valid Estonian SSN. Currently, this performs the following checks:that the SSN is numericthat the first digit is between 1 and 8 (inclusive)that the SSN is exactly 11 digitsthat the checksum is correctthat the birthdate existsthat the year of birth is between 1800 and 2199 (inclusive)Raises:AssertionError- When any of the assertions fail.assert_correct_checksumdefassert_correct_checksum(ssn:str)->NoneAssert that the given SSN's checksum is correct.Raises:AssertionError- When the assertion fails.assert_enum_argumentsdefassert_enum_arguments(genders:List[str],days:List[int],months:List[int],years:List[int])->NoneAssert that the arguments for functions.enum() are valid. This performs the following checks:that every element in genders is either 'm' or 'f'that every element in days is between 1 and 31 (inclusive)that every element in months is between 1 and 12 (inclusive)that every element in years is between 1800 and 2199 (inclusive)Raises:AssertionError- When any of the assertions fail.