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.

Common Interface

Most of the number format modules implement the following functions:


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.


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.


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


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:


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.


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 Python’s standard exception class hierarchy.

Generic check digit algorithms


Table Of Contents

Next topic