Handling ISBNs

The Isbn supports SBNs, ISBN-10 and -13. If you’re handling multiple inputs it is easiest to use this class.

class pyisbn.Isbn(isbn)[source]

Class for representing ISBN objects.

Initialise a new Isbn object.

Parameters:

isbn (TIsbn (str)) – ISBN string

calculate_checksum()[source]

Calculate ISBN checksum.

Return type:

str

Returns:

ISBN checksum value

convert(code='978')[source]

Convert ISBNs between ISBN-10 and ISBN-13.

Parameters:

code (str) – ISBN-13 prefix code

Return type:

str

Returns:

Converted ISBN

to_url(site='amazon', country='us')[source]

Generate a link to an online book site.

Parameters:
  • site (str) – Site to create link to

  • country (str | None) – Country specific version of site

Return type:

str

Returns:

URL on site for book

Raises:
to_urn()[source]

Generate a RFC 3187 URN.

RFC 3187 is the commonly accepted way to use ISBNs as uniform resource names.

Return type:

str

Returns:

RFC 3187 compliant URN

validate()[source]

Validate an ISBN value.

Return type:

bool

Returns:

True if ISBN is valid

Examples

Validate ISBN

>>> book = Isbn('9783540009788')
>>> book.validate()
True
>>> invalid_book = Isbn('0123456654321')
Traceback (most recent call last):

pyisbn.IsbnError: invalid Bookland region

Format ISBN

>>> book.to_urn()
'URN:ISBN:9783540009788'
>>> book.to_url()
'https://www.amazon.com/s?search-alias=stripbooks&field-isbn=9783540009788'
>>> book.to_url('google')
'https://books.google.com/books?vid=isbn:9783540009788'