ISBN
The pydantic_extra_types.isbn
module provides functionality to recieve and validate ISBN.
ISBN (International Standard Book Number) is a numeric commercial book identifier which is intended to be unique. This module provides a ISBN type for Pydantic models.
ISBN ¶
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'
validate_isbn_format
staticmethod
¶
validate_isbn_format(value: str) -> None
Validate a ISBN format from the provided str value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
The str value representing the ISBN in 10 or 13 digits. |
required |
Raises:
Type | Description |
---|---|
PydanticCustomError
|
If the ISBN is not valid. |
Source code in .venv/lib/python3.12/site-packages/pydantic_extra_types/isbn.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
convert_isbn10_to_isbn13
staticmethod
¶
Convert an ISBN-10 to ISBN-13.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
str
|
The ISBN-10 value to be converted. |
required |
Returns:
Type | Description |
---|---|
str
|
The converted ISBN or the original value if no conversion is necessary. |
Source code in .venv/lib/python3.12/site-packages/pydantic_extra_types/isbn.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
isbn10_digit_calc ¶
Calc a ISBN-10 last digit from the provided str value. More information of validation algorithm on Wikipedia
Parameters:
Name | Type | Description | Default |
---|---|---|---|
isbn |
str
|
The str value representing the ISBN in 10 digits. |
required |
Returns:
Type | Description |
---|---|
str
|
The calculated last digit of the ISBN-10 value. |
Source code in .venv/lib/python3.12/site-packages/pydantic_extra_types/isbn.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
isbn13_digit_calc ¶
Calc a ISBN-13 last digit from the provided str value. More information of validation algorithm on Wikipedia
Parameters:
Name | Type | Description | Default |
---|---|---|---|
isbn |
str
|
The str value representing the ISBN in 13 digits. |
required |
Returns:
Type | Description |
---|---|
str
|
The calculated last digit of the ISBN-13 value. |
Source code in .venv/lib/python3.12/site-packages/pydantic_extra_types/isbn.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|