ISBN validator¶
This module provides basic API for validation of the ISBN-10 and ISBN-13 numbers. It can also compute the checksum digits for incomplete numbers.
Examples¶
>>> import isbn_validator
ISBN validation:
>>> isbn_validator.is_valid_isbn("80-85892-15-4")
True
>>> isbn_validator.is_valid_isbn("978-80-86056-31-9")
True
>>> isbn_validator.is_valid_isbn("978-80-904248-2-77777")
False
Or just specific ISBN standard:
>>> isbn_validator.is_isbn10_valid("80-85892-15-4")
True
>>> isbn_validator.is_isbn13_valid("978-80-86056-31-9")
True
You can also let the module to compute the checksum digit:
>>> isbn_validator.get_isbn10_checksum("80-86056-31")
7
>>> isbn_validator.get_isbn13_checksum("978-80-904248-2")
1
API¶
ISBN validation module¶
This module is providing funcionality to validate and compute ISBN checksums.
See is_valid_isbn() for details.
API¶
- isbn_validator.isbn_validator.get_isbn10_checksum(isbn)[source]¶
Parameters: isbn (str/list) – ISBN number as string or list of digits Warning
Function expects that isbn is only 9 digits long.
Returns: Last (checksum) digit for given isbn. Return type: int
- isbn_validator.isbn_validator.is_isbn10_valid(isbn)[source]¶
Check if given isbn 10 is valid.
Parameters: isbn (str/list) – ISBN number as string or list of digits. Returns: True if ISBN is valid. Return type: bool
- isbn_validator.isbn_validator.get_isbn13_checksum(isbn)[source]¶
Parameters: isbn (str/list) – ISBN number as string or list of digits. Warning
Function expects that isbn is only 12 digits long.
Returns: Last checksum digit for given isbn. Return type: int
- isbn_validator.isbn_validator.is_isbn13_valid(isbn)[source]¶
Check if given isbn 13 is valid.
Parameters: isbn (str/list) – ISBN number as string or list of digits. Returns: True if ISBN is valid. Return type: bool
- isbn_validator.isbn_validator.is_valid_isbn(isbn)[source]¶
Validate given isbn. Wrapper for is_isbn10_valid()/ is_isbn13_valid().
Parameters: isbn (str/list) – ISBN number as string or list of digits. Note
Function doesn’t require isbn type to be specified (it can be both 10/13 isbn’s versions).
Returns: True if ISBN is valid. Return type: bool
Source code¶
This project is released as opensource (MIT) and source codes can be found at GitHub:
Testing¶
Almost every feature of the project is tested in unit/integration tests. You can run this tests using provided run_tests.sh script, which can be found in the root of the project.
Requirements¶
This script expects that pytest is installed. In case you don’t have it yet, it can be easily installed using following command:
pip install --user pytest
or for all users:
sudo pip install pytest
Example¶
$ ./run_tests.sh
============================= test session starts ==============================
platform linux2 -- Python 2.7.6 -- py-1.4.26 -- pytest-2.6.4
collected 6 items
tests/test_isbn_validator.py ......
=========================== 6 passed in 0.02 seconds ===========================