Quickstart¶
This page builds a small todo tracker, todo-axi, one piece at a time, all in a single file,
todo.py. Each step adds a little code and shows what an agent sees when it runs the result.
By the end you will have a working command-line tool with a home view, a list, a detail view,
help text and clear errors.
1. Create the file¶
Start todo.py with this header:
# /// script
# requires-python = ">=3.10"
# dependencies = ["fastaxi"]
# ///
The header is
inline script metadata:
it lists what the script needs, so there is no project to set up. uv run todo.py reads it and
runs the script with fastaxi available, installing it the first time.
Steps 2 to 6 add the rest of the file, in order.
2. Create the app¶
from fastaxi import AXI
app = AXI(
"todo-axi",
description="Track todos for the current project",
version="0.1.0",
)
AXI is the tool itself. Its name is what users type once the tool is installed (todo-axi),
the description appears at the top of --help, and the version is printed by --version.
Every command you add in the next steps is registered on app.
The last lines of the file run the app. Keep them at the bottom as you add the steps below:
if __name__ == "__main__":
app.run()
app.run() reads the command line, runs the matching command and exits with its status code.
3. Describe what a todo looks like¶
Commands return ordinary Python objects; fastaxi turns them into output. Here a todo is a Pydantic model:
from typing import Annotated
from pydantic import BaseModel
from fastaxi import Default, Truncate
class Todo(BaseModel):
id: Annotated[int, Default]
title: Annotated[str, Default]
status: Annotated[str, Default]
assignee: str | None = None
body: Annotated[str, Truncate(60)] = ""
The Annotated[...] markers tell fastaxi how to show each field:
Defaultmarks the fields a list shows unless the agent asks for others. Lists stay narrow, which saves the agent tokens; the other fields are still a--fieldsflag away.Truncate(60)cuts long text to 60 characters, so one longbodycannot flood the output. fastaxi says when it cut something, and how to get the full text.
Without any markers, fastaxi still picks sensible default fields itself (an id, a title, a status). The markers just make the choice explicit.
Some sample data to work with:
TODOS = [
Todo(id=41, title="Fix login redirect", status="open", assignee="alice"),
Todo(
id=42,
title="Write the docs",
status="open",
assignee="bob",
body="Cover the quickstart, the --fields flag and CSV output, "
"then add a short FAQ.",
),
Todo(id=40, title="Set up CI", status="done", assignee="bob"),
]
4. Add a list command¶
@app.command(
name="list",
next_steps=["{bin} view <id>"],
empty="no todos match",
)
def list_todos(status: str = "open", assignee: str | None = None) -> list[Todo]:
"""List todos.
Args:
status: Filter by status.
assignee: Filter by assignee login.
Examples:
{bin} list --status done
{bin} list --assignee alice --fields id,title
"""
return [
t
for t in TODOS
if t.status == status and assignee in (None, t.assignee)
]
This is an ordinary function, and fastaxi reads everything it needs from it:
- The parameters become flags. A parameter with a default is a flag (
--status,--assignee); one without a default would be a positional argument. Values are converted and checked with Pydantic, so anintparameter rejectsabcwith a clear error. - The docstring becomes the help text. The first line is the command's summary,
Args:describes each flag, andExamples:lists example commands.{bin}is replaced with the tool's name. - The return type decides the output. A list of flat records, like
list[Todo], is printed as CSV. next_stepssuggests what to run next, andemptyis the message for an empty result. Both help an agent move on without guessing.
Running it:
$ uv run todo.py list
id,title,status
41,Fix login redirect,open
42,Write the docs,open
count: 2 of 2 total
help[1]: todo-axi view <id>
The rows go to stdout as CSV, so an agent can pipe them through grep or cut. The count and
the suggested next command go to stderr. Suggestions use the tool's name, todo-axi: that is
how the tool is called once it is installed, in step 7.
Only the Default fields are shown; --fields all adds the rest, cutting the long body:
$ uv run todo.py list --fields all
id,title,status,assignee,body
41,Fix login redirect,open,alice,
42,Write the docs,open,bob,"Cover the quickstart, the --fields flag and CSV output, then…"
count: 2 of 2 total
help[2]: todo-axi view <id>,todo-axi list --fields all --full
An empty result says so explicitly, and still exits 0:
$ uv run todo.py list --assignee carol
result: no todos match
The help text was built from the function:
$ uv run todo.py list --help
todo-axi list - List todos.
usage: todo-axi list [flags]
flags:
--status <status> Filter by status (default: open)
--assignee <assignee> Filter by assignee login
--fields <a,b,...|all> Fields to show (default: id,title,status)
--format <csv|toon> Output format (default: csv)
--full Show long text without truncation
available fields: id,title,status,assignee,body
examples:
todo-axi list --status done
todo-axi list --assignee alice --fields id,title
You only wrote --status and --assignee. fastaxi added --fields and --format because the
command returns a list of records, and --full because body can be truncated.
5. Add a detail view¶
from fastaxi import AxiError
@app.command()
def view(id: int) -> Todo:
"""Show one todo.
Args:
id: Todo id.
"""
for todo in TODOS:
if todo.id == id:
return todo
raise AxiError(f"todo {id} not found", help=["todo-axi list"])
id has no default, so it is a positional argument: todo.py view 42. The command returns
one Todo, so the output is a detail view in TOON, a compact,
readable format, with every field:
$ uv run todo.py view 42
id: 42
title: Write the docs
status: open
assignee: bob
body: "Cover the quickstart, the --fields flag and CSV output, then… (60 of 77 chars)"
help[1]: todo-axi view 42 --full
The cut body says how much of it is shown, and fastaxi suggests the same command with
--full to see the rest.
AxiError is how a command reports an expected failure. The message is printed on stdout
together with help, so the agent knows what to try instead, and the tool exits with code 1:
$ uv run todo.py view 99
error: todo 99 not found
help[1]: todo-axi list
Mistakes in how the tool is called exit with code 2, and fastaxi explains them without any code from you:
$ uv run todo.py view
error: missing required argument <id>
hint: "usage: todo-axi view <id> [flags]"
$ uv run todo.py list --stauts done
error: unknown flag --stauts
hint: did you mean --status?
flags[5]: "--status","--assignee","--fields","--format","--full"
Any other exception in a command is reported as error: internal error (TypeName), without
leaking its details. Run with AXI_DEBUG=1 to see the traceback.
6. Add a home view¶
@app.home(next_steps=["{bin} view <id>"])
def home() -> list[Todo]:
"""Open todos."""
return [t for t in TODOS if t.status == "open"]
The home view is what the tool shows when it runs with no arguments. Instead of a usage page, the agent gets current state straight away:
$ uv run todo.py
bin: todo.py
description: Track todos for the current project
count: 2 of 2 total
todos[2]{id,title,status}:
41,Fix login redirect,open
42,Write the docs,open
help[1]: todo-axi view <id>
The home view is always TOON. It starts with bin:, the program that ran, so an agent knows
exactly what to call, then the description. It is also what
session hooks show an agent when a session starts.
That is the whole tool. Every command is in place, so --help lists them:
$ uv run todo.py --help
todo-axi - Track todos for the current project
usage: todo-axi <command> [flags]
commands:
list List todos.
view Show one todo.
setup Connect this tool to coding agents (session hooks, skill)
flags:
--help, -h Show help
--version, -v, -V Show version
Run `todo-axi` with no arguments for a live overview.
Run `todo-axi <command> --help` for a command's flags.
You did not write setup: every AXI gets it, to connect the tool to coding agents.
7. Install it¶
uv run todo.py is convenient while you build. To use todo-axi as an ordinary command, the
way an agent will, install it. setup hooks also needs this: session hooks run an installed
command, not a .py file.
Add a pyproject.toml next to todo.py. The script entry points the todo-axi command at
app.run in todo.py, and only-include packages just that file:
[project]
name = "todo-axi"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["fastaxi"]
[project.scripts]
todo-axi = "todo:app.run"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
only-include = ["todo.py"]
Then install it from the same folder:
uv tool install .
This puts todo-axi on your PATH, so it works from any folder, and its suggestions now match
how it is called:
$ todo-axi list
id,title,status
41,Fix login redirect,open
42,Write the docs,open
count: 2 of 2 total
help[1]: todo-axi view <id>
After changing todo.py, run uv tool install . --reinstall to update the installed copy.
Next steps¶
- Building AXIs: other return types, totals and summaries, argument types, groups and async commands.
- Connecting to coding agents: install session hooks and an Agent Skill
with
todo-axi setup. - Agent-framework tools: hand the same commands to PydanticAI, LangChain or the OpenAI Agents SDK.
- Testing: run the tool from pytest.
A fuller version of this tool, split into modules, with dates, comments, a create command and tests, lives in examples/todo_axi.