Skip to main content

No project description provided

Project description

sphinx-llm

The sphinx-llm package includes a collection of extensions for working with LLMs.

There are two categories of tools in this package:

  • Enabling LLMs and agents to consume your docs - This is useful when you want your project to be well indexed and represented in LLMs when users ask about projects in your domain.
  • Leveraging LLMs to generate content dynamically during the Sphinx build - This is useful for generating static content that gets baked into the documentation. It it not intended to provide an interactive chat service in your documentation.

Installation

pip install sphinx-llm

# For extensions that use LLMs to generate text
pip install sphinx-llm[gen]

Extensions

llms.txt Support

The sphinx_llm.txt extension automatically generates markdown files for consumption by LLMs following the llms.txt standard alongside HTML files during the Sphinx build process.

The llms.txt standard describes how you can provide documentation in a way that can be easily consumed by LLMs, either during model training or by agents at inference time when using tools that gather context from the web. The standard describes that your documentation sitemap should be provided in markdown in llms.txt and then the entire documentation should be provided in markdown via a single file called llms-full.txt. Additionally each individual page on your website should also have a markdown version of the page at the same URL with an additional .md extension.

To use the extension add it to your conf.py:

# conf.py
# ...

extensions = [
    "sphinx_llm.txt",
]

When you build your documentation with sphinx-build (or make html), the extension will:

  1. Find all HTML files generated in the output directory
  2. Convert each HTML file to markdown format
  3. Save the markdown files with the same name plus an extra .md extension
  4. Concatenates all generated markdown into a single llms-full.txt file

For example, if your build generates:

  • _build/html/index.html
  • _build/html/apples.html

The extension will also create:

  • _build/html/index.html.md
  • _build/html/apples.html.md
  • _build/html/llms-full.txt

Note: This extension only works with HTML builders (like html and dirhtml).

Docref

The sphinx_llm.docref extension adds a directive for summarising and referencing other pages in your documentation. Instead of just linking to a page the extension will generate a summary of the page being linked to and include that too.

To use this extension you need to have ollama running.

If you have a GPU then generation will be much faster, but it is optional. See the GitHub Actions for an example of using it in CI.

To use the extension add it to your conf.py.

# conf.py
# ...

extensions = [
    "sphinx_llm.docref",
]

Then use the docref directive in your documents to reference other documents.

Testing page
============


.. docref:: apples
   
   Summary of apples page.

Then when you run sphinx-build (or make html) a summary will be generated and your source file will be updated too.

Testing page
============


.. docref:: apples
   :hash: 31ec12a54205539af3cde39b254ec766
   :model: llama3.2:3b
   
   Feeding apples to a friendly pig involves selecting ripe, pesticide-free apples, washing them thoroughly, cutting into manageable pieces, introducing them calmly, monitoring the pig's reaction, and cleaning up afterwards.

A hash of the referenced document is included to avoid generating summaries unnecessarily. But if the referenced page changes the summary will be regenerated.

You can also modify the summary if you need to clean up the language generated, and as long as the hash still matches the file it will be used.

Building the docs

Try it out yourself by building the example documentation.

uv run --dev sphinx-autobuild docs/source docs/build/html

Alternatives

There are other projects that solve this same problem, that’s the wonderful nature of open source software. This section compares the various approaches each project has taken.

These comparisons have been put together with the best of intentions, but I acknowledge they are highly subjective. If you spot any information on this page that you beleive to be incorrect or incomplete please don’t hesitate to open a Pull Request. The goal here is to provide you with all the information you need to make the right choice for your needs.

Dimension sphinx-llm sphinx-llms-txt
Purpose Rich llms.txt and llms-full.txt markdown creation with individual pages and LLM summarization capabilities. Simple llms.txt and llms-full.txt files creation.
Individual pages Outputs a Markdown rendered version for each page. Source of each page is available at a Sphinx specific _sources URL.
Supported docs input formats Works with any Sphinx source format including RST, MyST, etc. Works with any Sphinx source format including RST, MyST, etc.
Supported llms.txt output formats Markdown. llm.txt is in markdown, llms-full.txt and invividual pages pass through whatever the source format was.
Additional features In the future could allow llms.txt to include LLM generated summaries of each page (see #28). Allows manual configuration of llms-full.txt content.
Build-time behavior Can double docs build time; Needs to run the markdown builder after the main build is complete (in future could run in parallel see #31). Minimal build time impact; post build runs a converter/aggregator of _sources.
Limitations Not all directives are supported by the markdown builder. Source documentation files are not processed, so directives like automodule aren't expanded.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_llm-0.1.4.tar.gz (263.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_llm-0.1.4-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_llm-0.1.4.tar.gz.

File metadata

  • Download URL: sphinx_llm-0.1.4.tar.gz
  • Upload date:
  • Size: 263.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for sphinx_llm-0.1.4.tar.gz
Algorithm Hash digest
SHA256 be0032b62809548edc0131ecffffaba9617ff8aaebf19bf5c2c1d18d1b7af557
MD5 bc832b055fee18103fe4a62d3f36621c
BLAKE2b-256 b7b5194aeb37dfb66334653db836ebf45cf9bdab01bcf1906ed1fe5c6e63f381

See more details on using hashes here.

File details

Details for the file sphinx_llm-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_llm-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f19ffdd6fba561af6acbe4f335f396d7af6c92de5fa5ccf29fbb7f74c4b87985
MD5 bd7e40bc0bd2a4d676500dfaafdf1853
BLAKE2b-256 8d8cf71906df31fb9ef6473b6ba74378c7e4ce314d4e3071addbce05fd7e32e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page