Skip to main content

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.

Comberloads, since comberload 1.0.2, were added two more methods to comberloader, failback and fail

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

fallback

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

fail

Use this handler in case the module fails to import

import comberload


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

@first.fail
def second():
    print(first.error)

failback

This is what I advice to use, it uses the default handler in case the module is not loaded due to error or any else.

import comberload


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

@first.failback
def second():
    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!

Metadata

Release files for comberload 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comberload 1.1.3
File Size Uploaded
comberload-1.1.3.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for comberload 1.1.3
File Interpreter ABI Platform
comberload-1.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / comberload-1.1.3.tar.gz

Download URL comberload-1.1.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3b51432af10db007498e637db7ec0a8e1042f2260f75cd683e2544d27a085c83
BLAKE2b-256 checksum
How to use checksums
520d2ab2b7f54eefe5fd91388f62b21b84bcce5676eaf339d8ae80f3857f8908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / comberload-1.1.3-py3-none-any.whl

Download URL comberload-1.1.3-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22d180e253773d9e5bb8c008d999e4fff43b0bc18bbc860904ae1f8b9b2d4332
BLAKE2b-256 checksum
How to use checksums
30bd1da2271fe382776d9f2c2cd7203d0c2f387ed29b1c6f48627dc1deb044d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page