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 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

Make a lazy module

Make pandas become 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 a simpler way to create a lazy module, but it 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 physically loaded until their attrubutes are imported or used, but sometimes you may want to activate a lazy module without excessing any of its attributes. For that purpose, 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.3

  • Various improvements.

v0.0.2

  • New lazyr.wakeup function, for compulsively activating modules.

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.3-py2.py3-none-any.whl (5.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: lazyr-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4d3234fc3708c04d251913db0c5fa21fd30d8f2f899d02a649426a57ebb0f9f6
MD5 2fdfb5ef9f4ee85d433275b0f1f4491a
BLAKE2b-256 2026487a88625faeccf288a5245984ae7eb778b4e80d01d4eb9831c205886f24

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