Sphinx API Documentation Setup Plan
Sphinx API Documentation Setup Plan
Goal: Generate comprehensive API documentation from Python docstrings using Sphinx.
Context: JustDoIt codebase has 96+ Python files with ReST-format docstrings. Currently no auto-generated API reference. Jekyll-based project docs already exist in docs/ (GitHub Pages).
1. Prerequisites
Current State:
- All modules use ReST docstrings (compatible with Sphinx autodoc)
- Consistent module structure with
_MODULE_NAME, docstrings, type hints - Dev environment managed by
uv(pyproject.toml) - Existing
docs/directory hosts Jekyll/GitHub Pages content
Decision: Use docs/api/ subdirectory for Sphinx to avoid conflicts with existing Jekyll docs.
2. Installation & Dependencies
2.1 Add Sphinx to dev dependencies
File: pyproject.toml
[dependency-groups]
dev = [
"pytest>=8.0",
"Pillow>=10.0",
"sphinx>=7.0",
"sphinx-rtd-theme>=2.0", # Read the Docs theme
"sphinx-autodoc-typehints>=1.25", # Type hint rendering
]
Install:
uv sync --dev
3. Initialize Sphinx
3.1 Create API docs directory
mkdir docs/api
cd docs/api
3.2 Run sphinx-quickstart
uv run sphinx-quickstart
Configuration answers:
- Separate source and build directories? No (simpler structure)
- Project name: JustDoIt
- Author name: Jonny Galloway
- Project release: 0.1.0
- Project language: en
Generated files:
docs/api/
├── conf.py # Sphinx configuration
├── index.rst # API documentation root
├── _build/ # HTML output (gitignored)
├── _static/ # Custom CSS/JS
└── _templates/ # Custom Jinja2 templates
4. Configure Sphinx (conf.py)
4.1 Enable autodoc extensions
File: docs/api/conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('../..')) # Add repo root to path
extensions = [
'sphinx.ext.autodoc', # Extract docstrings
'sphinx.ext.napoleon', # Parse NumPy/Google style docstrings
'sphinx.ext.viewcode', # Add [source] links
'sphinx.ext.intersphinx', # Link to Python docs
'sphinx_autodoc_typehints', # Render type hints
]
# Autodoc settings
autodoc_default_options = {
'members': True,
'undoc-members': True,
'private-members': False,
'special-members': '__init__',
'inherited-members': False,
'show-inheritance': True,
}
# Napoleon settings (for ReST docstrings)
napoleon_google_docstring = False
napoleon_numpy_docstring = False
napoleon_use_param = True
napoleon_use_rtype = True
# Intersphinx mapping
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'PIL': ('https://pillow.readthedocs.io/en/stable/', None),
'numpy': ('https://numpy.org/doc/stable/', None),
}
# Theme
html_theme = 'sphinx_rtd_theme'
# Project info
project = 'JustDoIt'
copyright = '2026, Jonny Galloway'
author = 'Jonny Galloway'
release = '0.1.0'
5. Create Documentation Structure
5.1 Main index.rst
File: docs/api/index.rst
JustDoIt API Reference
======================
Zero-dependency Python 3 ASCII art CLI with multi-line ANSI-colorized terminal output.
.. toctree::
:maxdepth: 2
:caption: Contents:
modules
cli
core
fonts
effects
output
animate
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
5.2 Auto-generate module stubs
Run:
cd docs/api
uv run sphinx-apidoc -o . ../../justdoit --separate --force
Generated files:
docs/api/
├── justdoit.rst # Package overview
├── justdoit.cli.rst
├── justdoit.core.rst
├── justdoit.fonts.rst
├── justdoit.effects.rst
├── justdoit.output.rst
├── justdoit.animate.rst
└── modules.rst # Module index
5.3 Create package-level .rst files manually (optional)
For more control, create custom .rst files:
File: docs/api/cli.rst
CLI Module
==========
.. automodule:: justdoit.cli
:members:
:undoc-members:
:show-inheritance:
6. Build Configuration
6.1 Add .gitignore entry
File: .gitignore
# Sphinx build output
docs/api/_build/
docs/api/_autosummary/
6.2 Create Makefile (optional, already generated by sphinx-quickstart)
File: docs/api/Makefile
# Minimal makefile for Sphinx documentation
SPHINXBUILD = uv run sphinx-build
SOURCEDIR = .
BUILDDIR = _build
html:
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)"
clean:
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)"
7. Build & Preview
7.1 Build HTML documentation
cd docs/api
uv run sphinx-build -b html . _build/html
Or using Makefile:
make html
7.2 Preview locally
# Option 1: Open in browser
start _build/html/index.html
# Option 2: Local HTTP server
cd _build/html
python -m http.server 8000
# Visit http://localhost:8000
8. Add to CONTRIBUTING.md
File: CONTRIBUTING.md
Add section under Documentation:
### Building API Documentation
JustDoIt uses Sphinx to generate API documentation from docstrings.
**Build HTML docs:**
```bash
cd docs/api
uv run sphinx-build -b html . _build/html
Preview:
start _build/html/index.html # Windows
open _build/html/index.html # macOS/Linux
Rebuild after changes:
make clean && make html
Requirements:
- All public functions/classes must have ReST-format docstrings
- Use type hints (rendered automatically by sphinx-autodoc-typehints)
- Follow existing module docstring patterns ```
9. CI/CD Integration (Optional)
9.1 GitHub Actions workflow
File: .github/workflows/docs.yml
name: Build Sphinx Docs
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v1
- name: Install dependencies
run: uv sync --dev
- name: Build Sphinx docs
run: |
cd docs/api
uv run sphinx-build -W --keep-going -b html . _build/html
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: sphinx-docs
path: docs/api/_build/html/
9.2 Deploy to GitHub Pages (separate from Jekyll docs)
Option A: Deploy to gh-pages branch under /api/ path
Option B: Deploy to Read the Docs (free for open source)
Option C: Keep as build artifact only (download from CI runs)
10. Verification Checklist
- Sphinx dependencies installed (
uv sync --dev) docs/api/conf.pyconfigured with autodoc extensionsdocs/api/index.rstcreated with module toctree- Module stubs auto-generated or manually created
_build/added to.gitignore- Documentation builds without errors:
uv run sphinx-build -b html docs/api docs/api/_build/html - HTML output viewable in browser
- All modules appear in generated docs
- Docstrings render correctly with type hints
- CONTRIBUTING.md updated with build instructions
- (Optional) CI/CD workflow added
11. Common Issues & Solutions
Issue: Module not found during build
Solution: Ensure sys.path.insert(0, os.path.abspath('../..')) in conf.py points to repo root.
Issue: Type hints not rendering
Solution: Install sphinx-autodoc-typehints and add to extensions in conf.py.
Issue: Optional dependencies (Pillow, numpy) cause import errors
Solution: Mock imports in conf.py:
autodoc_mock_imports = ['PIL', 'numpy', 'sounddevice']
Issue: Private modules (_module.py) not documented
Solution: Set autodoc_default_options['private-members'] = True or use .. automodule:: with :private-members: option.
12. Estimated Effort
- Setup & Configuration: 1-2 hours
- Documentation Structure: 1 hour
- First Build & Fixes: 1-2 hours
- CI/CD Integration: 1 hour (optional)
- Total: 3-6 hours
13. Future Enhancements
- Auto-generate examples from tests: Use
sphinx-galleryto embed test code as examples - Docstring coverage report: Use
interrogateto track missing docstrings - API stability badges: Mark experimental vs stable APIs
- Version selector: Support multiple doc versions (e.g.,
latest,0.1.0) - Search optimization: Configure better search indexing for large codebases