Useful tools for pydantic
Project description
pydantic-tools
A set of tools for pydantic(i18n, alias, etc.)
i18n
A simple example
from pydantic_tools import i18n
class TestModel(i18n.BaseModel_i18n):
name: str
age: int
class Config:
locale = "zh_cn"
test = TestModel()
pydantic.error_wrappers.ValidationError: 2 validation errors for TestModel
name
确保该值不缺失 (type=value_error.missing)
age
确保该值不缺失 (type=value_error.missing)
Config available
-
locale
: The locale of the model, default isNone
, which means no translation enabled, and the default error message will be used. Usepython -m pydantic_tools.i18n -l
to show all available locales. -
locale_strict
: Whether to raise an error when the locale is not found, default isFalse
. -
translations
: If specified, the error messages will be translated according to the given dict instead of the locale config. The dict should be like{"value_error.missing": "Missing"}
. One oflocale
andtranslations
should be specified, do not set both of them. -
extra_translations
: If specified, an extra dict will be merged into the default translations. The dict should be like{"value_error.missing": "some msg"}
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pydantic_tools-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 242be73ade5702687ad5d5f15647b59db63c734a4df1ca6841f17c3ac7117d49 |
|
MD5 | b4c52e7fb52b0ec3745b1fff1a979e3a |
|
BLAKE2b-256 | 7788d5bba577c6fd86e04f3c2c31dc304c0f87e6e6d1c7c90dfd92664431a4dd |