Skip to main content

Style and unit tests badge

click-async-plugins

This is a proof-of-concept of a Python asyncio plugin architecture based on click.

Instead of writing functions that make up sub-commands, you write asynchronous "lifespan functions" (AsyncGenerator), like this one:

@cli_core.plugin_command
@click.option("--sleep", type=click.FloatRange(min=0.01), default=1)
async def myplugin(sleep: float) -> PluginLifespan:

    # code to set things up goes here

    async def long_running_task(*, sleep: float) -> None:
        # task initialisation can happen here

        try:
            while True:
                await asyncio.sleep(sleep)

        finally:
            # code to clean up the task goes here
            pass

    yield long_running_task(sleep=sleep)

    # code to tear things down goes here

Multiple such plugins can be defined/added to core (see the demo code). These plugins will all have their setup code called in turn. If, after setup, a plugin yields a coroutine (e.g. a long-running task), this task is scheduled with the main event loop, but this is optional, and tasks that yield nothing (None) will just sleep until program termination. Upon termination, the plugins' teardown code is invoked (in reverse order).

Here's what the demo code logs to the console. Two plugins are invoked. The first counts down from 3 each second, and notifies subscribers of each number. The second plugin — "echo" — just listens for updates from the "countdown" task and echoes them.

$ python demo.py countdown --from 3 echo --immediately
DEBUG:root:Setting up task for 'echo'
DEBUG:root:Setting up task for 'countdown'
DEBUG:root:Scheduling task for 'echo'
DEBUG:root:Waiting for update to 'countdown'…
DEBUG:root:Scheduling task for 'countdown'
INFO:root:Counting down… 3
DEBUG:root:Notifying subscribers of update to 'countdown'…
INFO:root:Countdown currently at 3
DEBUG:root:Waiting for update to 'countdown'…
INFO:root:Counting down… 2
DEBUG:root:Notifying subscribers of update to 'countdown'…
INFO:root:Countdown currently at 2
DEBUG:root:Waiting for update to 'countdown'…
INFO:root:Counting down… 1
DEBUG:root:Notifying subscribers of update to 'countdown'…
INFO:root:Countdown currently at 1
DEBUG:root:Waiting for update to 'countdown'…
INFO:root:Finished counting down
^C
DEBUG:root:Task for 'echo' cancelled
DEBUG:root:Terminating…
DEBUG:root:Lifespan over for countdown
DEBUG:root:Lifespan over for echo
DEBUG:root:Finished.

I hope you get the idea. If you need more input, take a look at look at tptools' tpsrv CLI, which I was developing when I factored out this code.

There's also a "debug" plugin included, which allows interaction with the CLI as its running via key presses. Hit ? to get an overview of commands available.

Looking forward to your feedback.

TODO

Test coverage… yeah, there's none right now :(

© 2025–26 martin f. krafft <click-async-plugins@pobox.madduck.net>

Metadata

Release files for click-async-plugins 0.7.4

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

Source distribution (sdist)

Source distribution for click-async-plugins 0.7.4
File Size Uploaded
click_async_plugins-0.7.4.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for click-async-plugins 0.7.4
File Interpreter ABI Platform
click_async_plugins-0.7.4-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / click_async_plugins-0.7.4.tar.gz

Download URL click_async_plugins-0.7.4.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9dde4ac9937374e20891ebbd18f8c6e1d45aee9171baf169f1195931d4e4052e
BLAKE2b-256 checksum
How to use checksums
619591877105960aa970fc570577cdd66352851d103bf9c5fd3b9d9203fb2853
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.

Transparency log

Release files / click_async_plugins-0.7.4-py3-none-any.whl

Download URL click_async_plugins-0.7.4-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
241c1d96d59c6a0963bdc7285d09cfca4b632f0fb980f1ab2eca7401aefaea29
BLAKE2b-256 checksum
How to use checksums
ec4f9b9a8c5252667431f4a91f6cff22deb0be3633f2b1789b5c31620dc4fdd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.

Transparency log

Release history Release notifications | RSS feed

0.8.0

2 release files

This release

0.7.4 This release

2 release files

0.7.3

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