A decorator to serialize a string into a Pydantic model with error handling
Project description
Pydantic deserializer
this is a simple decorator that can be used on functions that have a return type of str, To deserialize it into a given Pydantic Model.
Usage:
For a function returning a string:
def func_returning_str() -> str:
return '{"sample": "json"}'
Let's say there's a Pydantic model like so:
class SampleJson(BaseModel):
sample: str
We can try and parse it with the decorator:
from pydantic_serializer import deserialize
@deserialize(return_type=SampleJson)
def func_returning_str() -> str:
return '{"sample": "json"}'
The function will return a None and log the error using loguru if there is an error.
If no error occurs, then you should get a return type of SampleJson in this case.
Project details
Release history Release notifications | RSS feed
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_serializer-0.2.1.tar.gz.
File metadata
- Download URL: pydantic_serializer-0.2.1.tar.gz
- Upload date:
- Size: 1.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd076b631c3fa4df6c65bfe75bd7622fb7de88b917f7d31c119b4a7e28451706
|
|
| MD5 |
5685f731771b6e3b5a84ffbeca66077a
|
|
| BLAKE2b-256 |
39adbd0d004a01e9a094e63b6d24d1873aad5d54a40543db3665056897bfe56e
|
File details
Details for the file pydantic_serializer-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pydantic_serializer-0.2.1-py3-none-any.whl
- Upload date:
- Size: 2.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
407b1599917d6d0ca05ae53821836a99ecf1036eca07a06be9b64804e7bc2cc3
|
|
| MD5 |
6d4e36f608e49243a2023f4a14c6058d
|
|
| BLAKE2b-256 |
eb7570978e0554ae3508c606399af95965387d287650158c1299e4baf59522dc
|