No project description provided
Project description
Lazy parsing for Pydantic models
This library provides a lazy interface for parsing objects from dictionaries. During the parsing, it saves the raw data inside the object and parses each field on demand.
Install
poetry
poetry add lazy-model
pip
pip install lazy-model
Usage
from lazy_model import LazyModel
from pydantic import validator
class Sample(LazyModel):
i: int
s: str
@validator("s")
def s_upper(cls, v):
return v.upper()
obj = Sample.lazy_parse({"i": "10", "s": "test"})
# at this point the data is stored in a raw format inside the object
print(obj.__dict__)
# >>> {'i': NAO, 's': NAO}
# NAO - Not An Object. It shows that the field was not parsed yet.
print(obj.s)
# >>> TEST
# Custom validator works during lazy parsing
print(obj.__dict__)
# >>> {'i': NAO, 's': 'TEST'}
# The `s` field was already parsed by this step
print(obj.i, type(obj.i))
# >>> 10 <class 'int'>
# It converted `10` from string to int based on the annotations
print(obj.__dict__)
# >>> {'i': 10, 's': 'TEST'}
# Everything was parsed
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
lazy-model-0.4.0.tar.gz
(8.3 kB
view details)
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 lazy-model-0.4.0.tar.gz.
File metadata
- Download URL: lazy-model-0.4.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a851d85d0b518b0b9c8e626bbee0feb0494c0e0cb5636550637f032dbbf9c55f
|
|
| MD5 |
ebfdfaa9bd55db5013c489f978c8b467
|
|
| BLAKE2b-256 |
7285e25dc36dee49cf0726c03a1558b5c311a17095bc9361bcbf47226cb3075a
|
File details
Details for the file lazy_model-0.4.0-py3-none-any.whl.
File metadata
- Download URL: lazy_model-0.4.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.12.11 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95ea59551c1ac557a2c299f75803c56cc973923ef78c67ea4839a238142f7927
|
|
| MD5 |
0e28f0e726e61c96c160a337740bb195
|
|
| BLAKE2b-256 |
5c54653ea0d7c578741e9867ccf0cbf47b7eac09ff22e4238f311ac20671a911
|