MkDocs-MkNodes
Don't write docs. Code them.
mkdocs-mknodes builds your documentation site from a Python node tree created with MkNodes. Pages, navigation, API docs, changelogs, dependency tables, diagrams and more are generated from your project's metadata and code, and you can still mix in hand-written Markdown and Jinja templates wherever you like. The HTML site is built by Zensical.
2.0: The MkDocs plugin is gone. MkNodes generates the site input (pages, nav, assets, config) and Zensical builds it. Existing
mkdocs.ymlfiles keep working: themknodesentry of thepluginslist is still read for settings, but[tool.mknodes]inpyproject.tomlis the preferred place now.
Installation
pip install mkdocs-mknodes
Quickstart
1. Zero configuration: the default website
mkdocs-mknodes build # generate + zensical build
mkdocs-mknodes serve # live preview on http://localhost:8000/
A mkdocs.yml is optional (theme, site_name, markdown_extensions, ...). Without a
build-fn or pages setting, MkNodes builds a complete default website for the project in the
current Git repository:
- Home: your
README.md(falls back to.github/README.md, then the package description) - API: API reference for your package, generated recursively
- CLI: CLI documentation, if your project defines a command line interface
- Development: changelog (from Git commits), contribution guidelines, dev environment setup, dependency table and tree and license
2. Custom website: your own build function
Point build-fn to any callable (module:function, module:Class.classmethod or
path/to/file.py:function). It receives the root MkNav and the theme and fills the tree:
# build_docs.py (in the project root)
import mknodes as mk
def build(root: mk.MkNav, theme: mk.Theme) -> None:
page = root.add_page("Home", is_index=True)
page += mk.MkAdmonition("Hello, world!")
page += mk.MkCode.for_object(build) # show the code that created this page
root.add_doc(section_name="API", recursive=True)
# pyproject.toml
[tool.mknodes]
build-fn = "build_docs.py:build"
Build functions may also be async. Extra keyword arguments can be passed via the kwargs
setting.
3. Custom website from config
The default build function also accepts a node tree via the pages setting:
[[tool.mknodes.pages]]
title = "Home"
type = "MkText"
text = "{{ metadata.description }}"
is_index = true
[[tool.mknodes.pages]]
title = "API"
type = "MkDoc"
section_name = "API"
recursive = true
[[tool.mknodes.pages]]
Development = [
{ title = "Changelog", type = "MkChangelog" },
{ title = "License", type = "MkLicense" },
]
How it works
mkdocs-mknodes generate runs the build function and writes
- the generated pages and assets into the docs folder (listed in a generated
docs/.gitignore; hand-written pages are never overwritten and keep working next to the generated ones), - HTML template overrides (announcement bars, per-page resources, error page, ...) into the
theme
custom_dir(defaultoverrides/), mkdocs.generated.yml, whichINHERITsmkdocs.ymland adds the nav, the required Markdown extensions and extra CSS / JS.
mkdocs-mknodes build then runs zensical build -f mkdocs.generated.yml; serve runs
generate --watch next to zensical serve.
Features
- Project metadata (pyproject, Git, installed distribution, ...) is available to all nodes and to the built-in Jinja environment (powered by JinjaRope).
- Pages can be Jinja templates; bare links between generated pages are resolved automatically.
- Edit-page links point to the code that generated a page;
show-page-info = trueappends build information (metadata, resources, generating code) to every page. - Build documentation for remote repositories (
--repo-urlcan be a Git URL).
CLI
mkdocs-mknodes generate [--watch] # only write the site input
mkdocs-mknodes build [-d site] [-s] # generate + zensical build (strict mode with -s)
mkdocs-mknodes serve # generate --watch + zensical serve
mkdocs-mknodes build -r https://github.com/owner/repo.git # docs for a remote repository
--engine zensical / -e zensical is accepted for compatibility (Zensical is the only engine).
Run mkdocs-mknodes <command> --help for all options.
Settings
Read from [tool.mknodes] in pyproject.toml (preferred) and the mknodes entry of the
plugins list in mkdocs.yml (pyproject.toml wins, CLI options win over both).
The most important settings (see the docs for all):
| Setting | Default | Description |
|---|---|---|
build-fn |
mkdocs_mknodes:parse |
Callable that builds the node tree |
kwargs |
Keyword arguments for the build function | |
pages |
Node tree for the default build function | |
repo-path |
. |
Local path or Git URL of the repository to document |
clone-depth |
100 |
Clone depth for remote repositories |
show-page-info |
false |
Append build information to every page |
global-resources |
true |
Put CSS/JS into all pages instead of only the pages that need them |
render-by-default |
true |
Render generated pages with Jinja |
generated-dir |
docs dir | Where generated pages are written |
Migrating from 1.x
- Build with
mkdocs-mknodes build(--engine zensicalstill works), notmkdocs build. mkdocsis no longer a dependency; addzensical(pulled in by mkdocs-mknodes) and keepmkdocstrings[python]in your docs dependencies for API pages.- Removed: the MkDocs plugin (
mkdocs.pluginsentry point),create-config, the--themeand--use-directory-urlsoptions, the Jinja rendering of hand-written pages, the link replacer for hand-written pages and the MkDocs template rewriting. The plugin optionsbuild_folder,rewrite_theme_templates,auto_delete_generated_templates,jinja_on_undefinedandllm_*are ignored.
License
MIT
Metadata
Release files for mkdocs-mknodes 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mkdocs_mknodes-2.1.1.tar.gz | 38.9 kB | Without provenance | Details for mkdocs_mknodes-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mkdocs_mknodes-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for mkdocs_mknodes-2.1.1-py3-none-any.whl |
Total release size: 82.3 kB
Release files / mkdocs_mknodes-2.1.1.tar.gz
| Download URL | mkdocs_mknodes-2.1.1.tar.gz |
|---|---|
| Size | 38.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
621a48e68173807b78e398ab39c1fd21a15c9520ac6e4c20e52edf4e0f7dceda
|
|
BLAKE2b-256 checksum How to use checksums |
8dbdf978f6c02c4ec111187978232f4c1285ba8b36945646a744b3535e980161
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / mkdocs_mknodes-2.1.1-py3-none-any.whl
| Download URL | mkdocs_mknodes-2.1.1-py3-none-any.whl |
|---|---|
| Size | 43.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce497ee7fbcc18998fe72dd1a854bf4ebffe2fc7675ec3fc32b27b8fd1b926e9
|
|
BLAKE2b-256 checksum How to use checksums |
770f454f47f6de169d844498924e8917a0b819cb7847757cb4e14e002fea0d6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for mkdocs-mknodes 2.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.