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
Metadata
Release files for lazy-model 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lazy-model-0.4.0.tar.gz | 8.3 kB | Without provenance | Details for lazy-model-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lazy_model-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for lazy_model-0.4.0-py3-none-any.whl |
Total release size: 22.0 kB
Release files / lazy-model-0.4.0.tar.gz
| Download URL | lazy-model-0.4.0.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a851d85d0b518b0b9c8e626bbee0feb0494c0e0cb5636550637f032dbbf9c55f
|
|
BLAKE2b-256 checksum How to use checksums |
7285e25dc36dee49cf0726c03a1558b5c311a17095bc9361bcbf47226cb3075a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.0 CPython/3.12.11 Linux/6.11.0-1018-azure
|
Release files / lazy_model-0.4.0-py3-none-any.whl
| Download URL | lazy_model-0.4.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95ea59551c1ac557a2c299f75803c56cc973923ef78c67ea4839a238142f7927
|
|
BLAKE2b-256 checksum How to use checksums |
5c54653ea0d7c578741e9867ccf0cbf47b7eac09ff22e4238f311ac20671a911
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.0 CPython/3.12.11 Linux/6.11.0-1018-azure
|
Security for lazy-model 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.