Skip to content

✨ Support async functionality with asyncio#213

Closed
amfarrell wants to merge 12 commits into
fastapi:masterfrom
amfarrell:async-sketch
Closed

✨ Support async functionality with asyncio#213
amfarrell wants to merge 12 commits into
fastapi:masterfrom
amfarrell:async-sketch

Conversation

@amfarrell

Copy link
Copy Markdown

I've merely copied the PR from @jessekrubin. All credit to him.
but I've put it into in a single commit on top of current master so it is small enough to be reviewable.

@codecov

codecov Bot commented Dec 27, 2020

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
tests/test_completion/test_async.py 100.00% <100.00%> (ø)
typer/utils.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Andrew M. Farrell added 2 commits December 27, 2020 19:48
I've merely copied his code, but in a single commit on current master
which is small enough to be reviewable.
@amfarrell amfarrell changed the title Copy @jessekrubin's async async-typer sketch Copy @jessekrubin's async-typer sketch Dec 27, 2020
@malthunayan

Copy link
Copy Markdown

@amfarrell thank you for doing that so the difference is actually viewable now. Just a small comment, for line 213 in main.py I see the following:

def __call__(self, *args: Any, **kwargs: Any) -> Any:
        cmd = get_command(self)
        print(cmd, is_async(cmd))
        if is_async(cmd):
            return aio_run(cmd(*args, **kwargs))
        return get_command(self)(*args, **kwargs)

I think the print statement was left there by mistake, and I see get_command(self) being called twice. Perhaps it could be written as such:

def __call__(self, *args: Any, **kwargs: Any) -> Any:
        cmd = get_command(self)
        if is_async(cmd):
            return aio_run(cmd(*args, **kwargs))
        return cmd(*args, **kwargs)

@amfarrell

amfarrell commented Dec 30, 2020

Copy link
Copy Markdown
Author

@malthunayan I've removed that print statement now.

@jessekrubin

jessekrubin commented Dec 30, 2020 via email

Copy link
Copy Markdown

@cauebs

cauebs commented Apr 13, 2021

Copy link
Copy Markdown

It would be interesting to allow aio_run to be overriden somehow, to support other async frameworks. If it were used exclusively inside the Typer class, it would be trivial: an optional async_runner kwarg on the constructor. As it stands, I'm not sure how it could be patched. Shouldn't be too complex, though.

@svlandeg svlandeg added feature New feature, enhancement or request p3 and removed investigate labels Mar 8, 2024
@jessekrubin

Copy link
Copy Markdown

@svlandeg @amfarrell how's everybody doing!? I am here!

@amfarrell

Copy link
Copy Markdown
Author

Hi @jessekrubin if you could drive this forward, I'd be grateful. I've had to refocus to other projects.

@svlandeg svlandeg self-assigned this Feb 6, 2025
@svlandeg
svlandeg marked this pull request as draft August 18, 2025 09:12
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Sep 1, 2025
@github-actions

This comment was marked as resolved.

@jessekrubin

jessekrubin commented Sep 3, 2025

Copy link
Copy Markdown

This is still open? I totally forgot about this.

@svlandeg

svlandeg commented Sep 3, 2025

Copy link
Copy Markdown
Member

Hi @jessekrubin! We do still have optional async support on our roadmap, so I wanted to have a look at previously suggested approaches to distill a final solution from. #340 being another example.

@svlandeg svlandeg removed their assignment Nov 4, 2025
@svlandeg svlandeg changed the title Copy @jessekrubin's async-typer sketch ✨ Support async functionality with asyncio Nov 19, 2025
@github-actions github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Nov 19, 2025
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Dec 25, 2025
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

@tiangolo

Copy link
Copy Markdown
Member

Thanks everyone for the work here! There are several refactors we needed to do before this that cause conflicts, plus some more, and some additional details in what is needed in the implementation, but we'll need to tackle this again after some additional work.

I'm sorry I left the PR open without much feedback for so long, I knew there were other things that needed to be done first, but didn't want to close it before providing a solution... but then that ended up being just too long. Sorry for that.

So for now, I'll close this one for cleanup and we'll continue to track it internally. Thank you! 🙌 ☕

@tiangolo tiangolo closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature, enhancement or request p3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants