Skip to content

Instantly share code, notes, and snippets.

@daaniam
Created May 4, 2023 17:38
Show Gist options
  • Save daaniam/4873f05470de917ab1d6a45993697c87 to your computer and use it in GitHub Desktop.
Save daaniam/4873f05470de917ab1d6a45993697c87 to your computer and use it in GitHub Desktop.
Async typer
class AsyncTyper(typer.Typer):
def __init__(self, *args, **kwargs):
kwargs["no_args_is_help"] = True
super().__init__(*args, **kwargs)
def async_command(self, *args, **kwargs):
def decorator(async_func):
@wraps(async_func)
def sync_func(*_args, **_kwargs):
return run(async_func(*_args, **_kwargs))
self.command(*args, **kwargs)(sync_func)
return async_func
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment