Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Shebang support #140

Answered by tiangolo
gergelyk asked this question in Questions
Discussion options

You must be logged in to vote

typer something.py run is needed to be able to get autocompletion in the shell and all that stuff, which is pretty much the benefit of the typer command.

The shebang would be useful if you make the script executable and you want to call it directly. But in that case, you could use plain Python, and run typer at the end, e.g.:

  • main.py:
#! /usr/bin/env python

import typer


def main(name: str):
    print(f"Hello {name}")


if __name__ == "__main__":
    typer.run(main)

And then:

$ chmod +x main.py

And then you can use it as a script directly:

$ ./main.py Grzegorz
Hello Grzegorz

Note: Typer-CLI is now part of Typer, you should simply install pip install typer and you would get the typer

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tiangolo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants
Converted from issue

This discussion was converted from issue #108 on April 06, 2024 22:54.