# stdnum.de.stnr

St.-Nr. (Steuernummer, German tax number).

The Steuernummer (St.-Nr.) is a tax number assigned by regional tax offices to taxable individuals and organisations. The number is being replaced by the Steuerliche Identifikationsnummer (IdNr).

The number has 10 or 11 digits for the regional form (per Bundesland) and 13 digits for the number that is unique within Germany. The number consists of (part of) the Bundesfinanzamtsnummer (BUFA-Nr.), a district number, a serial number and a check digit.

More information:

- https://de.wikipedia.org/wiki/Steuernummer

    >>> validate(' 181/815/0815 5')
    '18181508155'
    >>> validate('201/123/12340', 'Sachsen')
    '20112312340'
    >>> validate('4151081508156', 'Thuringen')
    '4151081508156'
    >>> validate('4151181508156', 'Thuringen')
    Traceback (most recent call last):
        ...
    InvalidFormat: ...
    >>> validate('136695978')
    Traceback (most recent call last):
        ...
    InvalidLength: ...

stdnum.de.stnr.REGIONS = ['Baden-Württemberg', 'Bayern', 'Berlin', 'Brandenburg', 'Bremen', 'Hamburg', 'Hessen', 'Mecklenburg-Vorpommern', 'Niedersachsen', 'Nordrhein-Westfalen', 'Rheinland-Pfalz', 'Saarland', 'Sachsen', 'Sachsen-Anhalt', 'Schleswig-Holstein', 'Thüringen']

  Valid regions recognised by this module.

stdnum.de.stnr.compact(number: str) → str

  Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.de.stnr.format(number: str, region: str | None = None) → str

  Reformat the passed number to the standard format.

stdnum.de.stnr.guess_regions(number: str) → list[str]

  Return a list of regions this number is valid for.

stdnum.de.stnr.is_valid(number: str, region: str | None = None) → bool

  Check if the number is a valid tax number. This checks the length and formatting. The region can be supplied to verify that the number is assigned in that region.

stdnum.de.stnr.to_country_number(number: str, region: str | None = None) → str

  Convert the number to the nationally unique number. The region is needed if the number is not only valid for one particular region.

stdnum.de.stnr.to_regional_number(number: str) → str

  Convert the number to a regional (10 or 11 digit) number.

stdnum.de.stnr.validate(number: str, region: str | None = None) → str

  Check if the number is a valid tax number. This checks the length and formatting. The region can be supplied to verify that the number is assigned in that region.