From scientific-python-development
Sets up and maintains documentation for scientific Python packages using Sphinx, MkDocs, NumPy-style docstrings, Diataxis framework, accessibility standards, and Read the Docs hosting.
npx claudepluginhub uw-ssec/rse-plugins --plugin scientific-python-developmentThis skill uses the workspace's default tool permissions.
A comprehensive guide to creating documentation for scientific Python packages following community best practices from the [Scientific Python Development Guide](https://learn.scientific-python.org/development/guides/docs/).
assets/index-template.mdassets/mkdocs-scientific.ymlassets/noxfile-docs.pyassets/readthedocs.yamlassets/sphinx-conf-scientific.pyreferences/accessible-documentation.mdreferences/common-issues.mdreferences/diataxis-framework.mdreferences/docstring-examples.mdreferences/notebook-integration.mdreferences/sphinx-extensions.mdscripts/generate-api-docs.pyGenerates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
A comprehensive guide to creating documentation for scientific Python packages following community best practices from the Scientific Python Development Guide.
This skill includes extensive supporting materials for documentation tasks:
References (detailed guides):
references/diataxis-framework.md - Complete Diátaxis framework guide with examples for all four documentation typesreferences/sphinx-extensions.md - Detailed Sphinx extension configuration and usagereferences/docstring-examples.md - Comprehensive NumPy-style docstring examples for functions, classes, and modulesreferences/notebook-integration.md - Jupyter notebook integration guide for Sphinx and MkDocsreferences/common-issues.md - Troubleshooting documentation build issuesreferences/accessible-documentation.md - Accessibility guidelines for scientific documentation including images, color contrast, and alt textAssets (ready-to-use templates):
assets/sphinx-conf-scientific.py - Complete Sphinx conf.py template for scientific Pythonassets/readthedocs.yaml - Read the Docs configuration templateassets/mkdocs-scientific.yml - MkDocs configuration template with Material themeassets/noxfile-docs.py - Nox automation sessions for documentation buildsassets/index-template.md - Documentation landing page templateScripts:
scripts/generate-api-docs.py - Script to generate API documentation stubsChoose your documentation framework based on project needs:
Sphinx - Best for:
MkDocs - Best for:
Jupyter Book - Best for:
For Sphinx:
| Theme | Best For | Pros | Cons |
|---|---|---|---|
pydata-sphinx-theme | Scientific Python standard | Dark mode, excellent navigation, ecosystem alignment | Requires configuration |
furo | Modern projects | Clean design, excellent search, fast | Less customization |
sphinx_rtd_theme | Traditional docs | Widely recognized, simple setup | Older design |
sphinx-book-theme | Book-like docs | Beautiful, narrative-focused | Less suitable for API-heavy |
For MkDocs:
| Theme | Best For | Pros | Cons |
|---|---|---|---|
material | Modern projects | Feature-rich, beautiful, customizable | Can be overwhelming |
readthedocs | Simple needs | Familiar, straightforward | Basic features |
| Platform | Best For | Pros | Cons |
|---|---|---|---|
| Read the Docs | Open source projects | Free, automatic builds, versioning | Limited customization |
| GitHub Pages | Simple static sites | Simple, integrated with GitHub | Manual build process |
| Netlify | Advanced needs | Preview deployments, control | Requires setup |
The Diátaxis framework organizes documentation into four categories based on user needs:
| Type | Purpose | Characteristics |
|---|---|---|
| Tutorials | Help newcomers learn by doing | Progressive difficulty, complete examples, encouraging tone |
| How-to Guides | Help users accomplish specific goals | Problem-focused, practical recipes, real-world scenarios |
| Reference | Provide technical specifications | Comprehensive, consistent, auto-generated from docstrings |
| Explanation | Help users understand concepts | Discursive, contextual, theory and design decisions |
Key principle: Don't mix documentation types. Keep tutorials separate from reference docs.
For complete Diátaxis guidance with detailed examples and templates for each documentation type, see
references/diataxis-framework.md.
Create docs/conf.py with these core extensions:
extensions = [
# Core Sphinx extensions
"sphinx.ext.autodoc", # Auto-generate docs from docstrings
"sphinx.ext.autosummary", # Generate summary tables
"sphinx.ext.viewcode", # Add source code links
"sphinx.ext.intersphinx", # Link to other projects
# Scientific Python extensions
"sphinx.ext.napoleon", # NumPy/Google docstrings
"sphinx.ext.mathjax", # Math rendering
"numpydoc", # NumPy documentation style
"sphinx_autodoc_typehints", # Type hint integration
# Markdown support
"myst_parser", # MyST Markdown parser
# Notebook integration
"nbsphinx", # Jupyter notebook rendering
]
autodoc - Automatically generate documentation from docstrings:
.. automodule:: mypackage.analysis
:members:
:undoc-members:
:show-inheritance:
autosummary - Create summary tables:
.. autosummary::
:toctree: generated/
mypackage.function1
mypackage.function2
napoleon - Parse NumPy-style docstrings (configure in conf.py):
napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = True
napoleon_use_param = True
napoleon_use_rtype = True
intersphinx - Link to external documentation:
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"pandas": ("https://pandas.pydata.org/docs/", None),
"matplotlib": ("https://matplotlib.org/stable/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
}
myst_parser - Use Markdown in Sphinx:
myst_enable_extensions = [
"colon_fence", # ::: fences
"deflist", # Definition lists
"dollarmath", # $...$ and $$...$$ for math
"fieldlist", # Field lists
"substitution", # Variable substitution
"tasklist", # Task lists
]
PyData Sphinx Theme (recommended for scientific Python):
html_theme = "pydata_sphinx_theme"
html_theme_options = {
"github_url": "https://github.com/org/package",
"use_edit_page_button": True,
"show_toc_level": 2,
"navigation_with_keys": True,
"icon_links": [
{
"name": "PyPI",
"url": "https://pypi.org/project/your-package",
"icon": "fas fa-box",
},
],
}
html_context = {
"github_user": "org",
"github_repo": "package",
"github_version": "main",
"doc_path": "docs",
}
For complete Sphinx extension configuration including advanced options, autodoc directives, and troubleshooting, see
references/sphinx-extensions.md. For a complete ready-to-useconf.py, seeassets/sphinx-conf-scientific.py.
NumPy-style docstrings are the standard for scientific Python projects. Key sections include:
def compute_statistic(data, method="mean", axis=0, weights=None):
"""
Compute a statistical measure along the specified axis.
Parameters
----------
data : array_like
Input data array. Can be any shape.
method : {'mean', 'median', 'std'}, optional
Statistical method to compute. Default is 'mean'.
axis : int or None, optional
Axis along which to compute. Default is 0.
weights : array_like, optional
Weights for each value. If None, equal weights.
Returns
-------
ndarray
Computed statistic.
Raises
------
ValueError
If `method` is not supported.
Examples
--------
>>> import numpy as np
>>> data = np.array([1, 2, 3, 4, 5])
>>> compute_statistic(data, method='mean')
3.0
"""
pass
For comprehensive NumPy-style docstring examples including classes, modules, generators, and all supported sections, see
references/docstring-examples.md.
.readthedocs.yamlPlace in repository root:
version: 2
build:
os: ubuntu-24.04
tools:
python: "3.12"
jobs:
post_install:
# Install package with docs dependencies
- pip install .[docs]
sphinx:
configuration: docs/conf.py
fail_on_warning: true
formats:
- pdf
- epub
In pyproject.toml, add docs extra:
[project.optional-dependencies]
docs = [
"sphinx>=7.0",
"pydata-sphinx-theme>=0.15",
"sphinx-autodoc-typehints>=2.0",
"numpydoc>=1.6",
"myst-parser>=2.0",
"nbsphinx>=0.9",
]
Or in setup.py:
extras_require = {
"docs": [
"sphinx>=7.0",
"pydata-sphinx-theme>=0.15",
"sphinx-autodoc-typehints>=2.0",
"numpydoc>=1.6",
"myst-parser>=2.0",
"nbsphinx>=0.9",
],
}
mkdocs.ymlsite_name: My Scientific Package
site_description: Description of your scientific package
site_url: https://org.github.io/package
repo_url: https://github.com/org/package
repo_name: org/package
theme:
name: material
features:
- navigation.tabs
- navigation.sections
- navigation.expand
- navigation.top
- search.suggest
- search.highlight
- content.code.copy
- content.tabs.link
palette:
- scheme: default
primary: indigo
accent: indigo
toggle:
icon: material/brightness-7
name: Switch to dark mode
- scheme: slate
primary: indigo
accent: indigo
toggle:
icon: material/brightness-4
name: Switch to light mode
plugins:
- search
- mkdocstrings:
handlers:
python:
options:
docstring_style: numpy
show_source: true
show_root_heading: true
separate_signature: true
merge_init_into_class: true
- mkdocs-jupyter:
include_source: true
execute: false
markdown_extensions:
- pymdownx.arithmatex:
generic: true
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- admonition
- pymdownx.details
- tables
- attr_list
- md_in_html
- def_list
extra_javascript:
- javascripts/mathjax.js
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
nav:
- Home: index.md
- Getting Started:
- Installation: getting-started/installation.md
- Quick Start: getting-started/quickstart.md
- Tutorials:
- tutorials/index.md
- First Analysis: tutorials/first-analysis.md
- How-to Guides:
- guides/index.md
- Handle Large Data: guides/large-data.md
- Reference:
- API: reference/api.md
- Configuration: reference/configuration.md
- Explanation:
- explanation/index.md
- Architecture: explanation/architecture.md
Create docs/javascripts/mathjax.js:
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
document$.subscribe(() => {
MathJax.typesetPromise()
})
Configuration in conf.py:
extensions = [
# ... other extensions
"nbsphinx",
]
# nbsphinx configuration
nbsphinx_execute = "auto" # or "always", "never"
nbsphinx_allow_errors = False
nbsphinx_timeout = 60 # seconds
# Exclude patterns
exclude_patterns = [
"_build",
"**.ipynb_checkpoints",
]
Include notebooks in documentation:
.. toctree::
:maxdepth: 2
notebooks/tutorial
notebooks/advanced_usage
Configuration in mkdocs.yml:
plugins:
- mkdocs-jupyter:
include_source: true
execute: false
allow_errors: false
kernel_name: python3
Reference in navigation:
nav:
- Tutorials:
- Getting Started: notebooks/tutorial.ipynb
- Advanced: notebooks/advanced.ipynb
For advanced notebook integration including execution options, cell tags, and troubleshooting, see
references/notebook-integration.md.
noxfile.py"""Nox sessions for documentation."""
import nox
@nox.session(python="3.12")
def docs(session):
"""Build the documentation."""
session.install(".[docs]")
session.run(
"sphinx-build",
"-W", # Treat warnings as errors
"-b", "html",
"docs",
"docs/_build/html",
)
@nox.session(python="3.12")
def docs_live(session):
"""Build and serve documentation with live reload."""
session.install(".[docs]", "sphinx-autobuild")
session.run(
"sphinx-autobuild",
"-W",
"--open-browser",
"docs",
"docs/_build/html",
)
@nox.session(python="3.12")
def docs_linkcheck(session):
"""Check documentation links."""
session.install(".[docs]")
session.run(
"sphinx-build",
"-b", "linkcheck",
"docs",
"docs/_build/linkcheck",
)
Usage:
nox -s docs # Build docs
nox -s docs_live # Live preview
nox -s docs_linkcheck # Check links
For a complete noxfile with additional sessions (spelling, coverage, doctest, PDF builds), see
assets/noxfile-docs.py.
docs/
├── conf.py # Sphinx configuration
├── index.md # Landing page
├── getting-started/
│ ├── installation.md
│ └── quickstart.md
├── tutorials/
│ ├── index.md
│ ├── first-analysis.md
│ └── advanced-usage.md
├── guides/
│ ├── index.md
│ ├── large-datasets.md
│ ├── performance.md
│ └── extending.md
├── reference/
│ ├── api.rst
│ ├── cli.md
│ └── configuration.md
├── explanation/
│ ├── index.md
│ ├── architecture.md
│ ├── algorithms.md
│ └── design-decisions.md
├── notebooks/
│ └── *.ipynb
└── _static/
└── custom.css
:func:, :class:, :ref:linkcheck builderFor detailed troubleshooting of common documentation build issues, see
references/common-issues.md.
Accessible documentation ensures all users can effectively use your documentation regardless of ability. Follow these core principles based on the Scientific Python Accessible Documentation Guide.
Design requirements:
Context requirements:
For comprehensive accessibility guidelines including code examples, testing tools, and detailed checklists, see
references/accessible-documentation.md.
For multiple versions:
# conf.py
version = "0.1" # Short version
release = "0.1.0" # Full version
# Add version switcher (pydata theme)
html_theme_options = {
"navbar_end": ["version-switcher", "navbar-icon-links"],
}
Create CITATION.cff:
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Doe"
given-names: "Jane"
orcid: "https://orcid.org/0000-0000-0000-0000"
title: "My Scientific Package"
version: 0.1.0
doi: 10.5281/zenodo.1234567
date-released: 2024-01-01
url: "https://github.com/org/package"
Document in docs/citation.md:
# Citing This Software
If you use this software in your research, please cite:
## BibTeX
\`\`\`bibtex
@software{doe2024package,
author = {Doe, Jane},
title = {My Scientific Package},
year = {2024},
version = {0.1.0},
doi = {10.5281/zenodo.1234567},
url = {https://github.com/org/package}
}
\`\`\`
## APA
Doe, J. (2024). My Scientific Package (Version 0.1.0) [Computer software]. https://doi.org/10.5281/zenodo.1234567
# Reproducibility
## Environment Setup
Install exact versions:
\`\`\`bash
pip install package==0.1.0
\`\`\`
Or from `requirements.txt`:
\`\`\`bash
pip install -r requirements.txt
\`\`\`
## Random Seeds
For reproducible results:
\`\`\`python
import numpy as np
import random
random.seed(42)
np.random.seed(42)
\`\`\`
## Data Requirements
Sample data available at: [URL]
Expected data format:
- CSV with columns: [...]
- Missing values encoded as NaN
- Date format: ISO 8601
## System Requirements
- Python 3.9+
- 8GB RAM minimum
- 16GB RAM recommended for large datasets