Calmcode - typer: introduction

Setting up Typer in Python

1 2 3 4 5 6 7 8 9 10

You can run python from the terminal and you're even able to pass in arguments using just the base library.

import sys

def hello_world(name):
    print(f"hello {name}!")

if __name__ == "__main__":

If you were to run you would be able to use the program and send arguments to it.

python vincent

However, there are some utilities missing. So let's make a better command line experience by using typer.

Using Typer

Before you're able to use typer, you need to make sure that it is installed.

pip install typer

Here's the same app, but now with typer.

import typer

def hello_world(name):
    """This prints your name"""
    print(f"hello {name}!")

if __name__ == "__main__":

When you run this from the command line, the experience is a lot better.