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.

Parameters:
  • output_folder (str) – Folder containing output.md file.

  • library_name (str) – Name of the library for the txt filename.

Returns:

Path to the created .txt file.

Return type:

str

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:

str

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.

Parameters:

file_path (str) – Path to a .py file.

Returns:

True if at least one docstring is found.

Return type:

bool

contextmaker.converters.auxiliary.has_documentation(lib_path: str) bool[source]

Check if the library contains a Sphinx documentation folder.

Parameters:

lib_path (str) – Path to the library.

Returns:

True if Sphinx files exist, else False.

Return type:

bool

contextmaker.converters.auxiliary.has_notebook(lib_path: str) bool[source]

Check if the library contains Jupyter notebooks.

Parameters:

lib_path (str) – Path to the library.

Returns:

True if at least one .ipynb file exists.

Return type:

bool

contextmaker.converters.auxiliary.has_source(lib_path: str) bool[source]

Check if the library has source code but no other documentation.

Parameters:

lib_path (str) – Path to the library.

Returns:

True if only source code is found.

Return type:

bool

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]
contextmaker.converters.markdown_builder.combine_markdown(build_dir, exclude, output, index_path, library_name)[source]
contextmaker.converters.markdown_builder.convert_notebook(nb_path)[source]
contextmaker.converters.markdown_builder.extract_toctree_order(index_path)[source]
contextmaker.converters.markdown_builder.main()[source]
contextmaker.converters.markdown_builder.parse_args()[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')