Migrating From Typer
Much of Cyclopts's syntax is Typer-inspired. Migrating from Typer should be pretty straightforward; it is recommended to first read the Getting Started and Commands sections. The below table offers a jumping off point for translating the various portions of the APIs. The Typer Comparison page also provides many examples comparing the APIs.
Typer |
Cyclopts |
Notes |
---|---|---|
|
|
|
|
In Cyclopts, |
|
|
|
Sub applications and commands are registered the same way in Cyclopts. |
|
Typer's callback always executes before executing an app.
If used to provide functionality when no command was specified from the CLI, then use |
|
|
In Cyclopts, Positional/Keyword arguments are determined from the function signature.
Some of Typer's validation fields, like |
Cyclopts and Typer mostly handle type-hints the same way, but there are a few notable exceptions:
Type Annotation |
Notes |
---|---|
Compared to Typer, Cyclopts handles |
|
Typer does not support type unions. Cyclopts does. |
|
|
When no CLI argument is specified, Typer passes in an empty list |
General Steps
Add the following import:
from cyclopts import App, Parameter
.Change
app = Typer(...)
to justapp = App()
. Revisit more advanced configuration later.Remove all
@app.callback
stuff. Cyclopts already provides a good--version
handler for you.Replace all
Annotated[..., Argument/Option]
type-hints withAnnotated[..., Parameter()]
. If only supplying ahelp
string, it's better to supply it via docstring.Cyclopts has similar boolean-flag handling as Typer, but has different configuration parameters.
######### # Typer # ######### # Overriding the name results in no "False" flag generation. my_flag: Annotated[bool, Option("--my-custom-flag")] # However, it can be custom specified: my_flag: Annotated[bool, Option("--my-custom-flag/--disable-my-custom-flag")] ############ # Cyclopts # ############ # Overriding the name still results in "False" flag generation: # --my-custom-flag --no-my-custom-flag my_flag: Annotated[bool, Parameter("--my-custom-flag")] # Negative flag generation can be disabled: # --my-custom-flag my_flag: Annotated[bool, Parameter("--my-custom-flag", negative="")] # Or the prefix can be changed: # --my-custom-flag --disable-my-custom-flag my_flag: Annotated[bool, Parameter("--my-custom-flag", negative_bool="--disable-")]
After the basic migration is done, it is recommended to read through the rest of Cyclopts's documentation to learn about some of the better functionality it has, which could result in cleaner, terser code.