Skip to content

Conversation

@svlandeg
Copy link
Member

@svlandeg svlandeg commented Nov 21, 2025

In an attempt to be minimal/clear, the docs have mostly been using typer.run. However for proper applications, we recommend to use Typer() directly, which unlocks much more options. As such, we're updating the docs here. This has the added advantage that it's easier to experiment with given tutorial examples without first having to adjust them to use Typer().

I know reviewing this is horrible. I've taken the time to go through every edit carefully (0% vibe coding ;-)). Mostly, this meant updating the tutorial examples and then updating the highlighted lines in the documentation markdown files. There were some special cases, that I'll highlight as review comments.

@svlandeg svlandeg self-assigned this Nov 21, 2025
@github-actions github-actions bot added the docs Improvements or additions to documentation label Nov 21, 2025
Comment on lines +42 to +46
{* docs_src/arguments/optional/tutorial000.py hl[4] *}

{* docs_src/arguments/optional/tutorial001_an.py hl[5] *}
Or, using an explicit `Typer()` instance creation:

{* docs_src/arguments/optional/tutorial001_an.py hl[8] *}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I've created a new tutorial file (docs_src/arguments/optional/tutorial000.py) to better show the difference with the more simplistic docs_src/first_steps/tutorial002.py. The next version then (docs_src/arguments/optional/tutorial001_an.py) introduces both Annotated as well as Typer().

{* docs_src/arguments/optional/tutorial003.py hl[7] *}

And the same way, you can make it optional by passing a different `default` value, for example `None`:
And the same way, you can make it optional by passing a different `default` value, for example `"World"`:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, and in the lines below, I've had to make extra edits, because this section had become out-of-date on master after PR #983. Basically in PR 983 we updated tutorial002 to have the default value "World" instead of None, and we updated the explanation around L112 but didn't notice that this same example was being used here at the end of the page at L220 and beyond.


Here I'll use **CLI application** or **program** to refer to the program you are building in Python with Typer, and **command** to refer to one of these "subcommands" of your program.

## Explicit application
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is moved almost verbatim to typer-instance.md, with some minor edits to ensure correct flow.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 21, 2025

📝 Docs preview

Last commit 07dc0f7 at: https://318880fe.typertiangolo.pages.dev

Modified Pages

@@ -0,0 +1,116 @@
## Explicit application
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, the title of this page is "Typer instance" - we should decide whether this is what we want, or something else.

<font color="#F92672">│</font> 7 <font color="#F92672">│</font>
<font color="#F92672">│</font> 8 <font color="#66D9EF">if</font> <font color="#F92672">__name__</font> == <font color="#F4BF75">&quot;__main__&quot;</font>: <font color="#F92672">│</font>
<font color="#F92672">│</font> 5 <font color="#F92672">│</font>
<font color="#F92672">│</font> 6 <font color="#FF00FF">@app</font>.command() <font color="#F92672">│</font>
Copy link
Member Author

@svlandeg svlandeg Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: outline this correctly 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant