Ways of isbnlib
Given a masked ISBN such as 978-958-5522-34-3
, which one of the Main Functions are the most useful for working with ISBN?
to_isbn13(isbn10)
- Transforms isbn-10 to isbn-13.
to_isbn13('978-958-5522-34-3')
‘9789585522343’
canonical(isbnlike)
- Keeps only digits and X. You will get strings like 9780321534965 and 954430603X.
canonical('978-958-5522-34-3')
‘9789585522343’
clean(isbnlike)
- Cleans ISBN (only legal characters).
clean('978-958-5522-34-3')
‘978-958-5522-34-3’
get_isbnlike(text, level='normal')
- Extracts all substrings that seem like ISBNs (very useful for scraping).
get_isbnlike('978-958-5522-34-3')
[‘978-958-5522-34-3’]
get_canonical_isbn(isbnlike, output='bouth')
- Extracts ISBNs and transform them to the canonical form.
get_canonical_isbn('978-958-5522-34-3')
‘9789585522343’
ean13(isbnlike)
- Transforms an isbnlike string into an EAN13 number (validated canonical ISBN-13).
ean13('978-958-5522-34-3')
‘9789585522343’
The useful ones are: to_isbn13(isbn10)
, canonical(isbnlike)
, and ean13(isbnlike)
According to the source code on the repo, ean13(isbnlike)
is the most comprehensive.
def ean13(isbnlike):
"""Transform an `isbnlike` string in an EAN number (canonical ISBN-13)."""
ib = canonical(isbnlike)
if len(ib) == 13:
return ib if is_isbn13(ib) else ''
if len(ib) == 10:
return to_isbn13(ib) if is_isbn10(ib) else ''
return ''