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.14.tar.gz (243.0 kB view details)

Uploaded Source

Built Distribution

lazycls-0.1.14-py3-none-any.whl (292.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazycls-0.1.14.tar.gz
  • Upload date:
  • Size: 243.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for lazycls-0.1.14.tar.gz
Algorithm Hash digest
SHA256 224a9210b995f531de87a9f958cae13ac8efb248a60c47273cd1fb6bab9b42a8
MD5 eb3ecee592c805eea236810568db1c85
BLAKE2b-256 98b965aacf113c3b6c8741c256359a7204debb569e79f71d317bd44678daab50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lazycls-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 292.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for lazycls-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 fec7fceff69b3e8cdf0e3d281b8f4b236406ebaae3c210b432fa8b8bdec80507
MD5 2398fc83a3fb9cada2d44a93110ac58a
BLAKE2b-256 16efccb96e17cedea98f42bcd1b4bb0e3bcf904e70ae5de7d6961af49987126e

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