API reference¶
This page is generated from the package's docstrings with mkdocstrings. Update the source code, not this page, when the API changes.
The CLI's user-facing interface is the wt command itself — see
Usage for the command reference. This page covers the Python
modules behind it.
CLI¶
The root Typer application, the api command group, and the cli() entry
point handling delegation:
appify(fn)
¶
Map WgtlError to a stderr message + exit code; forward RFC 7807 body.
Source code in src/wagtail_cli/cli/main.py
cli()
¶
Console entry point: route known groups/globals to Typer, delegate the rest.
Source code in src/wagtail_cli/cli/main.py
emit(ctx, data)
¶
Render data (or a dry-run request preview) to stdout.
Source code in src/wagtail_cli/cli/main.py
get_cli_context(ctx)
¶
Return the root CLI context from a nested command context.
Source code in src/wagtail_cli/cli/main.py
get_client(ctx)
¶
Build a configured WgtlClient from global options + config cascade.
Source code in src/wagtail_cli/cli/main.py
main(version=typer.Option(False, '--version', callback=_version_callback, is_eager=True, help='Show version and exit.'), url=typer.Option(None, '--url', help='API base URL (overrides config/env).'), token=typer.Option(None, '--token', help='API token (overrides config/env).'), json=typer.Option(False, '--json', help='Force JSON output.'), human=typer.Option(False, '--human', help='Force human-readable output.'), verbose=typer.Option(False, '-v', '--verbose', help='Print HTTP request/response details to stderr.'), dry_run=typer.Option(False, '--dry-run', help='Print the HTTP request that would be sent without sending it.'), select=typer.Option(None, '--select', help='Return only these response fields (comma-separated or repeatable; supports dot paths).'), ctx=typer.Context)
¶
CLI client for the Wagtail v3 API.
Source code in src/wagtail_cli/cli/main.py
resolve_delegate(args)
¶
Resolve the command to run for a delegated invocation.
Returns the argv to run, or None when there is nothing to delegate to. The project's own interpreter is preferred so that an isolated install of wt (uv tool, pipx) runs manage.py with the environment holding Django.
Source code in src/wagtail_cli/cli/main.py
resolve_output_format(ctx, local_format=None)
¶
Resolve a local format before falling back to global CLI options.
Source code in src/wagtail_cli/cli/main.py
start(name=typer.Argument(..., help='Name of the application or project.'), directory=typer.Argument(None, help='Optional destination directory, created if needed.'), template=typer.Option(DEFAULT_PROJECT_TEMPLATE, '--template', help='The path or URL to load the template from.'), extension=typer.Option(['html', 'rst'], '--extension', '-e', help='File extension(s) to render (repeatable).'), name_files=typer.Option(['Dockerfile'], '--name', '-n', help='File name(s) to render (repeatable).'), exclude=typer.Option([], '--exclude', '-x', help='Directory name(s) to exclude (repeatable).'), verbosity=typer.Option(1, '-v', '--verbosity', min=0, max=3, help='Verbosity level 0-3.'), settings=typer.Option(None, '--settings', help='Python path to settings module.'), pythonpath=typer.Option(None, '--pythonpath', help='Directory to add to PYTHONPATH.'), traceback=typer.Option(False, '--traceback', help='Show full traceback on CommandError.'), no_color=typer.Option(False, '--no-color', help="Don't colorize output."), force_color=typer.Option(False, '--force-color', help='Force colorized output.'), version=typer.Option(False, '--version', help='Show Django startproject version and exit.'))
¶
Create a Django project directory structure (replicates wagtail start).
Source code in src/wagtail_cli/cli/main.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
Configuration¶
The configuration cascade resolving flags, environment variables, and dotfiles:
Errors¶
The error hierarchy and exit-code mapping:
WgtlError
¶
Bases: Exception
Base CLI error. problem is the verbatim RFC 7807 body (or raw text).
Source code in src/wagtail_cli/errors.py
Output¶
JSON and human-readable rendering:
project(data, selectors)
¶
Project response data onto dot-separated fields.
Collection responses keep their pagination count while selectors apply to
each item. This is intentionally a local projection: the v3 API does not
support fields= projections, but agents often only need an id, title,
URL, or status from a large response.
Source code in src/wagtail_cli/output.py
Field parsing¶
--field value parsing, @file references, and page-ref resolution:
Docs viewer¶
Resolving, fetching, and rendering docs.wagtail.org content for wt docs:
Resolve, fetch, and render docs.wagtail.org content.
Pure logic shared by the wt docs commands: URL resolution, Wagtail
version detection, API reference parsing, and search result formatting.
Operation
dataclass
¶
One ### METHOD /api/v3/.../ section of the v3 API reference.
Source code in src/wagtail_cli/docs.py
detect_wagtail_version()
¶
Return the docs version of the locally installed Wagtail, if any.
Falls back to querying the surrounding project's interpreter, so an isolated install of wt (uv tool, pipx) still detects the project's Wagtail version.
Source code in src/wagtail_cli/docs.py
extract_index_section(markdown)
¶
Return the content under the ## Index heading of a docs page.
Source code in src/wagtail_cli/docs.py
extract_outline(markdown)
¶
Render a docs page's Markdown headings as an indented outline.
Scans lines for ATX headings (same line-based detection as
parse_operations), skipping fenced code blocks, and indents each
heading by its level.
Source code in src/wagtail_cli/docs.py
find_operations(operations, query)
¶
Match a query like GET /api/v3/documents/ against parsed operations.
Returns (exact_matches, similar_matches). The query's leading HTTP method
(case-insensitive, optional) narrows the match; the API version prefix is
optional and /api/v3/, /api/v3-preview/, and /cms-api/v3/ all
normalize to the same resource suffix.
Source code in src/wagtail_cli/docs.py
format_search_results(payload)
¶
Render a search API response as a concise numbered list.
Source code in src/wagtail_cli/docs.py
normalize_operation_path(path)
¶
Reduce an API path to its resource suffix, without version prefixes.
Source code in src/wagtail_cli/docs.py
normalize_wagtail_version(raw)
¶
Reduce a package version (8.0.1, 8.0b1) to its docs version (8.0).
parse_operations(markdown)
¶
Split the API reference Markdown into per-operation sections.
Source code in src/wagtail_cli/docs.py
resolve_docs_url(cli_url=None, environ=None)
¶
Resolve the docs site root: CLI flag > WAGTAIL_CLI_DOCS_URL > default.
Source code in src/wagtail_cli/docs.py
resolve_page_url(docs_url, language, version, path)
¶
Resolve a user-provided docs path or URL to a Markdown page URL.
Accepts full URLs (any host, e.g. PR preview builds), paths starting with a language or version segment, and bare page paths which get the resolved version inserted. A missing .html extension is appended, and the .html.md Markdown variant is fetched.
Source code in src/wagtail_cli/docs.py
resolve_version(explicit=None, installed=_unset)
¶
Resolve the docs version to use: --version > local Wagtail > stable.
Source code in src/wagtail_cli/docs.py
Transport¶
The HTTP client shared by all resources, with auth, error mapping, --dry-run
and -v support: