Skip to main content

Makes lazy modules in a more readable and friendly way.

Project description

lazyr

Creates lazily-imported modules in a more readable and safer way.

A lazily-imported module (or a lazy module, to be short) is not physically loaded in the Python environment until its attributes are being accessed. This could be very useful when you are importing some modules that are hardly used but take a lot of time to be loaded.

Installation

pip install lazyr

Usage

Let pandas be a lazy module, for example:

import lazyr

lazyr.register("pandas") # pandas is a lazy module from now on

import pandas as pd
print(pd)
# Output: LazyModule(pandas, ignore=set())

df = pd.DataFrame # pandas is activated and actually loaded now
print(df)
# Output: <class 'pandas.core.frame.DataFrame'>

There is also a simpler way to create a lazy module, but may cause type hints to lose efficacy:

pd = lazyr.register("pandas")
print(pd)
# Output: LazyModule(pandas, ignore=set())

Wake up a module

The lazy modules are not actually loaded until their attrubutes are imported or used, but sometimes you may want to activate a lazy module without excessing any of its attributes. In this case, you can wake up it like this:

lazyr.wakeup(pd) # pandas is no longer lazy now

See Also

Github repository

PyPI project

License

This project falls under the BSD 2-Clause License.

History

v0.0.2

  • Added the feature lazyr.wakeup.

v0.0.1

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lazyr-0.0.2-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lazyr-0.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: lazyr-0.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.13

File hashes

Hashes for lazyr-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 692a16b31b2367dfe02d6261f2986f8b0620a46a26dc5b648dc6be24c572a64c
MD5 091e931538b923471879b4fdd4ba1328
BLAKE2b-256 e8a8afbd3d403dc4d53a1d926f61d20d221811123e4f6f531ac144bbfb137f71

See more details on using hashes here.

Supported by

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