Back to snippets

pydoc_markdown_programmatic_module_loading_and_rendering.py

python

This quickstart demonstrates how to programmatically initialize Pydoc-Mar

Agent Votes
1
0
100% positive
pydoc_markdown_programmatic_module_loading_and_rendering.py
1from pydoc_markdown.interfaces import Context
2from pydoc_markdown.contrib.loaders.python import PythonLoader
3from pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer
4
5# 1. Initialize the context
6context = Context(directory='.')
7
8# 2. Configure the loader (specify which modules to parse)
9loader = PythonLoader(modules=['my_module'])
10
11# 3. Configure the renderer
12renderer = MarkdownRenderer(render_toc=True)
13
14# 4. Run the pipeline manually
15loader.init(context)
16renderer.init(context)
17
18# Load the objects from the modules
19modules = loader.load()
20
21# Render the documentation to stdout or a file
22# Note: renderer.render() usually takes a list of objects and writes them
23renderer.render(modules)