Skip to content

Typer ​

Starter for a Typer CLI app. Base steps come from Python Project Setup.

Create Project Directory ​

bash
mkdir carbuyers_worker
cd carbuyers_worker

Add Virtual Environment ​

bash
python3 -m venv .venv
source .venv/bin/activate

Install Typer ​

bash
pip install typer

.gitignore ​

bash
echo '# Byte-compiled / optimized / DLL files
__pycache__/
.venv

# editors
/.idea/
/.vscode/
/.zed
' >> .gitignore

main.py ​

python
import typer

app = typer.Typer()


@app.command()
def hello(name: str):
    print(f"Hello {name}")


@app.command()
def goodbye(name: str, formal: bool = False):
    if formal:
        print(f"Goodbye Ms. {name}. Have a good day.")
    else:
        print(f"Bye {name}!")


if __name__ == "__main__":
    app()

Run It ​

Typer apps are CLIs, not servers — there's no dev server to start.

bash
python main.py hello Randy
python main.py goodbye Randy --formal
python main.py --help

Create Repo ​

bash
gh repo create carbuyers_worker --private

Commit to repo ​

bash
git init
git add -A
git commit -m 'Initial Typer install'
git branch -M main
bash
git remote add origin git@github.com:zoonix/carbuyers_worker.git
bash
git push -u origin main