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

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.3.tar.gz (262.5 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.3-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sphinx_llm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 16a7331ed85a61aea7843e6d58bcfde0370df337bbf251db7531de7ab5881d6f
MD5 7e090ec4f8482a0d5d282dbe2e64931c
BLAKE2b-256 e76af6b069bd80599e41c13388bc67debd64c9df4154d03615035d09ced00b73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sphinx_llm-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for sphinx_llm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 dc2b0a4be87738987e7b5761655257073b400921d0eb28847d63f45c7b2084d7
MD5 40645394861871ea3bd0e1ac3c7546cc
BLAKE2b-256 cb2ce6fecc2c0bed49cfeac3d86545c7b18e9e3ac6cc36f36bd04577e11c68a6

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