Python Standardized Numbers and Codes

2.2 · active · verified Fri Apr 10

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.

Warnings

Install

Imports

Quickstart

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.

from stdnum import isbn
from stdnum.exceptions import InvalidChecksum, InvalidLength

# Validate an ISBN
try:
    validated_isbn = isbn.validate('978-0471117094')
    print(f"Validated ISBN: {validated_isbn}")
except (InvalidChecksum, InvalidLength) as e:
    print(f"Validation failed: {e}")

# Format an ISBN
formatted_isbn = isbn.format('9780471117094')
print(f"Formatted ISBN: {formatted_isbn}")

# Check validity without raising exceptions
is_valid = isbn.is_valid('978-0471117094')
print(f"Is valid (using is_valid): {is_valid}")

view raw JSON →