python-stdnum is a Python module designed to parse, validate, and reformat a large collection of standardized numbers and codes from various countries and international standards. Currently at version 2.2, released in January 2026, the library maintains a frequent release cadence, regularly adding support for new number formats, applying bug fixes, and enhancing existing functionalities.
pip install python-stdnumVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to validate and format an International Standard Book Number (ISBN) using `stdnum.isbn`. It shows how to catch validation-related exceptions and how to use `is_valid()` for a boolean check without exceptions.
Ensure your project's Python environment is version 3.8 or later before upgrading to python-stdnum 2.0 or newer.
Wrap `validate()` calls in `try...except stdnum.exceptions.StdnumException` blocks or use `is_valid()` for simple boolean checks. For example, `try: stdnum.isbn.validate(num) except stdnum.exceptions.InvalidChecksum: ...`
It is best practice to `validate()` a number before attempting to `compact()` or `format()` it, especially if the input source is untrusted or prone to errors.
pip install python-stdnum
from stdnum import isbn; isbn.is_valid('...') (Replace `isbn` with the desired standard like `vat`, `ean`, etc.)Ensure the input string is a valid representation of the number standard; use `is_valid()` to check validity without raising an error, or provide correct input to `validate()` or `parse()`.
Convert the input number to a string using `str()` before passing it to `stdnum` functions. Example: `stdnum.isbn.is_valid(str(9780321765724))`
No dependency data recorded yet.