run and launch¶
These two functions can be imported from typer directly:
from typer import launch, run
typer.run
¶
run(function)
This function converts a given function to a CLI application with Typer() and executes it.
Example¶
import typer
def main(name: str):
print(f"Hello {name}")
if __name__ == "__main__":
typer.run(main)
| PARAMETER | DESCRIPTION |
|---|---|
function
|
The function that should power this CLI application.
TYPE:
|
Source code in typer/main.py
1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 | |
typer.launch
¶
launch(url, wait=False, locate=False)
This function launches the given URL (or filename) in the default
viewer application for this file type. If this is an executable, it
might launch the executable in a new session. The return value is
the exit code of the launched application. Usually, 0 indicates
success.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
URL or filename of the thing to launch.
TYPE:
|
wait
|
Wait for the program to exit before returning. This only works if the launched program blocks.
In particular,
TYPE:
|
locate
|
If this is set to
TYPE:
|
The function avoids, when possible, using the webbrowser module on Linux and macOS to prevent spammy terminal messages from some browsers (e.g., Chrome).
Examples¶
import typer
typer.launch("https://typer.tiangolo.com/")
import typer
typer.launch("/my/downloaded/file", locate=True)
Source code in typer/main.py
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 | |