I would like to create a CLI command using pyproject.toml based on async Python function. Lets say I have this Python function in example/main.py:
async def main():
print("Hello world!")
and pyproject.toml file:
[project]
name = "example"
...
[project.scripts]
example = "example.main:main"
When I try to execute example CLI command I get this error:
$ example
<coroutine object main at 0x7af706afbb80>
sys:1: RuntimeWarning: coroutine 'main' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
It seems that pyproject.toml only supports synchronous function targets. Is there a way to tell pyproject.toml that the target is asynchronous and it has to be awaited without messing up with code?
asyncio.run, then wrap that in a sync func, then use that as the entry point?asyncio.runand I would accept it as an answer to this question. However, I wanted to inquire is there a simpler way, e.g. like[project.async_scripts]section inpyproject.toml?