Skip to main content

Lazy loading of Python modules, based on TensorFlow's LazyLoader util.

Project description

tf-lazy-loader

Installation

pip install tf-lazy-loader

Usage

from tf_lazy_loader import dynamic_import

# Lazily import the "os" module
os = dynamic_import("os")

# Trigger the actual import by referencing a name in the "os" module:
print(os.environ)

Conditionally switching between lazy and eager imports

You can set the lazy arg of the dynamic_import function to False to eagerly import the given module. This can be useful if you only want to perform lazy imports based on a flag.

For example, if you have a Django project and you only want to enable lazy imports when in DEBUG mode, and do imports eagerly in production, you would do something like this:

from django.conf import settings

DEBUG = settings.DEBUG

os = dynamic_import("os", lazy=DEBUG)

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

tf_lazy_loader-0.1.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

tf_lazy_loader-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file tf_lazy_loader-0.1.1.tar.gz.

File metadata

  • Download URL: tf_lazy_loader-0.1.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/22.6.0

File hashes

Hashes for tf_lazy_loader-0.1.1.tar.gz
Algorithm Hash digest
SHA256 da132676d1dbee56775ef85536d64c43196191c29023425e6567b300f285bce9
MD5 c3b792036578602cd0deab6f5dbf97b6
BLAKE2b-256 8aa20d511e50ce9795d8c35756c97fad9ef95ba5cdb207cbc5698f09fc261e61

See more details on using hashes here.

File details

Details for the file tf_lazy_loader-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tf_lazy_loader-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/22.6.0

File hashes

Hashes for tf_lazy_loader-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b2623126274f07158d47e7acfdbf3781916c36ba5a3c4800ca6d01f18887dc1
MD5 082eea4d64d9de2b0df7a5b8a6a6ed8b
BLAKE2b-256 af0dd4cc88514ac16d548939665137a44206cb6e59b4bdc84e9eee31b28192fd

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