Generate a reStructuredText file with an ASCII project tree and literalinclude blocks
Project description
Ship entire project source code and directory tree with your Sphinx documentation.
Generate a reStructuredText (.rst) file that contains:
An ASCII directory tree of your project.
A literalinclude directive for every source file you select.
The result is a single .rst document ready to be included in a Sphinx documentation build, specifically for the llms.txt, providing full project context for LLMs.
Prerequisites
Python 3.10+
Installation
uv pip install sphinx-source-tree
Usage
Quick start
Run in your project root:
sphinx-source-tree
This writes docs/source_tree.rst with the full tree and literalinclude blocks for .py, .md, .js and .rst files.
Print to stdout instead:
sphinx-source-tree --stdout
CLI reference
sphinx-source-tree [OPTIONS]
- -p, --project-root PATH
Project directory. Default: current directory.
- -d, --depth N
Maximum tree depth. Default: 10.
- -o, --output PATH
Output .rst file. Default: docs/source_tree.rst.
- -e, --extensions EXT [EXT ...]
File suffixes to include via literalinclude. Default: .py .md .js .rst.
- -i, --ignore PAT [PAT ...]
Glob patterns to ignore (matched against both the relative path and the bare file name).
- -w, --whitelist DIR [DIR ...]
Restrict output to these directories. Ignored when --include-all is active.
- --include-all / --no-include-all
Include everything regardless of whitelist. Default: on.
- -t, --title TEXT
RST section title. Default: Project source-tree.
- --linenos / --no-linenos
Attach :linenos: to literalinclude directives. Default: off.
- --stdout
Write to stdout instead of the output file.
- -V, --version
Show version and exit.
Configuration via pyproject.toml
All CLI options (except --stdout and --version) can be set under [tool.sphinx-source-tree] in your project’s pyproject.toml. CLI arguments always take precedence.
Example:
[tool.sphinx-source-tree]
depth = 4
output = "docs/source_tree.rst"
extensions = [".py", ".rst", ".toml"]
ignore = ["__pycache__", "*.pyc", ".git", "*.egg-info"]
whitelist = ["src", "docs"]
include-all = false
title = "Source listing"
linenos = true
extra-languages = {".vue" = "vue", ".svelte" = "svelte"}
Key names use hyphens (include-all) to follow TOML/PEP 621 convention; they are normalised internally.
Python API
You can also call the generator from Python:
from pathlib import Path
from sphinx_source_tree import generate
rst = generate(
project_root=Path("."),
output=Path("docs/source_tree1.rst"),
depth=5,
extensions=[".py", ".rst"],
ignore=["__pycache__", "*.pyc"],
title="My project source",
)
Path("docs/source_tree.rst").write_text(rst)
generate() returns the RST content as a string and never writes to disk, so you can post-process or redirect as needed.
Lower-level helpers are also importable:
build_tree() – ASCII tree string.
collect_files() – list of Path objects to include.
detect_language() – suffix-to-Sphinx-language mapping.
load_config() – read [tool.sphinx-source-tree] from pyproject.toml.
Documentation
Documentation is available on Read the Docs.
Tests
Run the tests:
pytest -vvv
Writing documentation
Keep the following hierarchy.
=====
title
=====
header
======
sub-header
----------
sub-sub-header
~~~~~~~~~~~~~~
sub-sub-sub-header
^^^^^^^^^^^^^^^^^^
sub-sub-sub-sub-header
++++++++++++++++++++++
sub-sub-sub-sub-sub-header
**************************
License
MIT
Support
For security issues contact me at the e-mail given in the Author section.
For overall issues, go to GitHub.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_source_tree-0.1.tar.gz.
File metadata
- Download URL: sphinx_source_tree-0.1.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a642d5affe6069d97b8144b10b49884e36c1a699b9e9dae7844f96441fc1557
|
|
| MD5 |
4da76fb5aba9046b7bc38e7d49331c7d
|
|
| BLAKE2b-256 |
82c9236b824a434d104250949789875ab5e7d9af5a9624ed3fbedccb55b0734a
|
File details
Details for the file sphinx_source_tree-0.1-py3-none-any.whl.
File metadata
- Download URL: sphinx_source_tree-0.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5976c6e092666b22616e5445264b174eae82d3ba5dffd25b9dafd62214ae85e5
|
|
| MD5 |
9c5db4d2ccf1c1c928abc6704e93c227
|
|
| BLAKE2b-256 |
db0d56fc034a691166121bcf5ad0fa1726acfb3ea506ce4df8ae60b6eea0d357
|