Skip to content
Myr

📝 Update link syntax to minimal Markdown (#1623)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sebastián Ramírez · committed by GitHub · parent d10dff0 · Browse files · 36 files+161 added−161 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

36 files+161 added−161 removed

  • other:+161 added−161 removed

36 files+161 added−161 removed

modified:docs/tutorial/arguments/envvar.md+1 added-1 removed
modified:docs/tutorial/arguments/help.md+2 added-2 removed
183 unmodified lines
184## *CLI Argument* help panels185186You might want to show the help information for *CLI arguments* in different panels when using the `--help` option.187188If you have installed Rich as described in the docs for [Printing and Colors](../printing.md){.internal-link target=_blank}, you can set the `rich_help_panel` parameter to the name of the panel where you want this *CLI argument* to be shown:188If you have installed Rich as described in the docs for [Printing and Colors](../printing.md), you can set the `rich_help_panel` parameter to the name of the panel where you want this *CLI argument* to be shown:189190{* docs_src/arguments/help/tutorial007_an_py310.py hl[12,16] *}191192Then, if you check the `--help` option, you will see a default panel named "`Arguments`" for the *CLI arguments* that don't have a custom `rich_help_panel`.
26 unmodified lines
219In this example we have a custom *CLI arguments* panel named "`Secondary Arguments`".220221## Help with style using Rich222223In a future section you will see how to use custom markup in the `help` for *CLI arguments* when reading about [Commands - Command Help](../commands/help.md#rich-markdown-and-markup){.internal-link target=_blank}.223In a future section you will see how to use custom markup in the `help` for *CLI arguments* when reading about [Commands - Command Help](../commands/help.md#rich-markdown-and-markup).224225If you are in a hurry you can jump there, but otherwise, it would be better to continue reading here and following the tutorial in order.226227## Hide a *CLI argument* from the help text
40 unmodified lines
modified:docs/tutorial/arguments/optional.md+2 added-2 removed
31 unmodified lines
32</div>3334## An alternative *CLI argument* declaration3536In the [First Steps](../first-steps.md#add-a-cli-argument){.internal-link target=_blank} you saw how to add a *CLI argument*:36In the [First Steps](../first-steps.md#add-a-cli-argument) you saw how to add a *CLI argument*:3738{* docs_src/first_steps/tutorial002_py310.py hl[4] *}3940Now let's see an alternative way to create the same *CLI argument*:
169 unmodified lines
210```211212/// note213214If you hadn't seen that `...` before: it is a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.214If you hadn't seen that `...` before: it is a special single value, it is [part of Python and is called "Ellipsis"](https://docs.python.org/3/library/constants.html#Ellipsis).215216///217218{* docs_src/arguments/optional/tutorial003_py310.py hl[7] *}
20 unmodified lines
modified:docs/tutorial/commands/context.md+1 added-1 removed
2 unmodified lines
3When you create a **Typer** application it always has a special, hidden object underneath called the "Context".45But you can access the context by declaring a function parameter of type `typer.Context`.67You might have read it in [CLI Option Callback and Context](../options/callback-and-context.md){.internal-link target=_blank}.7You might have read it in [CLI Option Callback and Context](../options/callback-and-context.md).89The same way, in commands or in the main `Typer` callback you can access the context by declaring a function parameter of type `typer.Context`.1011## Getting the context
114 unmodified lines
modified:docs/tutorial/commands/help.md+4 added-4 removed
211 unmodified lines
212///213214### Rich Markup215216If you set `rich_markup_mode="rich"` when creating the `typer.Typer()` app (which is the default), you will be able to use <a href="https://rich.readthedocs.io/en/stable/markup.html" class="external-link" target="_blank">Rich Console Markup</a> in the docstring, and even in the help for the *CLI arguments* and options:216If you set `rich_markup_mode="rich"` when creating the `typer.Typer()` app (which is the default), you will be able to use [Rich Console Markup](https://rich.readthedocs.io/en/stable/markup.html) in the docstring, and even in the help for the *CLI arguments* and options:217218{* docs_src/commands/help/tutorial004_an_py310.py hl[5,11,15:17,22,25,28] *}219220With that, you can use <a href="https://rich.readthedocs.io/en/stable/markup.html" class="external-link" target="_blank">Rich Console Markup</a> to format the text in the docstring for the command `create`, make the word "`create`" bold and green, and even use an <a href="https://rich.readthedocs.io/en/stable/markup.html#emoji" class="external-link" target="_blank">emoji</a>.220With that, you can use [Rich Console Markup](https://rich.readthedocs.io/en/stable/markup.html) to format the text in the docstring for the command `create`, make the word "`create`" bold and green, and even use an [emoji](https://rich.readthedocs.io/en/stable/markup.html#emoji).221222You can also use markup in the help for the `username` CLI Argument.223224And the same as before, the help text overwritten for the command `delete` can also use Rich Markup, the same in the CLI Argument and CLI Option.
54 unmodified lines
279If you set `rich_markup_mode="markdown"` when creating the `typer.Typer()` app, you will be able to use Markdown in the docstring:280281{* docs_src/commands/help/tutorial005_an_py310.py hl[5,10,13:21,26,28:29] *}282283With that, you can use Markdown to format the text in the docstring for the command `create`, make the word "`create`" bold, show a list of items, and even use an <a href="https://rich.readthedocs.io/en/stable/markup.html#emoji" class="external-link" target="_blank">emoji</a>.283With that, you can use Markdown to format the text in the docstring for the command `create`, make the word "`create`" bold, show a list of items, and even use an [emoji](https://rich.readthedocs.io/en/stable/markup.html#emoji).284285And the same as before, the help text overwritten for the command `delete` can also use Markdown.286287Check the help for the `create` command:
59 unmodified lines
347## Help Panels348349If you have many commands or CLI parameters, you might want to show their documentation in different panels when using the `--help` option.350351If you installed <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a> as described in [Printing and Colors](../printing.md){.internal-link target=_blank}, you can configure the panel to use for each command or CLI parameter.351If you installed [Rich](https://rich.readthedocs.io/) as described in [Printing and Colors](../printing.md), you can configure the panel to use for each command or CLI parameter.352353### Help Panels for Commands354355To set the panel for a command you can pass the argument `rich_help_panel` with the name of the panel you want to use:
149 unmodified lines
modified:docs/tutorial/options/help.md+1 added-1 removed
91 unmodified lines
92Here we have a custom *CLI options* panel named "`Customization and Utils`".9394## Help with style using Rich9596In a future section you will see how to use custom markup in the `help` for *CLI options* when reading about [Commands - Command Help](../commands/help.md#rich-markdown-and-markup){.internal-link target=_blank}.96In a future section you will see how to use custom markup in the `help` for *CLI options* when reading about [Commands - Command Help](../commands/help.md#rich-markdown-and-markup).9798If you are in a hurry you can jump there, but otherwise, it would be better to continue reading here and following the tutorial in order.99100
57 unmodified lines
modified:docs/tutorial/options/name.md+1 added-1 removed
30 unmodified lines
31{* docs_src/options/name/tutorial001_an_py310.py hl[9] *}3233/// note3435"<a href="https://docs.python.org/3.8/glossary.html#term-argument" class="external-link" target="_blank">Positional</a>" means that it's not a function argument with a keyword name.35"[Positional](https://docs.python.org/3.8/glossary.html#term-argument)" means that it's not a function argument with a keyword name.3637For example `show_default=True` is a keyword argument. "`show_default`" is the keyword.3839But in `"--name"` there's no `option_name="--name"` or something similar, it's just the string value `"--name"` that goes in `typer.Option()`.
278 unmodified lines
modified:docs/tutorial/options/required.md+1 added-1 removed
modified:docs/tutorial/options/version.md+1 added-1 removed
84 unmodified lines
85///8687/// note8889If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](../printing.md#standard-output-and-standard-error){.internal-link target=_blank}.89If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](../printing.md#standard-output-and-standard-error).9091///9293### Fix with `is_eager`
19 unmodified lines
modified:docs/tutorial/parameter-types/datetime.md+2 added-2 removed
1# DateTime23You can specify a *CLI parameter* as a Python <a href="https://docs.python.org/3/library/datetime.html" class="external-link" target="_blank">`datetime`</a>.3You can specify a *CLI parameter* as a Python [`datetime`](https://docs.python.org/3/library/datetime.html).45Your function will receive a standard Python `datetime` object, and again, your editor will give you completion, etc.67{* docs_src/parameter_types/datetime/tutorial001_py310.py hl[1,9,10,11] *}
38 unmodified lines
46## Custom date format4748You can also customize the formats received for the `datetime` with the `formats` parameter.4950`formats` receives a list of strings with the date formats that would be passed to <a href="https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime" class="external-link" target="_blank">datetime.strptime()</a>.50`formats` receives a list of strings with the date formats that would be passed to [datetime.strptime()](https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime).5152For example, let's imagine that you want to accept an ISO formatted datetime, but for some strange reason, you also want to accept a format with:5354* first the month
31 unmodified lines
modified:docs/tutorial/parameter-types/enum.md+1 added-1 removed
1# Enum - Choices23To define a *CLI parameter* that can take a value from a predefined set of values you can use a standard Python <a href="https://docs.python.org/3/library/enum.html" class="external-link" target="_blank">`enum.Enum`</a>:3To define a *CLI parameter* that can take a value from a predefined set of values you can use a standard Python [`enum.Enum`](https://docs.python.org/3/library/enum.html):45{* docs_src/parameter_types/enum/tutorial001_py310.py hl[1,6:9,16:17] *}67/// tip
140 unmodified lines
modified:docs/tutorial/parameter-types/file.md+3 added-3 removed
8 unmodified lines
9You can read and write data with `Path` the same way.1011///1213The difference is that these types will give you a Python <a href="https://docs.python.org/3/glossary.html#term-file-object" class="external-link" target="_blank">file-like object</a> instead of a Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" class="external-link" target="_blank">Path</a>.13The difference is that these types will give you a Python [file-like object](https://docs.python.org/3/glossary.html#term-file-object) instead of a Python [Path](https://docs.python.org/3/library/pathlib.html#basic-use).1415A "file-like object" is the same type of object returned by `open()` as in:1617```Python
149 unmodified lines
167## File *CLI parameter* configurations168169You can use several configuration parameters for these types (classes) in `typer.Option()` and `typer.Argument()`:170171* `mode`: controls the "<a href="https://docs.python.org/3/library/functions.html#open" class="external-link" target="_blank">mode</a>" to open the file with.171* `mode`: controls the "[mode](https://docs.python.org/3/library/functions.html#open)" to open the file with.172 * It's automatically set for you by using the classes above.173 * Read more about it below.174* `encoding`: to force a specific encoding, e.g. `"utf-8"`.175* `lazy`: delay <abbr title="input and output, reading and writing files">I/O</abbr> operations. Automatic by default.
1 unmodified line
177* `atomic`: if true, all writes will actually go to a temporal file and then moved to the final destination after completing. This is useful with files modified frequently by several users/programs.178179## Advanced `mode`180181By default, **Typer** will configure the <a href="https://docs.python.org/3/library/functions.html#open" class="external-link" target="_blank">`mode`</a> for you:181By default, **Typer** will configure the [`mode`](https://docs.python.org/3/library/functions.html#open) for you:182183* `typer.FileText`: `mode="r"`, to read text.184* `typer.FileTextWrite`: `mode="w"`, to write text.185* `typer.FileBinaryRead`: `mode="rb"`, to read binary data.
49 unmodified lines
modified:docs/tutorial/parameter-types/path.md+1 added-1 removed
1# Path23You can declare a *CLI parameter* to be a standard Python <a href="https://docs.python.org/3/library/pathlib.html#basic-use" class="external-link" target="_blank">`pathlib.Path`</a>.3You can declare a *CLI parameter* to be a standard Python [`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#basic-use).45This is what you would do for directory paths, file paths, etc:67{* docs_src/parameter_types/path/tutorial001_an_py310.py hl[1,10] *}
99 unmodified lines
modified:docs/tutorial/parameter-types/uuid.md+2 added-2 removed
1# UUID23/// note45A UUID is a <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier" class="external-link" target="_blank">"Universally Unique Identifier"</a>.5A UUID is a ["Universally Unique Identifier"](https://en.wikipedia.org/wiki/Universally_unique_identifier).67It's a standard format for identifiers, like passport numbers, but for anything, not just people in countries.89They look like this:
13 unmodified lines
23You can declare a *CLI parameter* as a UUID:2425{* docs_src/parameter_types/uuid/tutorial001_py310.py hl[1,9:11] *}2627Your Python code will receive a standard Python <a href="https://docs.python.org/3.8/library/uuid.html" class="external-link" target="_blank">`UUID`</a> object with all its attributes and methods, and as you are annotating your function parameter with that type, you will have type checks, autocompletion in your editor, etc.27Your Python code will receive a standard Python [`UUID`](https://docs.python.org/3.8/library/uuid.html) object with all its attributes and methods, and as you are annotating your function parameter with that type, you will have type checks, autocompletion in your editor, etc.2829Check it:3031<div class="termy">
18 unmodified lines
modified:docs/tutorial/subcommands/callback-override.md+1 added-1 removed
47 unmodified lines
48## Overriding the callback on creation4950If a callback was added when creating the `typer.Typer()` app, it's possible to override it with a new one using `@app.callback()`.5152This is the same information you saw on the section about [Commands - Typer Callback](../commands/callback.md){.internal-link target=_blank}, and it applies the same for sub-Typer apps:52This is the same information you saw on the section about [Commands - Typer Callback](../commands/callback.md), and it applies the same for sub-Typer apps:5354{* docs_src/subcommands/callback_override/tutorial003_py310.py hl[6,7,10,14,15,16] *}5556Here we had defined a callback when creating the `typer.Typer()` sub-app, but then we override it with a new callback with the function `user_callback()`.
42 unmodified lines
modified:docs/tutorial/subcommands/index.md+1 added-1 removed
1# SubCommands - Command Groups23You read before how to create a program with [Commands](../commands/index.md){.internal-link target=_blank}.3You read before how to create a program with [Commands](../commands/index.md).45Now we'll see how to create a *CLI program* with commands that have their own subcommands. Also known as command groups.67For example, the *CLI program* `git` has a command `remote`.
34 unmodified lines
modified:docs/tutorial/app-dir.md+1 added-1 removed
30 unmodified lines
31If the first element is a `Path` object the next ones (after the `/`) can be `str`.3233And it will create a new `Path` object from that.3435If you want a quick guide on using `Path()` you can check <a href="https://realpython.com/python-pathlib/" class="external-link" target="_blank">this post on Real Python</a> or <a href="https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/" class="external-link" target="_blank">this post by Trey Hunner</a>.35If you want a quick guide on using `Path()` you can check [this post on Real Python](https://realpython.com/python-pathlib/) or [this post by Trey Hunner](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/).3637In the code above, we are also explicitly declaring `config_path` as having type `Path` to help the editor provide completion and type checks:3839```Python
4 unmodified lines
modified:docs/tutorial/index.md+2 added-2 removed
6 unmodified lines
7You could consider this a **book**, a **course**, the **official** and recommended way to learn **Typer**. 😎89## Python Types1011If you need a refresher about how to use Python type hints, check the first part of <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">FastAPI's Python types intro</a>.11If you need a refresher about how to use Python type hints, check the first part of [FastAPI's Python types intro](https://fastapi.tiangolo.com/python-types/).1213You can also check the <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank">mypy cheat sheet</a>.13You can also check the [mypy cheat sheet](https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html).1415In short (very short), you can declare a function with parameters like:1617```Python
47 unmodified lines
modified:docs/tutorial/install.md+1 added-1 removed
1# Install **Typer**23The first step is to install **Typer**.45First, make sure you create your [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example with:5First, make sure you create your [virtual environment](../virtual-environments.md), activate it, and then install it, for example with:67<div class="termy">89```console
8 unmodified lines
modified:docs/tutorial/options-autocompletion.md+4 added-4 removed
46 unmodified lines
47## Custom completion for values4849Right now we get completion for the *CLI option* names, but not for the values.5051We can provide completion for the values creating an `autocompletion` function, similar to the `callback` functions from [CLI Option Callback and Context](./options/callback-and-context.md){.internal-link target=_blank}:51We can provide completion for the values creating an `autocompletion` function, similar to the `callback` functions from [CLI Option Callback and Context](./options/callback-and-context.md):5253{* docs_src/options_autocompletion/tutorial002_an_py310.py hl[6:7,16] *}5455We return a `list` of strings from the `complete_name()` function.
98 unmodified lines
154## Simplify with `yield`155156Instead of creating and returning a list with values (`str` or `tuple`), we can use `yield` with each value that we want in the completion.157158That way our function will be a <a href="https://docs.python.org/3.8/glossary.html#index-19" class="external-link" target="_blank">generator</a> that **Typer** can iterate:158That way our function will be a [generator](https://docs.python.org/3.8/glossary.html#index-19) that **Typer** can iterate:159160{* docs_src/options_autocompletion/tutorial005_an_py310.py hl[12:15] *}161162That simplifies our code a bit and works the same.
7 unmodified lines
170///171172/// note173174The function can use `yield`, so it doesn't have to return strictly a `list`, it just has to be <a href="https://docs.python.org/3.8/glossary.html#term-iterable" class="external-link" target="_blank">iterable</a>.174The function can use `yield`, so it doesn't have to return strictly a `list`, it just has to be [iterable](https://docs.python.org/3.8/glossary.html#term-iterable).175176But each of the elements for completion has to be a `str` or a `tuple` (when containing a help text).177178///
104 unmodified lines
283### Printing to "standard error"284285/// tip286287If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](./printing.md#standard-output-and-standard-error){.internal-link target=_blank}.287If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](./printing.md#standard-output-and-standard-error).288289///290291The completion system only reads from "standard output", so, printing to "standard error" won't break completion. 🚀
93 unmodified lines
modified:docs/tutorial/package.md+10 added-10 removed
18 unmodified lines
19///2021## Prerequisites2223For this guide we'll use <a href="https://docs.astral.sh/uv/" class="external-link" target="_blank">uv</a>.23For this guide we'll use [uv](https://docs.astral.sh/uv/).2425uv's docs are great, so go ahead, check them and install it.2627## Create a project
292 unmodified lines
320///321322/// tip323324Bonus points if you use <a href="https://docs.astral.sh/uv/" class="external-link" target="_blank">uvx</a> to install it while keeping an isolated environment for your Python CLI programs 🚀324Bonus points if you use [uvx](https://docs.astral.sh/uv/) to install it while keeping an isolated environment for your Python CLI programs 🚀325326///327328Now you have your CLI program installed. And you can use it freely:
156 unmodified lines
485But you can still support `python -m` for the cases where it's useful.486487## Publish to PyPI (optional)488489You can publish that new package to <a href="https://pypi.org/" class="external-link" target="_blank">PyPI</a> to make it public, so others can install it easily.489You can publish that new package to [PyPI](https://pypi.org/) to make it public, so others can install it easily.490491So, go ahead and create an account there (it's free).492493### PyPI API token494495To do it, you first need to configure a PyPI auth token.496497Login to <a href="https://pypi.org/" class="external-link" target="_blank">PyPI</a>.497Login to [PyPI](https://pypi.org/).498499And then go to <a href="https://pypi.org/manage/account/token/" class="external-link" target="_blank">https://pypi.org/manage/account/token/</a> to create a new token.499And then go to [https://pypi.org/manage/account/token/](https://pypi.org/manage/account/token/) to create a new token.500501Let's say your new API token is:502503```
26 unmodified lines
530```531532</div>533534Now you can go to PyPI and check your projects at <a href="https://pypi.org/manage/projects/" class="external-link" target="_blank">https://pypi.org/manage/projects/</a>.534Now you can go to PyPI and check your projects at [https://pypi.org/manage/projects/](https://pypi.org/manage/projects/).535536You should now see your new "rick-portal-gun" package.537538### Install from PyPI
119 unmodified lines
658## What's next659660This is a very simple guide. You could add many more steps.661662For example, you should use <a href="https://git-scm.com/" class="external-link" target="_blank">Git</a>, the version control system, to save your code.662For example, you should use [Git](https://git-scm.com/), the version control system, to save your code.663664You could use <a href="https://docs.astral.sh/uv/" class="external-link" target="_blank">uv</a> to manage your installed CLI Python programs in isolated environments.664You could use [uv](https://docs.astral.sh/uv/) to manage your installed CLI Python programs in isolated environments.665666Maybe use automatic formatting with <a href="https://docs.astral.sh/ruff/" class="external-link" target="_blank">Ruff</a>.666Maybe use automatic formatting with [Ruff](https://docs.astral.sh/ruff/).667668You'll probably want to publish your code as open source to <a href="https://github.com/" class="external-link" target="_blank">GitHub</a>.668You'll probably want to publish your code as open source to [GitHub](https://github.com/).669670And then you could integrate a <abbr title="Continuous Integration">CI</abbr> tool to run your tests and deploy your package automatically.671672And there's a long etc. But now you have the basics and you can continue on your own. 🚀
modified:docs/tutorial/printing.md+9 added-9 removed
16 unmodified lines
17</div>1819## Use Rich2021You can also display beautiful and more complex information using <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a>. It comes by default when you install `typer`.21You can also display beautiful and more complex information using [Rich](https://rich.readthedocs.io/). It comes by default when you install `typer`.2223### Use Rich `print`2425For the simplest cases, you can just import `print` from `rich` and use it instead of the standard `print`:
23 unmodified lines
49</div>5051### Rich Markup5253Rich also supports a <a href="https://rich.readthedocs.io/en/stable/markup.html" class="external-link" target="_blank">custom markup syntax</a> to set colors and styles, for example:53Rich also supports a [custom markup syntax](https://rich.readthedocs.io/en/stable/markup.html) to set colors and styles, for example:5455{* docs_src/printing/tutorial002_py310.py hl[9] *}5657<div class="termy">
7 unmodified lines
65</div>6667In this example you can see how to use font styles, colors, and even emojis.6869To learn more check out the <a href="https://rich.readthedocs.io/en/stable/markup.html" class="external-link" target="_blank">Rich docs</a>.69To learn more check out the [Rich docs](https://rich.readthedocs.io/en/stable/markup.html).7071### Rich Tables7273The way Rich works internally is that it uses a `Console` object to display the information.
24 unmodified lines
98</div>99100Rich has many other features, as an example, you can check the docs for:101102* <a href="https://rich.readthedocs.io/en/stable/prompt.html" class="external-link" target="_blank">Prompt</a>103* <a href="https://rich.readthedocs.io/en/stable/markdown.html" class="external-link" target="_blank">Markdown</a>104* <a href="https://rich.readthedocs.io/en/stable/panel.html" class="external-link" target="_blank">Panel</a>102* [Prompt](https://rich.readthedocs.io/en/stable/prompt.html)103* [Markdown](https://rich.readthedocs.io/en/stable/markdown.html)104* [Panel](https://rich.readthedocs.io/en/stable/panel.html)105* ...and more.106107### Typer and Rich108
72 unmodified lines
181## Typer Echo182183/// warning184185In most of the cases, for displaying advanced information, it is recommended to use <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a>.185In most of the cases, for displaying advanced information, it is recommended to use [Rich](https://rich.readthedocs.io/).186187You can probably skip the rest of this section. 🎉😎188189///
25 unmodified lines
215///216217/// tip218219Again, you are much better off using <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a> for this. 😎219Again, you are much better off using [Rich](https://rich.readthedocs.io/) for this. 😎220221///222223You can create colored strings to output to the terminal with `typer.style()`, that gives you `str`s that you can then pass to `typer.echo()`:
31 unmodified lines
255### `typer.secho()` - style and print256257/// tip258259In case you didn't see above, you are much better off using <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a> for this. 😎259In case you didn't see above, you are much better off using [Rich](https://rich.readthedocs.io/) for this. 😎260261///262263There's a shorter form to style and print at the same time with `typer.secho()` it's like `typer.echo()` but also adds style like `typer.style()`:
9 unmodified lines
modified:docs/tutorial/progressbar.md+6 added-6 removed
2 unmodified lines
3If you are executing an operation that can take some time, you can inform it to the user. 🤓45## Progress Bar67You can use <a href="https://rich.readthedocs.io/en/stable/progress.html" class="external-link" target="_blank">Rich's Progress Display</a> to show a progress bar, for example:7You can use [Rich's Progress Display](https://rich.readthedocs.io/en/stable/progress.html) to show a progress bar, for example:89{* docs_src/progressbar/tutorial001_py310.py hl[4,12] *}1011You put the thing that you want to iterate over inside of Rich's `track()`, and then iterate over that.
50 unmodified lines
62```6364</div>6566You can learn more about it in the <a href="https://rich.readthedocs.io/en/stable/progress.html" class="external-link" target="_blank">Rich docs for Progress Display</a>.66You can learn more about it in the [Rich docs for Progress Display](https://rich.readthedocs.io/en/stable/progress.html).6768## Typer `progressbar`6970If you can, you should use **Rich** as explained above, it has more features, it's more advanced, and can display information more beautifully. ✨
9 unmodified lines
80### Use `typer.progressbar`8182/// tip8384Remember, you are much better off using <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a> for this. 😎84Remember, you are much better off using [Rich](https://rich.readthedocs.io/) for this. 😎8586///8788You can use `typer.progressbar()` with a `with` statement, as in:
59 unmodified lines
148### Setting a Progress Bar `length`149150/// tip151152Remember, you are much better off using <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a> for this. 😎152Remember, you are much better off using [Rich](https://rich.readthedocs.io/) for this. 😎153154///155156The progress bar is generated from the length of the iterable (e.g. the list of users).
17 unmodified lines
174</div>175176#### About the function with `yield`177178If you hadn't seen something like that `yield` above, that's a "<a href="https://docs.python.org/3/glossary.html#term-generator" class="external-link" target="_blank">generator</a>".178If you hadn't seen something like that `yield` above, that's a "[generator](https://docs.python.org/3/glossary.html#term-generator)".179180You can iterate over that function with a `for` and at each iteration it will give you the value at `yield`.181182`yield` is like a `return` that gives values multiple times and let's you use the function in a `for` loop.
15 unmodified lines
198### Add a `label`199200/// tip201202Remember, you are much better off using <a href="https://rich.readthedocs.io/" class="external-link" target="_blank">Rich</a> for this. 😎202Remember, you are much better off using [Rich](https://rich.readthedocs.io/) for this. 😎203204///205206You can also set a `label`:
26 unmodified lines
modified:docs/tutorial/prompt.md+2 added-2 removed
1# Ask with Prompt23When you need to ask the user for info interactively you should normally use [*CLI Option*s with Prompt](options/prompt.md){.internal-link target=_blank}, because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).3When you need to ask the user for info interactively you should normally use [*CLI Option*s with Prompt](options/prompt.md), because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).45But if you absolutely need to ask for interactive information without using a *CLI option*, you can use `typer.prompt()`:67{* docs_src/prompt/tutorial001_py310.py hl[8] *}
13 unmodified lines
21</div>2223## Confirm2425There's also an alternative to ask for confirmation. Again, if possible, you should use a [*CLI Option* with a confirmation prompt](options/prompt.md){.internal-link target=_blank}:25There's also an alternative to ask for confirmation. Again, if possible, you should use a [*CLI Option* with a confirmation prompt](options/prompt.md):2627{* docs_src/prompt/tutorial002_py310.py hl[8] *}2829Check it:
65 unmodified lines
modified:docs/tutorial/testing.md+3 added-3 removed
1# Testing23Testing **Typer** applications is very easy with <a href="https://docs.pytest.org/en/latest/" class="external-link" target="_blank">pytest</a>.3Testing **Typer** applications is very easy with [pytest](https://docs.pytest.org/en/latest/).45Let's say you have an application `app/main.py` with:67{* docs_src/testing/app01_py310/main.py *}
68 unmodified lines
76///7778/// note7980If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](printing.md#standard-output-and-standard-error){.internal-link target=_blank}.80If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](printing.md#standard-output-and-standard-error).8182///8384### Call `pytest`
45 unmodified lines
130This is because what you type in the terminal goes to "**standard input**" and is handled by the operating system as if it was a "virtual file".131132/// note133134If you need a refresher about what is "standard output", "standard error", and "standard input" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](printing.md#standard-output-and-standard-error){.internal-link target=_blank}.134If you need a refresher about what is "standard output", "standard error", and "standard input" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](printing.md#standard-output-and-standard-error).135136///137138When you hit the <kbd>ENTER</kbd> key after typing the email, that is just a "new line character". And in Python that is represented with `"\n"`.
76 unmodified lines
modified:docs/tutorial/typer-app.md+2 added-2 removed
27 unmodified lines
2829A "decorator" takes the function below and does something with it.3031In our case, this decorator tells **Typer** that the function below is a "`command`".32You will learn more about commands later in the section [commands](./commands/index.md){.internal-link target=_blank}.32You will learn more about commands later in the section [commands](./commands/index.md).3334///3536Both ways, with `typer.run()` and creating the explicit application, achieve almost the same.
75 unmodified lines
112Having a standalone program like that allows setting up shell/tab completion.113114The first step to be able to create an installable package like that is to use an explicit `typer.Typer()` app.115116Later you can learn all the process to create a standalone CLI application and [Build a Package](./package.md){.internal-link target=_blank}.116Later you can learn all the process to create a standalone CLI application and [Build a Package](./package.md).117118But for now, it's just good to know that you are on that path. 😎
modified:docs/alternatives.md+9 added-9 removed
8 unmodified lines
9There have been many tools created before that have helped inspire its creation.1011## Previous tools1213### <a href="https://docs.python.org/3/library/argparse.html" class="external-link" target="_blank">`argparse`</a>13### [`argparse`](https://docs.python.org/3/library/argparse.html)1415`argparse` is the Python standard library's module to write CLIs.1617It provides a better alternative than reading the *CLI Parameters* as a `list` of `str` and parsing everything by hand.
3 unmodified lines
21Provide a better development experience than just reading *CLI Parameters* by hand.2223///2425### <a href="https://hugapi.github.io/hug/" class="external-link" target="_blank">Hug</a>25### [Hug](https://hugapi.github.io/hug/)2627Hug is a library to create APIs and CLIs, it uses parameters in functions to declare the required data.2829It inspired a lot of the ideas in **FastAPI** and **Typer**.
3 unmodified lines
33Use function parameters to declare *CLI arguments* and *CLI options* as it simplifies a lot the development experience.3435///3637### <a href="https://plac.readthedocs.io/en/latest/" class="external-link" target="_blank">Plac</a>37### [Plac](https://plac.readthedocs.io/en/latest/)3839Plac is another library to create CLIs using parameters in functions, similar to Hug.4041/// tip | Inspired **Typer** to
1 unmodified line
43Provide a simple way to use a function as a command line app, without having to create a complete app, with `typer.run(some_function)`.4445///4647### <a href="https://pydantic-docs.helpmanual.io/" class="external-link" target="_blank">Pydantic</a>47### [Pydantic](https://pydantic-docs.helpmanual.io/)4849Pydantic is a library to handle data validation using standard modern Python type annotations.5051It powers **FastAPI** underneath.
5 unmodified lines
57Use standard Python type annotations to declare types instead of library-specific types or classes and use them for data validation and documentation.5859///6061### <a href="https://click.palletsprojects.com" class="external-link" target="_blank">Click</a>61### [Click](https://click.palletsprojects.com)6263Click is one of the most widely used libraries to create CLIs in Python.6465It's a very powerful tool and there are many CLIs built with it. It is what powers **Typer** underneath.
9 unmodified lines
75Everything. 🚀7677**Typer** mainly adds a layer on top of Click, making the code simpler and easier to use, with autocompletion everywhere, etc, but providing all the powerful features of Click underneath.7879As someone pointed out: <em><a href="https://twitter.com/fishnets88/status/1210126833745838080" class="external-link" target="_blank">"Nice to see it is built on Click but adds the type stuff. Me gusta!"</a></em>79As someone pointed out: <em>["Nice to see it is built on Click but adds the type stuff. Me gusta!"](https://twitter.com/fishnets88/status/1210126833745838080)</em>8081///8283### <a href="https://github.com/click-contrib/click-completion" class="external-link" target="_blank">`click-completion`</a>83### [`click-completion`](https://github.com/click-contrib/click-completion)8485`click-completion` is a plug-in for Click. It was created to extend completion support for shells when Click only had support for Bash completion.8687Previous versions of **Typer** had deep integrations with `click-completion` and used it as an optional dependency. But now all the completion logic is implemented internally in **Typer** itself, the internal logic was heavily inspired and using some parts of `click-completion`.
5 unmodified lines
93Provide auto completion for all the shells.9495///9697### <a href="https://fastapi.tiangolo.com/" class="external-link" target="_blank">FastAPI</a>97### [FastAPI](https://fastapi.tiangolo.com/)9899I created **FastAPI** to provide an easy way to build APIs with autocompletion for everything in the code (and some other <a href="https://fastapi.tiangolo.com/features/" class="external-link" target="_blank">features</a>).99I created **FastAPI** to provide an easy way to build APIs with autocompletion for everything in the code (and some other [features](https://fastapi.tiangolo.com/features/)).100101**Typer** is the "FastAPI of CLIs".102103It uses the same design and usage of FastAPI as much as possible. So, if you have used FastAPI, you know how to use Typer.
modified:docs/contributing.md+5 added-5 removed
1# Development - Contributing23First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.3First, you might want to see the basic ways to [help Typer and get help](help-typer.md).45## Developing67If you already cloned the <a href="https://github.com/fastapi/typer" class="external-link" target="_blank">typer repository</a> and you want to deep dive in the code, here are some guidelines to set up your environment.7If you already cloned the [typer repository](https://github.com/fastapi/typer) and you want to deep dive in the code, here are some guidelines to set up your environment.89### Install Requirements Using `uv`1011Create a virtual environment and install the required packages in one command:
240 unmodified lines
252#### Typer CLI (optional)253254The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly.255256But you can also use <a href="https://typer.tiangolo.com/typer-cli/" class="external-link" target="_blank">Typer CLI</a>, and you will get autocompletion in your terminal for the commands after installing completion.256But you can also use [Typer CLI](https://typer.tiangolo.com/typer-cli/), and you will get autocompletion in your terminal for the commands after installing completion.257258If you install Typer CLI, you can install completion with:259260<div class="termy">
8 unmodified lines
269</div>270271### Docs Structure272273The documentation uses <a href="https://zensical.org" class="external-link" target="_blank">Zensical</a>.273The documentation uses [Zensical](https://zensical.org).274275And there are extra tools/scripts in place in `./scripts/docs.py`.276277/// tip
37 unmodified lines
315The same applies to comments and descriptions, please don't copy paste the content generated by an LLM.316317### Human Effort Denial of Service318319Using automated tools and AI to submit PRs or comments that we have to carefully review and handle would be the equivalent of a <a href="https://en.wikipedia.org/wiki/Denial-of-service_attack" class="external-link" target="_blank">Denial-of-service attack</a> on our human effort.319Using automated tools and AI to submit PRs or comments that we have to carefully review and handle would be the equivalent of a [Denial-of-service attack](https://en.wikipedia.org/wiki/Denial-of-service_attack) on our human effort.320321It would be very little effort from the person submitting the PR (an LLM prompt) that generates a large amount of effort on our side (carefully reviewing code).322323Please don't do that.
14 unmodified lines
modified:docs/environment-variables.md+5 added-5 removed
65 unmodified lines
66```6768/// tip6970The second argument to <a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> is the default value to return.70The second argument to [`os.getenv()`](https://docs.python.org/3.8/library/os.html#os.getenv) is the default value to return.7172If not provided, it's `None` by default, here we provide `"World"` as the default value to use.7374///
79 unmodified lines
154</div>155156/// tip157158You can read more about it at <a href="https://12factor.net/config" class="external-link" target="_blank">The Twelve-Factor App: Config</a>.158You can read more about it at [The Twelve-Factor App: Config](https://12factor.net/config).159160///161162## Types and Validation
1 unmodified line
164These environment variables can only handle **text strings**, as they are external to Python and have to be compatible with other programs and the rest of the system (and even with different operating systems, as Linux, Windows, macOS).165166That means that **any value** read in Python from an environment variable **will be a `str`**, and any conversion to a different type or any validation has to be done in code.167168You will learn more about using environment variables for your <abbr title="command line interface">CLI</abbr> applications later in the section about [CLI Arguments with Environment Variables](./tutorial/arguments/envvar.md){.internal-link target=_blank}.168You will learn more about using environment variables for your <abbr title="command line interface">CLI</abbr> applications later in the section about [CLI Arguments with Environment Variables](./tutorial/arguments/envvar.md).169170## `PATH` Environment Variable171172There is a **special** environment variable called **`PATH`** that is used by the operating systems (Linux, macOS, Windows) to find programs to run.
109 unmodified lines
282</div>283284////285286This information will be useful when learning about [Virtual Environments](virtual-environments.md){.internal-link target=_blank}.286This information will be useful when learning about [Virtual Environments](virtual-environments.md).287288It will also be useful when you **create your own CLI programs** as, for them to be available for your users, they will need to be somewhere in the `PATH` environment variable.289290## Conclusion291292With this you should have a basic understanding of what **environment variables** are and how to use them in Python.293294You can also read more about them in the <a href="https://en.wikipedia.org/wiki/Environment_variable" class="external-link" target="_blank">Wikipedia for Environment Variable</a>.294You can also read more about them in the [Wikipedia for Environment Variable](https://en.wikipedia.org/wiki/Environment_variable).295296In many cases it's not very obvious how environment variables would be useful and applicable right away. But they keep showing up in many different scenarios when you are developing, so it's good to know about them.297298For example, you will need this information in the next section, about [Virtual Environments](virtual-environments.md).
modified:docs/features.md+6 added-6 removed
1# Features23## Design based on **FastAPI**45<a href="https://fastapi.tiangolo.com" target="_blank"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" style="width: 20%;"></a>5<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" style="width: 20%;"></a>67**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling.7**Typer** is [FastAPI](https://fastapi.tiangolo.com)'s little sibling.89It follows the same design and ideas. If you know **FastAPI**, you already know **Typer**... more or less.1011## Just Modern Python1213It's all based on standard **Python type** declarations. No new syntax to learn. Just standard modern Python.1415If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI or Typer), check the FastAPI tutorial section: <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">Python types intro</a>.15If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI or Typer), check the FastAPI tutorial section: [Python types intro](https://fastapi.tiangolo.com/python-types/).1617You will also see a 20 seconds refresher on the section [Tutorial - User Guide: First Steps](tutorial/first-steps.md){.internal-link target=_blank}.17You will also see a 20 seconds refresher on the section [Tutorial - User Guide: First Steps](tutorial/first-steps.md).1819## Editor support2021**Typer** was designed to be easy and intuitive to use, to ensure the best development experience. With autocompletion everywhere.
1 unmodified line
23You will rarely need to come back to the docs.2425Here's how your editor might help you:2627* in <a href="https://code.visualstudio.com/" class="external-link" target="_blank">Visual Studio Code</a>:27* in [Visual Studio Code](https://code.visualstudio.com/):2829![editor support](img/vscode-completion.png)3031* in <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">PyCharm</a>:31* in [PyCharm](https://www.jetbrains.com/pycharm/):3233![editor support](img/pycharm-completion.png)3435You will get completion for everything. That's something no other CLI library provides right now.
43 unmodified lines
modified:docs/help-typer.md+21 added-21 removed
10 unmodified lines
11And there are several ways to get help too.1213## Subscribe to the newsletter1415You can subscribe to the (infrequent) [**FastAPI and friends** newsletter](https://fastapi.tiangolo.com/newsletter/){.internal-link target=_blank} to stay updated about:15You can subscribe to the (infrequent) [**FastAPI and friends** newsletter](https://fastapi.tiangolo.com/newsletter/) to stay updated about:1617* News about FastAPI and friends, including Typer 🚀18* Guides 📝19* Features ✨
1 unmodified line
21* Tips and tricks ✅2223## Star **Typer** in GitHub2425You can "star" Typer in GitHub (clicking the star button at the top right): <a href="https://github.com/fastapi/typer" class="external-link" target="_blank">https://github.com/fastapi/typer</a>.25You can "star" Typer in GitHub (clicking the star button at the top right): [https://github.com/fastapi/typer](https://github.com/fastapi/typer).2627By adding a star, other users will be able to find it more easily and see that it has been already useful for others.2829## Watch the GitHub repository for releases3031You can "watch" Typer in GitHub (clicking the "watch" button at the top right): <a href="https://github.com/fastapi/typer" class="external-link" target="_blank">https://github.com/fastapi/typer</a>.31You can "watch" Typer in GitHub (clicking the "watch" button at the top right): [https://github.com/fastapi/typer](https://github.com/fastapi/typer).3233There you can select "Releases only".3435By doing it, you will receive notifications (in your email) whenever there's a new release (a new version) of **Typer** with bug fixes and new features.3637## Connect with the author3839You can connect with <a href="https://tiangolo.com" class="external-link" target="_blank">me (Sebastián Ramírez / `tiangolo`)</a>, the author.39You can connect with [me (Sebastián Ramírez / `tiangolo`)](https://tiangolo.com), the author.4041You can:4243* <a href="https://github.com/tiangolo" class="external-link" target="_blank">Follow me on **GitHub**</a>.43* [Follow me on **GitHub**](https://github.com/tiangolo).44 * See other Open Source projects I have created that could help you.45 * Follow me to see when I create a new Open Source project.46* <a href="https://twitter.com/tiangolo" class="external-link" target="_blank">Follow me on **Twitter**</a>.46* [Follow me on **Twitter**](https://twitter.com/tiangolo).47 * Tell me how you use Typer (I love to hear that).48 * Hear when I make announcements or release new tools.49* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">Connect with me on **Linkedin**</a>.49* [Connect with me on **Linkedin**](https://www.linkedin.com/in/tiangolo/).50 * Hear when I make announcements or release new tools (although I use Twitter more often 🤷‍♂).51* Read what I write (or follow me) on <a href="https://dev.to/tiangolo" class="external-link" target="_blank">**Dev.to**</a> or <a href="https://medium.com/@tiangolo" class="external-link" target="_blank">**Medium**</a>.51* Read what I write (or follow me) on [**Dev.to**](https://dev.to/tiangolo) or [**Medium**](https://medium.com/@tiangolo).52 * Read other ideas, articles, and read about tools I have created.53 * Follow me to read when I publish something new.5455## Tweet about **Typer**5657<a href="https://twitter.com/compose/tweet?text=I'm loving Typer because... https://github.com/fastapi/typer cc @tiangolo" class="external-link" target="_blank">Tweet about **Typer**</a> and let me and others know why you like it.57[Tweet about **Typer**](https://twitter.com/compose/tweet?text=I'm loving Typer because... https://github.com/fastapi/typer cc @tiangolo) and let me and others know why you like it.5859I love to hear about how **Typer** is being used, what have you liked in it, in which project/company you are using it, etc.6061## Help others with questions in GitHub6263You can try and help others with their questions in:6465* <a href="https://github.com/fastapi/typer/discussions/categories/questions?discussions_q=category%3AQuestions+is%3Aunanswered" class="external-link" target="_blank">GitHub Discussions</a>66* <a href="https://github.com/fastapi/typer/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Aquestion+-label%3Aanswered+" class="external-link" target="_blank">GitHub Issues</a>65* [GitHub Discussions](https://github.com/fastapi/typer/discussions/categories/questions?discussions_q=category%3AQuestions+is%3Aunanswered)66* [GitHub Issues](https://github.com/fastapi/typer/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Aquestion+-label%3Aanswered+)6768In many cases you might already know the answer for those questions. 🤓6970Just remember, the most important point is: try to be kind. People come with their frustrations and in many cases don't ask in the best way, but try as best as you can to be kind. 🤗
19 unmodified lines
90For most of the cases and most of the questions there's something related to the person's **original code**.9192In many cases they will only copy a fragment of the code, but that's not enough to **reproduce the problem**.9394* You can ask them to provide a <a href="https://stackoverflow.com/help/minimal-reproducible-example" class="external-link" target="_blank">minimal, reproducible, example</a>, that you can **copy-paste** and run locally to see the same error or behavior they are seeing, or to understand their use case better.94* You can ask them to provide a [minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example), that you can **copy-paste** and run locally to see the same error or behavior they are seeing, or to understand their use case better.9596* If you are feeling too generous, you can try to **create an example** like that yourself, just based on the description of the problem. Just have in mind that this might take a lot of time and it might be better to ask them to clarify the problem first.9798### Suggest solutions
12 unmodified lines
111 * In GitHub Issues: **close** the issue**.112113## Watch the GitHub repository114115You can "watch" Typer in GitHub (clicking the "watch" button at the top right): <a href="https://github.com/fastapi/typer" class="external-link" target="_blank">https://github.com/fastapi/typer</a>.115You can "watch" Typer in GitHub (clicking the "watch" button at the top right): [https://github.com/fastapi/typer](https://github.com/fastapi/typer).116117If you select "Watching" instead of "Releases only" you will receive notifications when someone creates a new issue or question. You can also specify that you only want to be notified about new issues, or discussions, or PRs, etc.118119Then you can try and help them solve those questions.120121## Ask Questions122123You can <a href="https://github.com/fastapi/typer/discussions/new?category=questions" class="external-link" target="_blank">create a new question</a> in the GitHub repository, for example to:123You can [create a new question](https://github.com/fastapi/typer/discussions/new?category=questions) in the GitHub repository, for example to:124125* Ask a **question** or ask about a **problem**.126* Suggest a new **feature**.127
54 unmodified lines
182* Then also comment what you tried, that way I'll know that you checked it. 🤓183184## Create a Pull Request185186You can [contribute](contributing.md){.internal-link target=_blank} to the source code with Pull Requests, for example:186You can [contribute](contributing.md) to the source code with Pull Requests, for example:187188* To fix a typo you found on the documentation.189* To propose new documentation sections.190* To fix an existing issue/bug.
12 unmodified lines
203There's a lot of work to do, and for most of it, **YOU** can do it.204205The main tasks that you can do right now are:206207* [Help others with questions in GitHub](#help-others-with-questions-in-github){.internal-link target=_blank} (see the section above).208* [Review Pull Requests](#review-pull-requests){.internal-link target=_blank} (see the section above).207* [Help others with questions in GitHub](#help-others-with-questions-in-github) (see the section above).208* [Review Pull Requests](#review-pull-requests) (see the section above).209210Those two tasks are what **consume time the most**. That's the main work of maintaining Typer.211212If you can help me with that, **you are helping me maintain Typer** and making sure it keeps **advancing faster and better**. 🚀213214## Join the chat215216Join the 👥 <a href="https://discord.gg/VQjSZaeJmf" class="external-link" target="_blank">FastAPI and Friends Discord chat server</a> 👥 and hang out with others in the community. There's a `#typer` channel.216Join the 👥 [FastAPI and Friends Discord chat server](https://discord.gg/VQjSZaeJmf) 👥 and hang out with others in the community. There's a `#typer` channel.217218/// tip219220For questions, ask them in <a href="https://github.com/fastapi/typer/discussions/new?category=questions" class="external-link" target="_blank">GitHub Discussions</a>, there's a much better chance you will receive help there.220For questions, ask them in [GitHub Discussions](https://github.com/fastapi/typer/discussions/new?category=questions), there's a much better chance you will receive help there.221222Use the chat only for other general conversations.223224///
9 unmodified lines
234On the other side, there are thousands of users in the chat, so there's a high chance you'll find someone to talk to there, almost all the time. 😄235236## Sponsor the author237238You can also financially support the author (me) through <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub sponsors</a>.238You can also financially support the author (me) through [GitHub sponsors](https://github.com/sponsors/tiangolo).239240There you could buy me a coffee ☕️ to say thanks. 😄241242## Sponsor the tools that power Typer
1 unmodified line
244As you have seen in the documentation, Typer is built on top of Click.245246You can also sponsor:247248* Pallets Project (Click maintainers) <a href="https://palletsprojects.com/donate" class="external-link" target="_blank">via the PSF</a> or <a href="https://tidelift.com/subscription/pkg/pypi-click" class="external-link" target="_blank">via Tidelift</a>248* Pallets Project (Click maintainers) [via the PSF](https://palletsprojects.com/donate) or [via Tidelift](https://tidelift.com/subscription/pkg/pypi-click)249250---251252Thanks! 🚀
modified:docs/index.md+11 added-11 removed
12 unmodified lines
13<p align="center">14 <em>Typer, build great CLIs. Easy to code. Based on Python type hints.</em>15</p>16<p align="center">17<a href="https://github.com/fastapi/typer/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster" target="_blank">17<a href="https://github.com/fastapi/typer/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster">18 <img src="https://github.com/fastapi/typer/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test">19</a>20<a href="https://github.com/fastapi/typer/actions?query=workflow%3APublish" target="_blank">20<a href="https://github.com/fastapi/typer/actions?query=workflow%3APublish">21 <img src="https://github.com/fastapi/typer/workflows/Publish/badge.svg" alt="Publish">22</a>23<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/typer" target="_blank">23<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/typer">24 <img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/typer.svg" alt="Coverage">25<a href="https://pypi.org/project/typer" target="_blank">25<a href="https://pypi.org/project/typer">26 <img src="https://img.shields.io/pypi/v/typer?color=%2334D058&label=pypi%20package" alt="Package version">27</a>28</p>2930---3132**Documentation**: <a href="https://typer.tiangolo.com" target="_blank">https://typer.tiangolo.com</a>32**Documentation**: [https://typer.tiangolo.com](https://typer.tiangolo.com)3334**Source Code**: <a href="https://github.com/fastapi/typer" target="_blank">https://github.com/fastapi/typer</a>34**Source Code**: [https://github.com/fastapi/typer](https://github.com/fastapi/typer)3536---3738Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python type hints.
10 unmodified lines
49* **Run scripts**: Typer includes a `typer` command/program that you can use to run scripts, automatically converting them to CLIs, even if they don't use Typer internally.5051## FastAPI of CLIs5253**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling, it's the FastAPI of CLIs.53**Typer** is [FastAPI](https://fastapi.tiangolo.com)'s little sibling, it's the FastAPI of CLIs.5455## Installation5657Create and activate a <a href="https://typer.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a> and then install **Typer**:57Create and activate a [virtual environment](https://typer.tiangolo.com/virtual-environments/) and then install **Typer**:5859<div class="termy">6061```console
299 unmodified lines
361## Dependencies362363**Typer** stands on the shoulders of giants. It has three required dependencies:364365* <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a>: a popular tool for building CLIs in Python. Typer is based on it.366* <a href="https://rich.readthedocs.io/en/stable/index.html" class="external-link" target="_blank"><code>rich</code></a>: to show nicely formatted errors automatically.367* <a href="https://github.com/sarugaku/shellingham" class="external-link" target="_blank"><code>shellingham</code></a>: to automatically detect the current shell when installing completion.365* [Click](https://click.palletsprojects.com/): a popular tool for building CLIs in Python. Typer is based on it.366* [`rich`](https://rich.readthedocs.io/en/stable/index.html): to show nicely formatted errors automatically.367* [`shellingham`](https://github.com/sarugaku/shellingham): to automatically detect the current shell when installing completion.368369### `typer-slim`370371There used to be a slimmed-down version of Typer called `typer-slim`, which didn't include the dependencies `rich` and `shellingham`, nor the `typer` command.
8 unmodified lines
modified:docs/management-tasks.md+8 added-8 removed
1# Repository Management Tasks23These are the tasks that can be performed to manage the Typer repository by [team members](./management.md#team){.internal-link target=_blank}.3These are the tasks that can be performed to manage the Typer repository by [team members](./management.md#team).45/// tip67This section is useful only to a handful of people, team members with permissions to manage the repository. You can probably skip it. 😉89///1011...so, you are a [team member of Typer](./management.md#team){.internal-link target=_blank}? Wow, you are so cool! 😎11...so, you are a [team member of Typer](./management.md#team)? Wow, you are so cool! 😎1213You can help with everything on [Help Typer - Get Help](./help-typer.md){.internal-link target=_blank} the same ways as external contributors. But additionally, there are some tasks that only you (as part of the team) can perform.13You can help with everything on [Help Typer - Get Help](./help-typer.md) the same ways as external contributors. But additionally, there are some tasks that only you (as part of the team) can perform.1415Here are the general instructions for the tasks you can perform.1617Thanks a lot for your help. 🙇
21 unmodified lines
39For conversations that are more difficult, for example to reject a PR, you can ask me (@tiangolo) to handle it directly.4041## Edit PR Titles4243* Edit the PR title to start with an emoji from <a href="https://gitmoji.dev/" class="external-link" target="_blank">gitmoji</a>.43* Edit the PR title to start with an emoji from [gitmoji](https://gitmoji.dev/).44 * Use the emoji character, not the GitHub code. So, use `🐛` instead of `:bug:`. This is so that it shows up correctly outside of GitHub, for example in the release notes.45* Start the title with a verb. For example `Add`, `Refactor`, `Fix`, etc. This way the title will say the action that the PR does. Like `Add support for teleporting`, instead of `Teleporting wasn't working, so this PR fixes it`.46* Edit the text of the PR title to start in "imperative", like giving an order. So, instead of `Adding support for teleporting` use `Add support for teleporting`.47* Try to make the title descriptive about what it achieves. If it's a feature, try to describe it, for example `Add support for teleporting` instead of `Create TeleportAdapter class`.48* Do not finish the title with a period (`.`).4950Once the PR is merged, a GitHub Action (<a href="https://github.com/tiangolo/latest-changes" class="external-link" target="_blank">latest-changes</a>) will use the PR title to update the latest changes automatically.50Once the PR is merged, a GitHub Action ([latest-changes](https://github.com/tiangolo/latest-changes)) will use the PR title to update the latest changes automatically.5152So, having a nice PR title will not only look nice in GitHub, but also in the release notes. 📝5354## Add Labels to PRs5556The same GitHub Action <a href="https://github.com/tiangolo/latest-changes" class="external-link" target="_blank">latest-changes</a> uses one label in the PR to decide the section in the release notes to put this PR in.56The same GitHub Action [latest-changes](https://github.com/tiangolo/latest-changes) uses one label in the PR to decide the section in the release notes to put this PR in.5758Make sure you use a supported label from the <a href="https://github.com/tiangolo/latest-changes#using-labels" class="external-link" target="_blank">latest-changes list of labels</a>:58Make sure you use a supported label from the [latest-changes list of labels](https://github.com/tiangolo/latest-changes#using-labels):5960* `breaking`: Breaking Changes61 * Existing code will break if they update the version without changing their code. This rarely happens, so this label is not frequently used.62* `security`: Security Fixes
50 unmodified lines
113## Mark GitHub Discussions Answers114115When a question in GitHub Discussions has been answered, mark the answer by clicking "Mark as answer".116117You can filter discussions by <a href="https://github.com/fastapi/typer/discussions/categories/questions?discussions_q=category:Questions+is:open+is:unanswered" class="external-link" target="_blank">`Questions` that are `Unanswered`</a>.117You can filter discussions by [`Questions` that are `Unanswered`](https://github.com/fastapi/typer/discussions/categories/questions?discussions_q=category:Questions+is:open+is:unanswered).
modified:docs/management.md+5 added-5 removed
7 unmodified lines
8Here's a short description of how the Typer repository is managed and maintained.910## Owner1112I, <a href="https://github.com/tiangolo" target="_blank">@tiangolo</a>, am the creator and owner of the Typer repository. 🤓12I, [@tiangolo](https://github.com/tiangolo), am the creator and owner of the Typer repository. 🤓1314I normally give the final review to each PR before merging them. I make the final decisions on the project, I'm the <a href="https://en.wikipedia.org/wiki/Benevolent_dictator_for_life" class="external-link" target="_blank"><abbr title="Benevolent Dictator For Life">BDFL</abbr></a>. 😅14I normally give the final review to each PR before merging them. I make the final decisions on the project, I'm the [<abbr title="Benevolent Dictator For Life">BDFL</abbr>](https://en.wikipedia.org/wiki/Benevolent_dictator_for_life). 😅1516## Team1718There's a team of people that help manage and maintain the project. 😎1920They have different levels of permissions and [specific instructions](./management-tasks.md){.internal-link target=_blank}.20They have different levels of permissions and [specific instructions](./management-tasks.md).2122Some of the tasks they can perform include:2324* Adding labels to PRs.
10 unmodified lines
3536<div class="user-list user-list-center">37{% for user in members %}3839<div class="user"><a href="https://github.com/{{ user.login }}" target="_blank"><div class="avatar-wrapper"><img src="https://github.com/{{ user.login }}.png"/></div><div class="title">@{{ user.login }}</div></a></div>39<div class="user"><a href="https://github.com/{{ user.login }}"><div class="avatar-wrapper"><img src="https://github.com/{{ user.login }}.png"/></div><div class="title">@{{ user.login }}</div></a></div>40{% endfor %}4142</div>43
2 unmodified lines
46## External Contributions4748External contributions are very welcome and appreciated, including answering questions, submitting PRs, etc. 🙇‍♂️4950There are many ways to [help maintain Typer](./help-typer.md){.internal-link target=_blank}.50There are many ways to [help maintain Typer](./help-typer.md).
modified:docs/virtual-environments.md+15 added-15 removed
20 unmodified lines
21/// note2223This page will teach you how to use **virtual environments** and how they work.2425If you are ready to adopt a **tool that manages everything** for you (including installing Python), try <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">uv</a>.25If you are ready to adopt a **tool that manages everything** for you (including installing Python), try [uv](https://github.com/astral-sh/uv).2627///2829## Create a Project
55 unmodified lines
85////8687//// tab | `uv`8889If you have <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a> installed, you can use it to create a virtual environment.89If you have [`uv`](https://github.com/astral-sh/uv) installed, you can use it to create a virtual environment.9091<div class="termy">9293```console
55 unmodified lines
149////150151//// tab | Windows Bash152153Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):153Or if you use Bash for Windows (e.g. [Git Bash](https://gitforwindows.org/)):154155<div class="termy">156157```console
57 unmodified lines
215## Upgrade `pip`216217/// tip218219If you use <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a> you would use it to install things instead of `pip`, so you don't need to upgrade `pip`. 😎219If you use [`uv`](https://github.com/astral-sh/uv) you would use it to install things instead of `pip`, so you don't need to upgrade `pip`. 😎220221///222223If you are using `pip` to install packages (it comes by default with Python), you should **upgrade** it to the latest version.
23 unmodified lines
247If you are using **Git** (you should), add a `.gitignore` file to exclude everything in your `.venv` from Git.248249/// tip250251If you used <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a> to create the virtual environment, it already did this for you, you can skip this step. 😎251If you used [`uv`](https://github.com/astral-sh/uv) to create the virtual environment, it already did this for you, you can skip this step. 😎252253///254255/// tip
63 unmodified lines
319////320321//// tab | `uv`322323If you have <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a>:323If you have [`uv`](https://github.com/astral-sh/uv):324325<div class="termy">326327```console
23 unmodified lines
351////352353//// tab | `uv`354355If you have <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a>:355If you have [`uv`](https://github.com/astral-sh/uv):356357<div class="termy">358359```console
35 unmodified lines
395You would probably use an editor, make sure you configure it to use the same virtual environment you created (it will probably autodetect it) so that you can get autocompletion and inline errors.396397For example:398399* <a href="https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment" class="external-link" target="_blank">VS Code</a>400* <a href="https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html" class="external-link" target="_blank">PyCharm</a>399* [VS Code](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment)400* [PyCharm](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html)401402/// tip403404You normally have to do this only **once**, when you create the virtual environment.
29 unmodified lines
434///435436## Why Virtual Environments437438To work with Typer you need to install <a href="https://www.python.org/" class="external-link" target="_blank">Python</a>.438To work with Typer you need to install [Python](https://www.python.org/).439440After that, you would need to **install** Typer and any other **packages** you want to use.441442To install packages you would normally use the `pip` command that comes with Python (or similar alternatives).
100 unmodified lines
543```544545</div>546547That will download a compressed file with the Typer code, normally from <a href="https://pypi.org/project/typer/" class="external-link" target="_blank">PyPI</a>.547That will download a compressed file with the Typer code, normally from [PyPI](https://pypi.org/project/typer/).548549It will also **download** files for other packages that Typer depends on.550551Then it will **extract** all those files and put them in a directory in your computer.
54 unmodified lines
606////607608//// tab | Windows Bash609610Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):610Or if you use Bash for Windows (e.g. [Git Bash](https://gitforwindows.org/)):611612<div class="termy">613614```console
3 unmodified lines
618</div>619620////621622That command will create or modify some [environment variables](environment-variables.md){.internal-link target=_blank} that will be available for the next commands.622That command will create or modify some [environment variables](environment-variables.md) that will be available for the next commands.623624One of those variables is the `PATH` variable.625626/// tip627628You can learn more about the `PATH` environment variable in the [Environment Variables](environment-variables.md#path-environment-variable){.internal-link target=_blank} section.628You can learn more about the `PATH` environment variable in the [Environment Variables](environment-variables.md#path-environment-variable) section.629630///631632Activating a virtual environment adds its path `.venv/bin` (on Linux and macOS) or `.venv\Scripts` (on Windows) to the `PATH` environment variable.
192 unmodified lines
825This is a simple guide to get you started and teach you how everything works **underneath**.826827There are many **alternatives** to managing virtual environments, package dependencies (requirements), projects.828829Once you are ready and want to use a tool to **manage the entire project**, packages dependencies, virtual environments, etc. I would suggest you try <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">uv</a>.829Once you are ready and want to use a tool to **manage the entire project**, packages dependencies, virtual environments, etc. I would suggest you try [uv](https://github.com/astral-sh/uv).830831`uv` can do a lot of things, it can:832833* **Install Python** for you, including different versions
11 unmodified lines
modified:README.md+11 added-11 removed
4 unmodified lines
5<p align="center">6 <em>Typer, build great CLIs. Easy to code. Based on Python type hints.</em>7</p>8<p align="center">9<a href="https://github.com/fastapi/typer/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster" target="_blank">9<a href="https://github.com/fastapi/typer/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster">10 <img src="https://github.com/fastapi/typer/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test">11</a>12<a href="https://github.com/fastapi/typer/actions?query=workflow%3APublish" target="_blank">12<a href="https://github.com/fastapi/typer/actions?query=workflow%3APublish">13 <img src="https://github.com/fastapi/typer/workflows/Publish/badge.svg" alt="Publish">14</a>15<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/typer" target="_blank">15<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/typer">16 <img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/typer.svg" alt="Coverage">17<a href="https://pypi.org/project/typer" target="_blank">17<a href="https://pypi.org/project/typer">18 <img src="https://img.shields.io/pypi/v/typer?color=%2334D058&label=pypi%20package" alt="Package version">19</a>20</p>2122---2324**Documentation**: <a href="https://typer.tiangolo.com" target="_blank">https://typer.tiangolo.com</a>24**Documentation**: [https://typer.tiangolo.com](https://typer.tiangolo.com)2526**Source Code**: <a href="https://github.com/fastapi/typer" target="_blank">https://github.com/fastapi/typer</a>26**Source Code**: [https://github.com/fastapi/typer](https://github.com/fastapi/typer)2728---2930Typer is a library for building <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will **love using** and developers will **love creating**. Based on Python type hints.
10 unmodified lines
41* **Run scripts**: Typer includes a `typer` command/program that you can use to run scripts, automatically converting them to CLIs, even if they don't use Typer internally.4243## FastAPI of CLIs4445**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling, it's the FastAPI of CLIs.45**Typer** is [FastAPI](https://fastapi.tiangolo.com)'s little sibling, it's the FastAPI of CLIs.4647## Installation4849Create and activate a <a href="https://typer.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a> and then install **Typer**:49Create and activate a [virtual environment](https://typer.tiangolo.com/virtual-environments/) and then install **Typer**:5051<div class="termy">5253```console
299 unmodified lines
353## Dependencies354355**Typer** stands on the shoulders of giants. It has three required dependencies:356357* <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a>: a popular tool for building CLIs in Python. Typer is based on it.358* <a href="https://rich.readthedocs.io/en/stable/index.html" class="external-link" target="_blank"><code>rich</code></a>: to show nicely formatted errors automatically.359* <a href="https://github.com/sarugaku/shellingham" class="external-link" target="_blank"><code>shellingham</code></a>: to automatically detect the current shell when installing completion.357* [Click](https://click.palletsprojects.com/): a popular tool for building CLIs in Python. Typer is based on it.358* [`rich`](https://rich.readthedocs.io/en/stable/index.html): to show nicely formatted errors automatically.359* [`shellingham`](https://github.com/sarugaku/shellingham): to automatically detect the current shell when installing completion.360361### `typer-slim`362363There used to be a slimmed-down version of Typer called `typer-slim`, which didn't include the dependencies `rich` and `shellingham`, nor the `typer` command.
8 unmodified lines