Dynamic Dataclasses for the Super Lazy
Project description
lazycls
When writing data classes becomes too much work
Motivation
This library is forked from an internal project that works with a lot of dataclasses, (AWS API) and I got tired of writing data classes to work with and manipulate them. This library is a wrapper around the main pydantic.create_model
function that recursively parses a dict
object and transforms them into subclasses. So nested dict objects within dicts get transformed into their own dataclass.
Quickstart
pip install --upgrade lazycls
from lazycls import LazyCls, BaseLazy
data = {
'x': ...,
'y': ...
}
obj = LazyCls(
name: str = 'CustomCls',
data: Dict[str, Any] = data,
modulename: str = 'lazycls', # your module name
basecls: Type[BaseModel] = BaseLazy # A custom Base Model class that is used to generate the model
) -> Type[BaseModel]:
"""
obj = lazycls.CustomCls
lazycls.CustomCls.x = ...
lazycls.CustomCls.y = ...
"""
Utilities
Some additional enhancements/utilities include:
-
set_modulename(name)
- set the default module name - useful when included in other libs -
clear_lazy_models
- clears all the currently created lazy models. Memory management -
classproperty
- allows for usage of@classproperty
which isn't available for Python < 3.9 -
BaseCls
- A wrapper aroundBaseModel
with:arbitrary_types_allowed = True
.get(name, default)
function to retaindict
-like properties
-
BaseLazy
- Another wrapper aroundBaseModel
with:arbitrary_types_allowed = True
extra = 'allow'
alias_generator = to_camelcase
orjson
serializer by default.get(name, default)
function to retaindict
-like properties
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
File details
Details for the file lazycls-0.0.2.tar.gz
.
File metadata
- Download URL: lazycls-0.0.2.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58d984e8e3d1e13f5a3786e2982e1614be34e4b7d691cc50edada691fd0368b4 |
|
MD5 | b916d78a47bd9e58c1513663d2fd59f0 |
|
BLAKE2b-256 | 52526453bbf91ecd0ae3c3825d0734d071aab9e6a4919967388be14fceb765f7 |
File details
Details for the file lazycls-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: lazycls-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2f770041592b2fec538a4189205f6d4b5b5a2107845a8596880d6253a61a305 |
|
MD5 | d6979337aecc00c7392a099802ce0ec8 |
|
BLAKE2b-256 | fdb4c651d85d6f935621d9b9235a031f604b3d288669419a95da222c00025ae7 |