API Reference
Main Module
Converters
Auxiliary Functions
- contextmaker.converters.auxiliary.convert_markdown_to_txt(output_folder: str, library_name: str) str[source]
Convert the output.md file in the output folder to a .txt file with library name.
- contextmaker.converters.auxiliary.find_format(lib_path: str) str[source]
Detect the documentation format of a given library.
- Parameters:
lib_path (str) – Path to the root of the library.
- Returns:
One of [‘sphinx’, ‘notebook’, ‘docstrings’, ‘source’].
- Return type:
- Raises:
ValueError – If no valid format is detected.
- contextmaker.converters.auxiliary.has_docstrings(file_path: str) bool[source]
Check if the Python file contains docstrings.
- contextmaker.converters.auxiliary.has_documentation(lib_path: str) bool[source]
Check if the library contains a Sphinx documentation folder.
Sphinx Converter
Non-Sphinx Converter
Markdown Builder
This script builds Sphinx documentation in Markdown format and combines it into a single file for use as context with Large Language Models (LLMs).
- contextmaker.converters.markdown_builder.append_notebook_markdown(output_file, notebook_md)[source]
- contextmaker.converters.markdown_builder.build_markdown(sphinx_source, conf_path, source_root)[source]
Command Line Interface
The main entry point for ContextMaker is the command line interface:
python -m contextmaker.contextmaker [OPTIONS]
Arguments
- --input_path, -i
Path to the library documentation folder or project root. Required.
- --output_path, -o
Path to the output folder for converted files. Required.
- --library-name
Name of the library for the documentation title. Optional. Defaults to the basename of the input path.
- --exclude
Comma-separated list of files to exclude (without extension). Optional.
Markdown Builder CLI
The markdown builder tool has its own command line interface:
python converters/markdown_builder.py [OPTIONS]
Arguments
- --sphinx-source
Path to Sphinx source directory (where conf.py and index.rst are). Required.
- --output
Output file path for the generated markdown. Required.
- --source-root
Absolute path to the root of the source code to add to sys.path for Sphinx autodoc. Required.
- --conf
Path to conf.py (default: <sphinx-source>/conf.py). Optional.
- --index
Path to index.rst (default: <sphinx-source>/index.rst). Optional.
- --notebook
Path to notebook to convert and append. Optional.
- --library-name
Name of the library for the documentation title. Optional.
- --exclude
Comma-separated list of files to exclude (without .md extension). Optional.
Examples
Basic Sphinx Conversion
from contextmaker.contextmaker import main
import sys
# Convert Sphinx documentation
sys.argv = [
'contextmaker',
'--input_path', '/path/to/myproject/docs',
'--output_path', './converted_docs'
]
main()
Source Code Conversion
from contextmaker.converters.nonsphinx_converter import create_final_markdown
# Convert source code with docstrings
create_final_markdown('/path/to/source', './output')
Notebook Conversion
from contextmaker.converters.markdown_builder import convert_notebook
# Convert Jupyter notebook to markdown
md_path = convert_notebook('/path/to/notebook.ipynb')