python-stdnum

A Python module to parse, validate and reformat standard numbers and codes in different formats. It contains a large collection of number formats.

Basically any number or code that has some validation mechanism available or some common formatting is eligible for inclusion in this library.

http://arthurdejong.org/python-stdnum/

Common Interface

Most of the number format modules implement the following functions:

stdnum.validate(number)

Validate the number and return a compact, consistent representation of the number or code. If the validation fails, an exception is raised that indicates the type of error.

stdnum.is_valid(number)

Return either True or False depending on whether the passed number is in any supported and valid form and passes all embedded checks of the number. This function should never raise an exception.

stdnum.compact(number)

Return a compact representation of the number or code. This function generally does not do validation but may raise exceptions for wildly invalid numbers.

stdnum.format(number)

Return a formatted version of the number in the preferred format. This function generally expects to be passed a valid number or code and may raise exceptions for invalid numbers.

The check digit modules generally also provide the following functions:

stdnum.checksum(number)

Calculate the checksum over the provided number. This is generally a number that can be used to determine whether the provided number is valid. It depends on the algorithm which checksum is considered valid.

stdnum.calc_check_digit(number)

Calculate the check digit that should be added to the number to make it valid.

Apart from the above, the modules may add extra parsing, validation or conversion functions.

Helper modules

exceptions Collection of exceptions.

Generic check digit algorithms

iso7064 Collection of the ISO 7064 algorithms.
luhn The Luhn and Luhn mod N algorithms.
verhoeff The Verhoeff algorithm.

Available formats

at.uid UID (Umsatzsteuer-Identifikationsnummer, Austrian VAT number).
be.vat BTW, TVA, NWSt (Belgian VAT number).
bg.egn EGN (ЕГН, Единен граждански номер, Bulgarian personal identity codes).
bg.pnf PNF (ЛНЧ, Личен номер на чужденец, Bulgarian number of a foreigner).
bg.vat VAT (Идентификационен номер по ДДС, Bulgarian VAT number).
br.cpf CPF (Cadastro de Pessoas Físicas, Brazillian national identifier).
cy.vat Αριθμός Εγγραφής Φ.Π.Α. (Cypriot VAT number).
cz.dic DIČ (Daňové identifikační číslo, Czech VAT number).
cz.rc RČ (Rodné číslo, the Czech birth number).
de.vat Ust ID Nr. (Umsatzsteur Identifikationnummer, German VAT number).
dk.cpr CPR (personnummer, the Danish citizen number).
dk.cvr CVR (Momsregistreringsnummer, Danish VAT number).
ean EAN (International Article Number).
ee.kmkr KMKR (Käibemaksukohuslase, Estonian VAT number).
es.cif CIF (Certificado de Identificación Fiscal, Spanish company tax number).
es.dni DNI (Documento nacional de identidad, Spanish personal identity codes).
es.nie NIE (Número de Identificación de Extranjeros, Spanish foreigner number).
es.nif NIF (Número de Identificación Fiscal, Spanish VAT number).
eu.vat VAT (European Union VAT number).
fi.alv ALV nro (Arvonlisäveronumero, Finnish VAT number).
fi.hetu HETU (Henkilötunnus, Finnish personal identity code).
fr.siren SIREN (a French company identification number).
fr.tva n° TVA (taxe sur la valeur ajoutée, French VAT number).
gb.vat VAT (United Kingdom (and Isle of Man) VAT registration number).
gr.vat FPA, ΦΠΑ (Foros Prostithemenis Aksias, the Greek VAT number).
grid GRid (Global Release Identifier).
hr.oib OIB (Osobni identifikacijski broj, Croatian identification number).
hu.anum ANUM (Közösségi adószám, Hungarian VAT number).
iban IBAN (International Bank Account Number).
ie.pps PPS No (Personal Public Service Number, Irish personal number).
ie.vat VAT (Irish VAT number).
imei IMEI (International Mobile Equipment Identity).
imsi IMSI (International Mobile Subscriber Identity).
isan ISAN (International Standard Audiovisual Number).
isbn ISBN (International Standard Book Number).
isil ISIL (International Standard Identifier for Libraries).
ismn ISMN (International Standard Music Number).
issn ISSN (International Standard Serial Number).
it.iva Partita IVA (Italian VAT number).
lt.pvm PVM (Pridėtinės vertės mokestis mokėtojo kodas, Lithuanian VAT number).
lu.tva TVA (taxe sur la valeur ajoutée, Luxembourgian VAT number).
lv.pvn PVN (Pievienotās vērtības nodokļa, Latvian VAT number).
meid MEID (Mobile Equipment Identifier).
mt.vat VAT (Maltese VAT number).
my.nric NRIC No. (Malaysian National Registration Identity Card Number).
nl.brin Brin number (Dutch number for schools).
nl.bsn BSN (Burgerservicenummer, Dutch national identification number).
nl.btw BTW-nummer (Omzetbelastingnummer, the Dutch VAT number).
nl.onderwijsnummer Onderwijsnummer (Dutch student school number).
nl.postcode Postcode (Dutch postal code).
pl.nip NIP (Numer Identyfikacji Podatkowej, Polish VAT number).
pt.nif NIF (Número de identificação fiscal, Portuguese VAT number).
ro.cf CF (Cod de înregistrare în scopuri de TVA, Romanian VAT number).
ro.cnp CNP (Cod Numeric Personal, Romanian Numerical Personal Code).
se.vat VAT (Moms, Mervärdesskatt, Swedish VAT number).
si.ddv ID za DDV (Davčna številka, Slovenian VAT number).
sk.dph IČ DPH (IČ pre daň z pridanej hodnoty, Slovak VAT number).
sk.rc RČ (Rodné číslo, the Slovak birth number).
us.atin ATIN (U.S. Adoption Taxpayer Identification Number).
us.ein EIN (U.S. Employer Identification Number).
us.itin ITIN (U.S. Individual Taxpayer Identification Number).
us.ptin PTIN (U.S. Preparer Tax Identification Number).
us.ssn SSN (U.S. Social Security Number).
us.tin TIN (U.S. Taxpayer Identification Number).

Table Of Contents

Next topic

stdnum.exceptions