Pydantic Extra Types Isbn
The pydantic_extra_types.isbn module provides functionality to receive and validate ISBN.
ISBN (International Standard Book Number) is a numeric commercial book identifier which is intended to be unique. This module provides an ISBN type for Pydantic models.
Bases: str
Represents a ISBN and provides methods for conversion, validation, and serialization.
from pydantic import BaseModel
from pydantic_extra_types.isbn import ISBN
class Book(BaseModel):
isbn: ISBN
book = Book(isbn='8537809667')
print(book)
# > isbn='9788537809662'
@staticmethod
def validate_isbn_format(value: str) -> None
Validate a ISBN format from the provided str value.
value : str
The str value representing the ISBN in 10 or 13 digits.
PydanticCustomError— If the ISBN is not valid.
@staticmethod
def convert_isbn10_to_isbn13(value: str) -> str
Convert an ISBN-10 to ISBN-13.
str — The converted ISBN or the original value if no conversion is necessary.
value : str
The ISBN-10 value to be converted.
def isbn10_digit_calc(isbn: str) -> str
Calculate the ISBN-10 check digit from the provided str value. More information on the validation algorithm on Wikipedia
str — The calculated last digit of the ISBN-10 value.
isbn : str
The str value representing the ISBN in 10 digits.
def isbn13_digit_calc(isbn: str) -> str
Calc a ISBN-13 last digit from the provided str value. More information on the validation algorithm on Wikipedia
str — The calculated last digit of the ISBN-13 value.
isbn : str
The str value representing the ISBN in 13 digits.