Useful tools for pydantic
Project description
pydantic-tools
A set of tools for pydantic(i18n, alias(comming soon), etc.)
Installation
pip install pydantic-tools
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 -lto 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 oflocaleandtranslationsshould 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"}.
Show all available locales
python -m pydantic_tools.i18n -l
Show all available translations
python -m pydantic_tools.i18n -t
alias
Comming soon
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_tools-0.3.3.tar.gz.
File metadata
- Download URL: pydantic_tools-0.3.3.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
707358b1c73887df95efe622b23279f3053a66254b2d17251b1262934edffecf
|
|
| MD5 |
2d186d2901aad74e0407ee0b45475054
|
|
| BLAKE2b-256 |
77866532e72c8e3e891e6b3e578768fa473f664a51319111f1486041a0c235a2
|
File details
Details for the file pydantic_tools-0.3.3-py3-none-any.whl.
File metadata
- Download URL: pydantic_tools-0.3.3-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27275f4f0aeb670870d5d16fe13fae537b1d4506565ecf5e7260a002e01453d6
|
|
| MD5 |
3e5ca794c00ba091dbb333e8e3e27459
|
|
| BLAKE2b-256 |
587794f8c0301fe06ea521b138fe580658cfcca451f4b07751fe5e2bb3456e15
|