isbn-pure
Pure-stdlib ISBN-13 and ISBN-10 validator for Python — zero pip dependencies, ≤150 LOC core, ≥100 tests.
from isbn_pure import validate_isbn13, validate_isbn10, normalize_isbn13, normalize_isbn10
validate_isbn13("978-0-13-468599-1") # -> True
validate_isbn13("978-0-13-468599-0") # -> False (wrong check digit)
validate_isbn10("0-306-40615-2") # -> True
validate_isbn10("000000006X") # -> True (X check digit, verified valid)
normalize_isbn13("978-0-13-468599-1") # -> "9780134685991"
normalize_isbn10("0-306-40615-2") # -> "0306406152"
Install
pip install -e .
No external dependencies. Python ≥3.8.
Why isbn-pure?
Existing ISBN validators on PyPI require heavy runtime dependencies:
| Package | Dependencies |
|---|---|
pyisbn |
requests |
isbnlib |
requests, beautifulsoup4, lxml |
isbn-pure is zero-dependency — pure stdlib only. Ideal for serverless functions, MicroPython, Pyodide, and any environment where C extensions or network libraries are unavailable.
Key Features
- ISBN-13 validation — full ISO 2108 checksum validation
- ISBN-10 validation — full ISBN-10 checksum validation including
Xcheck digit (= 10) - Normalization — strip hyphens/spaces, returns clean digit string
- Pure stdlib — zero pip dependencies
- ≤150 LOC core — auditable, minimal attack surface
- ≥100 tests — comprehensive valid/invalid/boundary coverage
API Reference
validate_isbn13(isbn: str) -> bool
Returns True if the string is a valid ISBN-13, False otherwise. Strips hyphens and spaces before validation.
validate_isbn10(isbn: str) -> bool
Returns True if the string is a valid ISBN-10, False otherwise. Strips hyphens and spaces. Accepts X (or x) as the check digit in position 10.
normalize_isbn13(isbn: str) -> str
Returns the 13-digit normalized ISBN string if valid, otherwise "".
normalize_isbn10(isbn: str) -> str
Returns the 10-character normalized ISBN string if valid, otherwise "".
compute_check_digit_isbn13(first12: str) -> int
Computes the ISBN-13 check digit (0–9) for a 12-digit prefix.
compute_check_digit_isbn10(first9: str) -> str
Computes the ISBN-10 check digit for a 9-digit prefix. Returns '0'–'9' or 'X'.
Canonical Test Vectors
ISBN-13:
| Input | Expected | Notes |
|---|---|---|
978-0-13-468599-1 |
Valid | Canonical example from ISO 2108 / Wikipedia |
978-1-4919-1021-4 |
Valid | Correct check digit (spec had wrong 7) |
978-0-306-40615-7 |
Valid | |
978-0-13-468599-0 |
Invalid | Wrong check digit |
978-0-13-468599- |
Invalid | Truncated |
ISBN-10:
| Input | Expected | Notes |
|---|---|---|
0-306-40615-2 |
Valid | CRC Press example from Wikipedia |
000000006X |
Valid | Real ISBN-10 with X check digit (verified: total=12, cd=X) |
0-306-40615-X |
Invalid | Wrong check digit (correct is 2, not X) |
0306406152 |
Valid | Same ISBN without hyphens |
123456789X |
Valid | X is valid as check digit (=10) |
1234567890 |
Invalid | Wrong check digit |
Acceptance Criteria Checklist
- AC1:
validate_isbn13("978-0-13-468599-1")returnsTrue - AC2:
validate_isbn13("978-0-13-468599-0")returnsFalse - AC3:
validate_isbn10("0-306-40615-2")returnsTrue - AC4:
validate_isbn10("155404295X")returnsTrue - AC5:
normalize_isbn13("978-0-13-468599-1")returns"9780134685991"; invalid returns"" - AC6: Normalized ISBN re-validates:
validate_isbn13(normalize_isbn13(x)) == Truefor all valid x - AC7: Handles hyphens, spaces, lowercase
xaccepted for ISBN-10 - AC8: Pure Python stdlib only — zero pip dependencies
- AC9: Core LOC ≤ 150 (excluding tests)
- AC10: 100+ unit tests covering valid/invalid inputs, boundary cases
Run Tests
pip install -e .[dev]
pytest -v
Limitations
Format-only validation. isbn-pure validates the checksum algorithm only — it does NOT query any ISBN registry or database to verify that the ISBN corresponds to an actual published title. A structurally valid ISBN may not correspond to a real book.
Non-Goals
- ISBN-to-title lookup or registry queries
- CLI interface
- ISBN-10 to ISBN-13 conversion ( GS1 conversion)
- Integration with bibliographic databases
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file isbn_pure-0.1.0.tar.gz.
File metadata
- Download URL: isbn_pure-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb11d099d1da6f4b164ab8c5d850b4218cc5b5c479c63954ccbee3c8bb246c97
|
|
| MD5 |
9cd8b23ec90e7c24bc48775fda6ce0e0
|
|
| BLAKE2b-256 |
e332095cdece99d0d92e5da3a4b69b88dad7d6ec496346132175de68f0260ff1
|
File details
Details for the file isbn_pure-0.1.0-py3-none-any.whl.
File metadata
- Download URL: isbn_pure-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f536705c773ef69b2ab03bdeff0a22e076c2510a1f5d56cd7f51609ae493aa3e
|
|
| MD5 |
1ad4248d0d975ac09ab995b59ec6bd79
|
|
| BLAKE2b-256 |
7e18ffaaf79ce22eb65a28b2191ae8727e93b717a18d763f893de684115b5339
|