Pydentic
Pydentic is a thin wrapper over python-stdnum to facilitate the use
of its extensive collection of validators and formatters in Pydantic models.
pip install pydentic
Features
Automatic validation and formatting.
from pydentic.strings import Iban
from pydantic import BaseModel
class User(BaseModel):
name: str
iban: Iban
user = User(name='John Doe', iban='es1000750080110600658108')
print(user)
user = User(name='John Doe', iban='es1000750080110600658108Ñ')
...
pydantic.error_wrappers.ValidationError: 1 validation error for User
iban
es1000750080110600658108Ñ (type=value_error.format; error=invalid literal for int() with base 36: 'Ñ')
Title and description in the JSON Schema.
{
"title": "User",
"type": "object",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"iban": {
"title": "IBAN",
"description": "International Bank Account Number",
"type": "string"
}
},
"required": ["user", "iban"]
}
The classes Isan
, Isbn
, and Issn
include a urn
property that, not
surprisingly, returns their URN.
from pydentic.strings import Isbn
from pydantic import BaseModel
class Book(BaseModel):
author: str
title: str
isbn: Isbn
book = Book(author='D. Hofstadter', title='GEB', isbn='978-0-465-02656-2')
print(book.isbn.urn)
Identifiers
The list below contains some available international identifiers. There are
around 200 more identifiers included (see the python-stdnum docs for the
complete list.)