Skip to main content

Stop letting heavy packages block down your scripts!

Project description

Release status PyPI package Supported Python versions Test Coverage Status Pypi downloads Pypi downloads Code style: black

comberload

I have recently built some little command line utility. It simply receives a command, parses the command and evaluates it with syntax coloring and autocompletion from prompt_toolkit. But there was an issue, prompt_toolkit loaded extremely, I was wasting alot time to load a package which was not indispensable to my app.

comberload permits you to register modules for queued loading and callbacks if they are not loaded yet, howaworks?

a simple example for a function which uses prompt_toolkit.prompt but can fallback to simple input

import comberload

@comberload("prompt_toolkit")
def get_input():
    import prompt_toolkit

    return prompt_toolkit.prompt()

@get_input.fallback
def fallback_get_input():
    return input()

get_input()  # immediately uses fallback

get_input()  # abit later, uses prompt_toolkit

comberload uses a worker function running on a seperate thread to load the modules as listed in the queue. Each time you call on comberload("module1", "module2") the modules are queued and loaded.

multiple fallbacks

You can easily queue fallbacks as:

import comberload


comberload("mod1", "mod2")
def first():
    pass

@first.fallback
@comberload("mod3")
def second():
    pass

@second.fallback
def third():
    pass

callbacks

comberload also permits you to register callbacks when some modules finish loading as

import comberload

@comberload("mod", "mod2").fallback
def mod_and_mod2_loaded():
    pass

best practice

Only what necessary

I will advice to load only what is necessary taking such an approach

Loading in beginning

What I will advice is to queue all the required import at the begining of each of your modules to permit all of them load without having to fallback.

... # imports
import comberload

comberload("all", "my", "modules")

... # rest of code

Well, you're all set. Listening for issues at https://github.com/ken-morel/comberload , till then, good coding!

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

comberload-1.0.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

comberload-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file comberload-1.0.0.tar.gz.

File metadata

  • Download URL: comberload-1.0.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for comberload-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9b295d60d929c796b4cd31ae635aa2094325057fc1b7b7060046ef9d7950516f
MD5 4d495b797575c368bb6ba5c5b506e8cf
BLAKE2b-256 db61d88231826e1f81d30433cab27eccea40f400cc7a5e7b0310edc341c226f9

See more details on using hashes here.

Provenance

File details

Details for the file comberload-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: comberload-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for comberload-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8f8c24fd9b19983622373718e53d46b797bbf386e565b567c373b4b0038ad9e
MD5 f87b83ad59228b2d147f1b5e31b55aac
BLAKE2b-256 ef27ffb754e2dee2835d6ce270944a0aad572df1bfaa2ae62f96e048d8908e64

See more details on using hashes here.

Provenance

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