Skip to main content

pybind11_mkdoc

CI

This tool processes a sequence of C/C++ headers and extracts comments that can be referenced to generate docstrings in pybind11 binding code.

To install the latest development version:

python -m pip install git+https://github.com/pybind/pybind11_mkdoc.git

Usage

To use this tool, simply invoke it with a list of header files. All output will be written to stdout, or to a filename provided via the -o parameter.

python -m pybind11_mkdoc -o docstrings.h header_file_1.h header_file_2.h

Optionally, the path to the libclang.so and LLVM directory can be specified by setting the LIBCLANG_PATH and LLVM_DIR_PATH environment variables respectively.

Suppose we provide an input file with the following contents:

/// Docstring 1
class MyClass {

    /// Docstring 2
    MyClass() {
    }

    /// Docstring 3
    void foo() {
    }

    /// Docstring 4 for overload
    void foo(int bar) {
    }

    /// Docstring 5 for yet another overload
    void foo(int bar, int baz) {
    }
};

Once processed via pybind11_mkdoc, the docstrings can be accessed as follows from pybind11 binding code:

#include "docstrings.h"

const char *docstring_1 = DOC(MyClass);
const char *docstring_2 = DOC(MyClass, MyClass);
const char *docstring_3 = DOC(MyClass, foo);
const char *docstring_4 = DOC(MyClass, foo, 2);
const char *docstring_5 = DOC(MyClass, foo, 3);

Note the counter suffix for repeated definitions and docstrings. Namespaces and nested classes are also supported, in which case the number of arguments to the DOC macro simply increases.

In practice, the docstrings are likely referenced in a matching set of binding declarations:

py::class_<MyClass>(m, "MyClass", DOC(MyClass))
    .def(py::init<>(), DOC(MyClass, MyClass))
    ...

CMake

The pybind11_mkdoc CMake function is included to easily generate header for a pybind11 module when compiling said module in CMake. The function generates the headers based on the arguments provided. In addition, it add target dependencies so the pybind11-mkdoc header file is generated before the pybind11 module. Also, it will automatically add the current binary directory to the pybind11 module's includes, so it can easily be included when compiling the module.

The required parameters are:

  • OUTPUT - The name of the output file.
  • PYBIND11_MODULE - The pybind11 module target that these docs will be used for.
  • HEADERS - The header files to create docs for. These can be absolute paths or relative to the current source directory.

The optional parameters are:

  • EXTRA_ARGS - This string argument will be added verbatim to the pybind11-mkdoc command.

Below is an example of how it is used:

# Find pybind11-mkdoc
# This assumes you have already run a find_package for Python.
execute_process(
    COMMAND ${Python_EXECUTABLE} -c "import pybind11_mkdoc; print(pybind11_mkdoc.get_cmake_dir())"
    OUTPUT_VARIABLE pybind11_mkdoc_DIR
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
find_package(pybind11_mkdoc REQUIRED CONFIG)

# Add the pybind11 module
pybind11_add_module(my_pybind11_module my_src_files.cc)
pybind11_mkdoc(
    OUTPUT my_pybind11_module_docs.h
    PYBIND11_MODULE my_pybind11_module
    HEADERS
        header_1.h
        /absolute/path/to/header_2.h
)

Limitations

This tool supports Linux and macOS for Python versions 3.9 to 3.14. Also, it requires Clang/LLVM to be installed.

Testing

Install the packages pytest, pytest-forked and pybind11:

python3 -m pip install pytest pytest-forked pybind11

Next, install this project:

python3 -m pip install .

And execute the tests (forked)

python3 -m pytest --forked

Release files for pybind11-mkdoc 3.0.0

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

Source distribution (sdist)

Source distribution for pybind11-mkdoc 3.0.0
File Size Uploaded
pybind11_mkdoc-3.0.0.tar.gz 23.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pybind11-mkdoc 3.0.0
File Interpreter ABI Platform
pybind11_mkdoc-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 41.0 kB

Release files / pybind11_mkdoc-3.0.0.tar.gz

Download URL pybind11_mkdoc-3.0.0.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
777a19b5943ef8e3d22dde21245c47a297b560f241c21e841b9dd4c1ee3fe107
BLAKE2b-256 checksum
How to use checksums
86543b8504d21361c94b5c56ab49b49a3aca4ce40c1414e6c1dc11ea6754170a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 14, 2026.

Transparency log

Release files / pybind11_mkdoc-3.0.0-py3-none-any.whl

Download URL pybind11_mkdoc-3.0.0-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d836f5ef29276e74aeb0456b3bdb219e7bbfca839c0e4c6831004bc9dc62270c
BLAKE2b-256 checksum
How to use checksums
ec7039ebac87ad9fd40261828a1c2bdcf5891f9f4c53a42c840599eafb2bd263
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.6.2

2 release files

2.6.0

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