1- <div align =" center " ><img src =" https://raw.githubusercontent.com/pallets/click/refs/heads/stable/docs/_static/click-name.svg " alt =" " height =" 150 " ></div >
1+ # $ asyncclick_
2+
3+ Asyncclick is a fork of Click (described below) that works with trio or asyncio.
24
3- # AsyncClick
5+ AsyncClick allows you to seamlessly use async command and subcommand handlers.
46
5- [ AsyncClick] [ ] is a fork of Click that works well with [ anyio] [ ] , [ Trio] [ ] , or [ asyncio] [ ] .
67
7- [ anyio ] : https://anyio.readthedocs.io/en/stable/
8- [ Trio ] : https://trio.readthedocs.io/en/stable/
9- [ asyncio ] : https://docs.python.org/3/library/asyncio.html
10- [ AsyncClick ] : https://github.com/python-trio/asyncclick/
8+ <div align =" center " ><img src =" https://raw.githubusercontent.com/pallets/click/refs/heads/stable/docs/_static/click-name.svg " alt =" " height =" 150 " ></div >
119
1210# Click
1311
@@ -20,12 +18,11 @@ It aims to make the process of writing command line tools quick and fun
2018while also preventing any frustration caused by the inability to
2119implement an intended CLI API.
2220
23- AsyncClick in four points:
21+ Click in three points:
2422
2523- Arbitrary nesting of commands
2624- Automatic help page generation
2725- Supports lazy loading of subcommands at runtime
28- - Seamlessly use async-enabled command and subcommand handlers
2926
3027
3128## A Simple Example
@@ -39,13 +36,13 @@ import anyio
3936@click.option (" --name" , prompt = " Your name" , help = " The person to greet." )
4037async def hello (count , name ):
4138 """ Simple program that greets NAME for a total of COUNT times."""
42- for x in range (count):
43- if x:
44- await anyio.sleep(0.1 )
39+ for _ in range (count):
4540 click.echo(f " Hello, { name} ! " )
41+ await anyio.sleep(0.2 )
4642
4743if __name__ == ' __main__' :
4844 hello()
45+ # alternately: anyio.run(hello.main)
4946```
5047
5148```
@@ -56,15 +53,28 @@ Hello, Click!
5653Hello, Click!
5754```
5855
59- Compared to the original [ Click] [ ] , you'll note that AsyncClick supports
60- optional(!) sprinkling of ` async ` /` await ` keywords wherever your code needs
61- them.
56+ ## Differences to Click
57+
58+ This async-ized version of Click is mostly backwards compatible for "normal" use:
59+ you can freely mix sync and async versions of your command handlers and callbacks.
6260
63- In the interest of not diverging from Click more than absolutely necessary,
64- many examples have not been touched .
61+ Several advanced methods, most notably :meth: ` BaseCommand.main ` , and
62+ :meth: ` Context.invoke ` , are now asynchronous .
6563
64+ The :meth:` BaseCommand.__call__ ` alias now invokes the main entry point via
65+ ` anyio.run ` . If you already have an async main program, simply use
66+ `` await cmd.main() `` instead of `` cmd() `` .
67+
68+ :func:` asyncclick.prompt ` is asyncronous and accepts a `` blocking `` parameter
69+ that switches between "doesn't affect your event loop but has unwanted effects when
70+ interrupted" (bugfix pending) and "pauses your event loop but is safe to interrupt"
71+ with Control-C". The latter is the default until we fix that bug.
72+
73+ You cannot use Click and AsyncClick in the same program. This is not a problem
74+ in practice, as replacing `` import click `` with `` import asyncclick as click `` , and
75+ `` from click import ... `` with `` from asyncclick import ... `` , should be all that's
76+ required.
6677
67- [ Click ] : https://palletsprojects.com/p/click/
6878
6979## Donate
7080
@@ -76,13 +86,29 @@ donate today][].
7686[ please donate today ] : https://palletsprojects.com/donate
7787
7888The AsyncClick fork is maintained by Matthias Urlichs < matthias@urlichs.de > .
79- It's not a lot of work, so if you'd like to motivate me, donate to the
80- charity of your choice and tell me that you've done so. ;-)
8189
8290## Contributing
8391
92+ ### Click
93+
8494See our [ detailed contributing documentation] [ contrib ] for many ways to
8595contribute, including reporting issues, requesting features, asking or answering
8696questions, and making PRs.
8797
8898[ contrib ] : https://palletsprojects.com/contributing/
99+
100+ ### AsyncClick
101+
102+ You can file async-specific issues, ideally including a corresponding fix,
103+ to the [ MoaT/asyncclick] [ moat ] repository on github.
104+
105+ [ moat ] : https://github.com/M-o-a-T/asyncclick
106+
107+ #### Testing
108+
109+ If you find a bug, please add a testcase to prevent it from recurring.
110+
111+ In tests, you might wonder why ` runner.invoke ` is not called asynchronously.
112+ The reason is that there are far too many of these calls to modify them all.
113+ Thus `` tests/conftest.py `` contains a monkeypatch that turns this call
114+ into a thread that runs this call using ` anyio.run ` .
0 commit comments