ISBNlib

3.10.14 · active · verified Thu Apr 16

ISBNlib is an active Python library (current version 3.10.14) providing a pure-Python solution for extracting, cleaning, transforming, hyphenating, and fetching metadata for ISBNs (International Standard Book Numbers). It offers a straightforward API for various ISBN-related tasks and receives frequent minor updates to its internal data ranges and service integrations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to clean (canonicalize), validate, retrieve metadata, and hyphenate an ISBN using `isbnlib`'s core functions. It uses a known ISBN-13 and prints the results.

from isbnlib import canonical, is_isbn13, meta, mask

# An example ISBN-13 (striped, only digits and X)
isbn_like = "978-0446310789"

# 1. Canonicalize the ISBN
canonical_isbn = canonical(isbn_like)
print(f"Canonical ISBN: {canonical_isbn}")

# 2. Validate the ISBN
if is_isbn13(canonical_isbn):
    print(f"'{canonical_isbn}' is a valid ISBN-13 format.")
else:
    print(f"'{canonical_isbn}' is not a valid ISBN-13 format.")

# 3. Get metadata (default service is 'goob' - Google Books)
try:
    book_metadata = meta(canonical_isbn)
    if book_metadata:
        print("\nBook Metadata:")
        for key, value in book_metadata.items():
            print(f"  {key}: {value}")
    else:
        print(f"\nNo metadata found for ISBN: {canonical_isbn}")
except Exception as e:
    print(f"\nError fetching metadata: {e}")

# 4. Mask (hyphenate) the ISBN
hyphenated_isbn = mask(canonical_isbn)
print(f"\nHyphenated ISBN: {hyphenated_isbn}")

view raw JSON →