Registry / serialization / python-stdnum

python-stdnum

JSON →
library2.2pypypi✓ verified 26d ago

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-stdnum
INSTALL
IMPORT
SIG · PYTHON-STDNUM
P
python-stdnum
serializationpythonv2.2
Install
1.8s avg
Import
142ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.152s · 23.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.132s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isbn
from stdnum import isbn
Common pattern for importing a specific number format module (e.g., 'isbn', 'us.ssn', 'nl.btw').
get_cc_module
from stdnum import get_cc_module
Used for dynamically retrieving a country-specific module by country code and name (e.g., `get_cc_module('nl', 'vat')`).

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}")
Debug
Known issues
breakingVersion 2.0 (released May 2025) dropped support for Python 2.x. It now requires Python 3.8 or newer. Attempts to install or run on older Python versions will fail.
fix
Ensure your project's Python environment is version 3.8 or later before upgrading to python-stdnum 2.0 or newer.
affects: >=2.0
gotchaThe `validate()` function raises specific exceptions (e.g., `InvalidChecksum`, `InvalidLength`) for invalid numbers, which can halt execution if not handled. In contrast, `is_valid()` returns a boolean (`True` or `False`) and never raises an exception. Choose the appropriate function based on your error handling strategy.
fix
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: ...`
affects: All
gotchaThe `compact()` function generally does not perform full validation but may raise exceptions for 'wildly incorrect' inputs. The `format()` function also expects a valid number and may raise exceptions if an invalid number is passed to it.
fix
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.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'stdnum'
The 'python-stdnum' library, which provides the 'stdnum' package, has not been installed in the current Python environment.
fix
pip install python-stdnum
AttributeError: module 'stdnum' has no attribute 'is_valid'
The `is_valid` function is not directly available under the top-level `stdnum` module; it resides within specific standard submodules (e.g., `stdnum.isbn.is_valid`).
fix
from stdnum import isbn; isbn.is_valid('...')  (Replace `isbn` with the desired standard like `vat`, `ean`, etc.)
stdnum.exceptions.InvalidFormat: Input must be a 10 or 13 digit number.
The input string provided to a `stdnum` validation or parsing function (e.g., `stdnum.isbn.validate()`) does not conform to the expected format or length for the specified standard.
fix
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()`.
TypeError: expected string, got int
Standard number functions in `python-stdnum` expect string inputs for validation and parsing, but an integer (or other non-string type) was provided.
fix
Convert the input number to a string using `str()` before passing it to `stdnum` functions. Example: `stdnum.isbn.is_valid(str(9780321765724))`
Upgrade
Version history
2.2latest on PyPI · released Jan 4, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
12
Amazon
1
Resources
python-stdnum — pip install python-stdnum · libregistry