Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support asynchronous CLI methods in CliApp #531

Open
KanchiShimono opened this issue Feb 6, 2025 · 0 comments · May be fixed by #533
Open

Feature Request: Support asynchronous CLI methods in CliApp #531

KanchiShimono opened this issue Feb 6, 2025 · 0 comments · May be fixed by #533
Assignees

Comments

@KanchiShimono
Copy link

Currently, the CliApp.run function only supports synchronous methods. When attempting to pass an asynchronous method to CliApp.run, an error is raised indicating that the coroutine was never awaited. As asynchronous programming becomes more prevalent in Python applications, it would be extremely helpful if CliApp could handle async methods out of the box.

Background

The pydantic-settings library provides a CliApp class that allows running methods of a BaseSettings subclass as CLI commands. However, passing an async method to CliApp.run triggers a warning because the method is never awaited internally.

Sample Code

from pydantic_settings import BaseSettings, CliApp

class AsyncSettings(BaseSettings):
    async def cli_cmd(self) -> None:
        print('Hello from an async CLI method!')

Error

.../.venv/lib/python3.12/site-packages/pydantic_settings/main.py:450: RuntimeWarning: coroutine 'AsyncSettings.cli_cmd' was never awaited
  getattr(type(model), cli_cmd_method_name)(model)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants