Skip to main content

Python Utilities for the Super Lazy

Project description

lazy

Python Utilities for the Super Lazy


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 around BaseModel with:

    • arbitrary_types_allowed = True
    • .get(name, default) function to retain dict-like properties
  • BaseLazy - Another wrapper around BaseModel with:

    • arbitrary_types_allowed = True
    • extra = 'allow'
    • alias_generator = to_camelcase
    • orjson serializer by default
    • .get(name, default) function to retain dict-like properties

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

lazycls-0.1.13.tar.gz (241.2 kB view details)

Uploaded Source

Built Distribution

lazycls-0.1.13-py3-none-any.whl (290.5 kB view details)

Uploaded Python 3

File details

Details for the file lazycls-0.1.13.tar.gz.

File metadata

  • Download URL: lazycls-0.1.13.tar.gz
  • Upload date:
  • Size: 241.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for lazycls-0.1.13.tar.gz
Algorithm Hash digest
SHA256 ec2a4e530ba8f5204739ece707a554ec1b9f5bfb46aaf4b02c935bf619e0c20b
MD5 ec20461a5a0596db1354358f1830abe8
BLAKE2b-256 3f6d6bb607da65c1eb870a981dd0bd3cf401b61c28ff139238bc138d8eabe444

See more details on using hashes here.

File details

Details for the file lazycls-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: lazycls-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 290.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for lazycls-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 8a5d2e2d75da5930e4a85c400476255133f0a4c5466847a8b1257d16c1a85886
MD5 e8fbeeb72eba8d4c67fd4e9b25362cb7
BLAKE2b-256 b7a64071456f6b2e60e4dddcd6df9cd881e31dce7b3ae2fe7e8caa0f5fa798a7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page