mkdocstrings-python is a handler for the mkdocstrings library, specifically designed to parse and render Python API documentation within MkDocs-generated sites. It leverages the Griffe library for static analysis of Python code to extract docstrings and signatures. The current version is 2.0.3, and it maintains an active release cadence with frequent updates and bug fixes.
pip install mkdocs mkdocstrings mkdocstrings-pythonNo compatibility data collected yet for this library.
This quickstart creates a minimal MkDocs project structure, including an mkdocs.yml file configured to use mkdocstrings-python, a sample Python package, and a Markdown file with a `:::` directive. It demonstrates how to set up `mkdocstrings` to document Python code. Run the Python script, then navigate to the `my_docs_project` directory and execute `mkdocs build` to generate the documentation. The `paths` configuration under `plugins.mkdocstrings.handlers.python` is crucial for mkdocstrings-python to locate your source code.
Consult the migration guide or changelog for specific breaking changes and adapt your configuration/code accordingly.
Ensure 'griffelib' is installed. If you have custom integrations, verify compatibility with 'griffelib' API.
Install all three packages: `pip install mkdocs mkdocstrings mkdocstrings-python`.
Add `plugins: [mkdocstrings]` to `mkdocs.yml` and ensure the `python` handler is configured, e.g., `plugins.mkdocstrings.handlers.python.paths`.
Ensure `plugins.mkdocstrings.handlers.python.paths` in `mkdocs.yml` correctly points to the directory containing your Python modules, or set your `PYTHONPATH` environment variable correctly before running `mkdocs build`.
Carefully review the specified file and line number for syntax errors. Use a Python linter or run the file directly with `python your_module.py` to diagnose basic syntax issues. Ensure the file is correctly encoded (e.g., UTF-8) and does not contain invisible problematic characters.
Inspect and correct the Python syntax error in `/script.py` at the specified line. Ensure the test script is compatible with the Python 3.13 environment.
Ensure `mkdocstrings-python` is installed in the correct environment: `pip install mkdocstrings-python`.
Verify that 'your_package.your_module' is the correct dotted path to an existing and importable Python object. Ensure your project's root directory or the directory containing the package is added to the `paths` option in `mkdocs.yml` under the `python` handler, for example: `plugins: mkdocstrings: handlers: python: paths: [src]`. Also, confirm all relevant directories have `__init__.py` files, especially if it's a non-namespace package.
Check the spelling of the cross-reference identifier. Ensure the referenced object is actually being documented by `mkdocstrings-python`. If referencing an external project, confirm its inventory is correctly imported in `mkdocs.yml`. For false positives, wrap the text in backticks (` `) to prevent mkdocstrings from trying to process it as a cross-reference.
Try reinstalling `mkdocstrings` and `mkdocstrings-python` in a clean virtual environment: `pip uninstall mkdocstrings mkdocstrings-python && pip install mkdocstrings mkdocstrings-python`. If using a dependency manager like Poetry or PDM, ensure dependencies are properly synchronized (e.g., `poetry install` or `pdm sync`).