Skip to main content

Markdownizer

Extract existing documentation from Python projects into Markdown.

CI PyPI Python License: MIT

Markdownizer never generates, rewrites, summarizes, or improves documentation. It only extracts what is already present in your source code: docstrings, comments, decorators, and source.

Installation

pip install markdownizer

Or with pipx for an isolated CLI:

pipx install markdownizer

Requires Python 3.9+. No runtime dependencies.

Usage

CLI

markdownizer /path/to/project -o ./docs

This recursively scans the project, parses every Python file with the AST, builds a deterministic Project IR, and writes one Markdown file per package into ./docs.

The compiler-style form is equivalent and supports format selection:

markdownizer build /path/to/project -o ./docs --format markdown
markdownizer build /path/to/project -o ./docs --format json
markdownizer build /path/to/project -o ./docs --format compact

Budgeted context

Produce the best possible representation of a project within a token budget:

markdownizer context . --max-tokens 20000 --profile api
markdownizer context . --profile django --query "user model"

Writes context.md. Options: --max-tokens (default 20000), --profile (architecture default, api, debugging, refactor, django, onboarding), --rank (pagerank default, fanout, simple), and --query (deterministic keyword prefilter).

Statistics

markdownizer stats . --rank pagerank
markdownizer stats . --json

Shows project counts, a token estimate, and top-ranked files/symbols. Ranking is deterministic: PageRank over the import graph with framework-aware boosts (Django models, URL configs, management commands), combined with public/documented factors per symbol.

Common options:

markdownizer . -o ./docs \
  --exclude "tests/*" --exclude "migrations" \
  --only-documented --no-source
Option Description
-o, --output DIR Output directory (default: ./docs)
--root-name NAME Filename for files at the project root (default: _root)
--exclude GLOB Skip matching paths; may be repeated
--format FMT Output backend: markdown, json, or compact
--no-source Omit the ## Source Code section
--no-comments Omit the ## Comments section
--only-documented Only include objects with a docstring
-v, --verbose Increase logging verbosity
-q, --quiet Suppress non-error output
--version Show the version

Run markdownizer --help for the full list.

Python API

from pathlib import Path
from markdownizer import extract_project, build_project_ir, optimize_context

written = extract_project(
    Path("."),
    Path("docs"),
    exclude=["tests/*"],
    include_source=False,
)
print(written)  # list of written output files

# Or build the Project IR directly:
ir = build_project_ir(Path("."), exclude=["tests/*"])
print(ir.ir_version, ir.hash, ir.stats.symbol_count)

# Or generate a budgeted, ranked context artifact:
ctx = optimize_context(ir, max_tokens=20000, profile="api", query="auth")
print(ctx.estimated_tokens, ctx.included_symbols)
print(ctx.text)

Output formats

The pipeline builds a deterministic Project IR (packages → modules → symbols, plus import/inherit/define edges) and renders it through a backend:

Format Command Output
markdown (default) markdownizer build . -o ./docs One .md file per package
json markdownizer build . -o ./docs --format json project.json — full IR serialization
compact markdownizer build . -o ./docs --format compact context.compact.md — signatures, docstrings, inheritance, decorators (no bodies)

The legacy invocation markdownizer <project> -o <out> is kept as a compatibility alias for markdownizer build <project> --format markdown.

Signature mode

Instead of full source or no source, extract_project() accepts include_source="signature" to emit only declaration lines:

extract_project(Path("."), Path("docs"), include_source="signature")

Functions render as def foo(x: int = 1) -> str:, async functions as async def ..., classes as class User(models.Model): (with base classes), and methods with their parameters. Modules render without source. The boolean modes (True/False) are unchanged.

Project IR

build_project_ir(project_root, exclude=None) returns a ProjectIR with:

  • ir_version — schema version (currently 1), independent of the package version
  • packages, modules, symbols — the project hierarchy
  • imports, inherits, defines — relationship edges
  • stats — file/module/symbol counts
  • hash — deterministic blake2b of the canonical IR content

The hash and JSON serialization are deterministic: the same repository content always produces the same hash and the same project.json, making the output suitable for version control and caching. Machine-specific metadata (root, python_version, git) is excluded from the hash.

Import resolution is conservative and fully static: project code is never imported or executed. Imports that cannot be resolved to a project module are marked external.

What is extracted

For every documented object (modules, packages, classes, dataclasses, enums, functions, async functions, methods, properties, Django models, Django forms, Django admin classes, DRF serializers, DRF viewsets, signals, middleware, management commands, URL configuration, and any other object with a docstring):

  • The docstring, verbatim
  • Comments that belong to the object (preceding and inline)
  • Decorators
  • The complete source code

Output format

Each generated Markdown file groups all modules inside a single package and uses specialized headers such as:

# Django Model: User
# DRF Serializer: UserSerializer
# DRF ViewSet: UserViewSet
# Enum: Status
# Dataclass: Point
# Async Function: fetch_data

Every section preserves the original formatting of the source documentation.

Development

See CONTRIBUTING.md for setup, checks, and release steps. Changes are recorded in CHANGELOG.md.

License

MIT — see LICENSE.

Release files for markdownizer 0.4.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 markdownizer 0.4.0
File Size Uploaded
markdownizer-0.4.0.tar.gz 42.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for markdownizer 0.4.0
File Interpreter ABI Platform
markdownizer-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 78.2 kB

Release files / markdownizer-0.4.0.tar.gz

Download URL markdownizer-0.4.0.tar.gz
Size 42.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4ba27d6f7746c51898f9a3f7544ee2640261dbc2ec012af2a9982aa76f104d5c
BLAKE2b-256 checksum
How to use checksums
a34d5cf89b925eb4de8d4be0c0013384baf742a44b34ba01f24aeef1c2a1cccd
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 Sep 24, 2026.

Transparency log

Release files / markdownizer-0.4.0-py3-none-any.whl

Download URL markdownizer-0.4.0-py3-none-any.whl
Size 35.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d68d212d9c57eef37c1e42b2826984b9bb0dc4680a8271b30aaf885901947e2
BLAKE2b-256 checksum
How to use checksums
cf37f5dc540064475217d8b3795b6c5edf2df57e3a987e730658df70b06365e7
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 Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.1.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