Skip to main content

mkdocs-autoapi

pypi version docs Ruff

Description

mkdocs-autoapi is a MkDocs plugin that automatically generates API documentation from your project's source code. The idea for the plugin comes from this recipe in the MkDocs documentation.

Installation

Requirements

  • Python version 3.6 or higher
  • MkDocs version 1.4.0 or higher
  • mkdocstrings version 0.19.0 or higher

Installation via pip

We recommend installing this package with pip:

pip install mkdocs-autoapi

Usage

Basic Usage

To use the plugin, add the following configuration to your mkdocs.yml file:

plugins:
  - ... other plugin configuration ...
  - mkdocs-autoapi
  - mkdocstrings

Setting the Project Root

By default, the plugin will use the current working directory as the project root. If you would like to use a different directory, you can specify a value in the autoapi_dir configuration option:

plugins:
  - ... other plugin configuration ...
  - mkdocs-autoapi:
      autoapi_dir: /path/to/autoapi/dir
  - mkdocstrings

Including and Ignoring Patterns

You can ignore files and directories from the documentation by specifying a value in the autoapi_ignore configuration option. This option accepts a list of glob patterns. Note that the following patterns are always ignored:

  • **/.venv/**/
  • **/venv/**/

Likewise, the autoapi_file_patterns configuration option allows for control of which files are included in the API reference. This option also accepts a list of glob patterns which are evaluated (recursively) relative to autoapi_dir. By default, all files with .py and .pyi extensions are included.

As an example, suppose your project has the following structure:

project/
    docs/
        index.md
    module/
        __init__.py
        lorem.py
        ipsum.py
        dolor.py
    second_module/
        __init__.py
        lorem.py
        sit.py
        amet.py
    venv/
    mkdocs.yml
    README.md

To ignore all files named lorem.py, you can add the following configuration to your mkdocs.yml file:

plugins:
  - ... other plugin configuration ...
  - mkdocs-autoapi:
      autoapi_ignore:
        - "**/lorem.py"
      autoapi_file_patterns:
        - "*.py"
  - mkdocstrings

Disabling API Documentation Generation

To disable API documentation generation, set the autoapi_generate_api_docs configuration option to False. This is useful when transitioning to manual documentation or when the API documentation is not needed.

Including API Documentation in Navigation

The inclusion of API documentation in the navigation can be controlled via the configuration option autoapi_add_nav_entry. This option accepts either a boolean value or a string. Behavior is as follows:

  • If True, then a section named "API Reference" will be added to the end of the navigation.
  • If False, then no section for the API documentation will be added. In this case, a manual link to the API documentation can be added to the navigation.
  • If a string, then a section with the specified name will be added to the end of the navigation.

Example: To include the API documentation in the navigation under the section "Reference", add the following configuration to mkdocs.yml:

plugins:
  - ... other plugin configuration ...
  - mkdocs-autoapi:
      autoapi_add_nav_entry: Reference
  - mkdocstrings

Example: To disable the automatic addition of the API documentation to the navigation and add a manual link to the API documentation, add the following configuration to mkdocs.yml:

nav:
  - ... other navigation configuration ...
  - API: autoapi/ # target should be `autoapi_root`
  - ... other navigation configuration ...

More information on navigation configuration can be found in the MkDocs User Guide.

Putting It All Together

Again, consider the following project structure:

project/
    docs/
        index.md
    module/
        __init__.py
        lorem.py
        ipsum.py
        dolor.py
    second_module/
        __init__.py
        lorem.py
        sit.py
        amet.py
    venv/
    mkdocs.yml
    README.md

A full mkdocs.yml for the project might look like this:

site_name: Project

nav:
  - Home: index.md
  - API Reference: autoapi/

plugins:
  - mkdocs-autoapi
  - mkdocstrings

theme:
  name: readthedocs

More information MkDocs configuration through mkdocs.yml can be found in the MkDocs User Guide.

Contributing

Contributions are always welcome! Please submit a pull request or open an issue to get started.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Metadata

Release files for mkdocs-autoapi 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-autoapi 0.4.1
File Size Uploaded
mkdocs_autoapi-0.4.1.tar.gz 21.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-autoapi 0.4.1
File Interpreter ABI Platform
mkdocs_autoapi-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.2 kB

Release files / mkdocs_autoapi-0.4.1.tar.gz

Download URL mkdocs_autoapi-0.4.1.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3ea73c66361124afea8024a5cb2d681b8d88c3137b6acfed6fe31e11f7b8cf85
BLAKE2b-256 checksum
How to use checksums
002275c85eb1129754da3d1275a599e924ee266a94c68d94db632f58e1f5897e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / mkdocs_autoapi-0.4.1-py3-none-any.whl

Download URL mkdocs_autoapi-0.4.1-py3-none-any.whl
Size 24.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f6903058c1a790c6180870559ad930fea04da93961371e21ff23cd010f09c78
BLAKE2b-256 checksum
How to use checksums
c99a41dd5bb54cb698fa6e7e970fc224df9e53ca26ca8951f5647769ba2150cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page