Skip to main content

A Python package to lazy import modules and functions.

Project description

Lazypimp

Lazypimp stands for lazy python import. It is a python package that allows you to setup an importing system that loads all imports on demand. This is useful for large projects where you don't want to load all the imports at once.

Installation

using pip:

pip install lazypimp

using conda:

conda install -c conda-forge lazypimp

Usage

Let's say we have a file structure as follows:

mymodule/
    __init__.py
    submod1.py
    submod2.py
    submod3.py
    subpackage/
        __init__.py
        submod4.py
    class1.py
    functions.py

And we want to have the following imports in the __init__.py file:

# imports of submodules
from mymodule import submod1, submod2, submod3 as sm3
from mymodule.subpackage import submod4

# imports of classes, functions, etc.
from mymodule.class1 import MyClass1
from mymodule.functions import my_function

To set up the module mymodule to load submodules on demand, we can use the following code:

from lazypimp import setup

all_modules_by_origin = {
    "mymodule": ["submod1", "submod2", {"sm3": "submod3"}], 
    "mymodule.subpackage": ["submod4"]
}

all_imports_by_origin = {
    "mymodule.class1": "MyClass1",
    "mymodule.functions": "my_function"
}

setup(__name__, all_modules_by_origin, all_imports_by_origin)

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

lazypimp-0.1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

lazypimp-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file lazypimp-0.1.0.tar.gz.

File metadata

  • Download URL: lazypimp-0.1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for lazypimp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bf3c58d15e668a9e54f7f8692b40539ded39f8c2af63c736090895c36d7f8f5e
MD5 552e2c2d823dea85912acaeca972093f
BLAKE2b-256 b3162f6b16d231b5dcbba61276dbc233f561db38e03aa6f36149a70acf9069d7

See more details on using hashes here.

File details

Details for the file lazypimp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lazypimp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for lazypimp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ad8099b582cf0fdb89fd362c6af7df97ec2006aedf75f5068a135149b554530
MD5 18af5acf6354a65244ed8200e24999b3
BLAKE2b-256 5e1ea2c5c1a5377caeef873de9531967ff0c2fb24852687575e56b89ce22aa8f

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