Skip to main content

Mkdocs plugin for generating Typer CLI docs

Project description

mkdocs-typer2

PyTest Ruff MkDocs Typer UV Python PyPI License Downloads Codecov Issues

A MkDocs plugin that automatically generates beautiful documentation for your Typer CLI applications.

You might be wondering why there are two plugins for Typer. The mkdocs-typer plugin is great, but it hasn't been updated in over a year, and there have been a number of changes to Typer since then. One important change is that Typer now has its own documentation generation system via the typer <module> utils docs command. This plugin simply leverages that system to generate the documentation for your Typer CLIs.

I created this plugin because the original plugin was no longer working for me, and I wanted to have a simple plugin that would work with the latest version of Typer. If the original mkdocs-typer plugin still works for you, there probably isn't a reason to switch. However, if you are looking for a plugin that will work with the latest version of Typer, this plugin is for you!

Features

  • Seamlessly integrates with MkDocs and Material theme
  • Automatically generates CLI documentation from your Typer commands
  • Supports all Typer command features including arguments, options, and help text
  • Easy to configure and use
  • pretty feature for encapsulating arguments & options inside tables instead of lists
  • Global plugin configuration or per-documentation block configuration

How It Works

The plugin leverages Typer's built-in documentation generation via the typer <module> utils docs command to create Markdown documentation. It then processes this Markdown content and integrates it into your MkDocs site.

The plugin works by:

  1. Registering a Markdown extension that processes special directive blocks
  2. Running the Typer documentation command on your specified module
  3. Optionally reformatting the output to use tables for arguments and options (the "pretty" mode)
  4. Integrating the resulting HTML into your MkDocs site

Installation

Install using pip:

pip install mkdocs-typer2

Requirements

  • Python 3.10 or higher
  • MkDocs 1.6.1 or higher
  • Typer 0.12.5 or higher
  • Pydantic 2.9.2 or higher

Configuration

Basic Configuration

Add the plugin to your mkdocs.yml file:

plugins:
  - mkdocs-typer2

Pretty Mode

The plugin offers a pretty option that can be set in your mkdocs.yml file to enable pretty documentation. This will use markdown tables to format the CLI options and arguments instead of lists:

plugins:
  - mkdocs-typer2:
      pretty: true

Usage

Basic Usage

In your Markdown files, use the ::: mkdocs-typer2 directive to generate documentation for your Typer CLI:

::: mkdocs-typer2
    :module: my_module
    :name: mycli

Required Parameters

  • :module: - The module containing your Typer CLI application. This is the installed module, not the directory path. For example, if your app is located in src/my_module/cli.py, your :module: should typically be my_module.cli.

Optional Parameters

  • :name: - The name of the CLI. If left blank, your CLI will simply be named CLI in your documentation.
  • :pretty: - Set to true to enable pretty formatting for this specific documentation block, overriding the global setting.

Advanced Usage

Per-Block Pretty Configuration

You can override the global pretty setting for individual documentation blocks:

::: mkdocs-typer2
    :module: my_module.cli
    :name: mycli
    :pretty: true

Multiple CLI Documentation

You can document multiple CLIs in the same MkDocs site by using multiple directive blocks:

# Main CLI

::: mkdocs-typer2
    :module: my_module.cli
    :name: mycli

# Admin CLI

::: mkdocs-typer2
    :module: my_module.admin
    :name: admin-cli

Example

This repository is a good example of how to use the plugin. We have a simple CLI located in src/mkdocs_typer2/cli.py.

The CLI's documentation is automatically generated using the block level directive in docs/cli.md:

::: mkdocs-typer2
    :module: mkdocs_typer2.cli
    :name: mkdocs-typer2

And the pretty version in docs/cli-pretty.md:

::: mkdocs-typer2
    :module: mkdocs_typer2.cli
    :name: mkdocs-typer2
    :pretty: true

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_typer2-0.1.7.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_typer2-0.1.7-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_typer2-0.1.7.tar.gz.

File metadata

  • Download URL: mkdocs_typer2-0.1.7.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mkdocs_typer2-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b9d55790822995f2d924718eeaa4d8f2fe047490963f272c1b5f4ff62cb6db13
MD5 8a91c0dc20d0494bc1f6062d90a6822f
BLAKE2b-256 be08994b98ecf9fa0691d9628aa35b1907e15a93ee54ec9005556ae788573454

See more details on using hashes here.

File details

Details for the file mkdocs_typer2-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_typer2-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mkdocs_typer2-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0d1c58da20cc1c10f4ac591492ab9602fb5a7fbcde4e95ab36b3ea509643b46a
MD5 d5997695a0e075b98cad529748c67378
BLAKE2b-256 9a2acce84e4c0d9720bc89b8ef30b7efc5e8af3fc976a5a73b0507a73d95b4a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page