Skip to content

Instantly share code, notes, and snippets.

@vnvmar
Last active April 25, 2026 10:16
Show Gist options
  • Select an option

  • Save vnvmar/679e7590b5313fd082c1b9c19a864589 to your computer and use it in GitHub Desktop.

Select an option

Save vnvmar/679e7590b5313fd082c1b9c19a864589 to your computer and use it in GitHub Desktop.
A simple __main__.py file to turn any folder into an autodiscovering typer app composer
from pathlib import Path
import importlib
import typer
app = typer.Typer(
no_args_is_help=True
)
parent_dir = Path(__file__).parent
for file in parent_dir.glob("*.py"):
if file.name.startswith("_") or file.name == Path(__file__).name:
continue
name = f"{parent_dir.stem}.{file.stem}"
mod = importlib.import_module(name)
sub = getattr(mod, "app", None)
if sub is not None:
app.add_typer(sub, name=file.stem)
app()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment