Launching Applications¶
AI coding agents
Use the official Typer skill for your installed version. Install it from your project directory:
uvx library-skills
See Develop with AI.
You can launch applications from your CLI program with typer.launch().
It will launch the appropriate application depending on the URL or file type you pass it:
import typer
app = typer.Typer()
@app.command()
def main():
print("Opening Typer's docs")
typer.launch("https://typer.tiangolo.com")
if __name__ == "__main__":
app()
Check it:
$ uv run python main.py
Opening Typer docs
// Opens browser with Typer's docs
Locating a file¶
You can also make the operating system open the file browser indicating where a file is located with locate=True:
from pathlib import Path
import typer
APP_NAME = "my-super-cli-app"
app = typer.Typer()
@app.command()
def main():
app_dir = typer.get_app_dir(APP_NAME)
app_dir_path = Path(app_dir)
app_dir_path.mkdir(parents=True, exist_ok=True)
config_path: Path = Path(app_dir) / "config.json"
if not config_path.is_file():
config_path.write_text('{"version": "1.0.0"}')
config_file_str = str(config_path)
print("Opening config directory")
typer.launch(config_file_str, locate=True)
if __name__ == "__main__":
app()
Tip
The rest of the code in this example is just making sure the app directory exists and creating the config file.
But the most important part is the typer.launch(config_file_str, locate=True) with the argument locate=True.
Check it:
$ uv run python main.py
Opening config directory
// Opens a file browser indicating where the config file is located