Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Instructions that come with the machine
A brilliant tool with no instructions is almost useless to the next person, including you in a year. Documentation answers the questions code can’t: what is this for, how do I use it, what units are these numbers in, why was it built this way? The best documentation lives right next to the code (in docstrings), includes small examples that are run automatically so they can’t silently go out of date, and is turned into a browsable website by tools.
def slew_time(angle_deg, rate_deg_s=1.0):
"""Time [s] to slew by an angle at a constant rate.
Parameters
----------
angle_deg : float
rate_deg_s : float
Examples
--------
>>> slew_time(90)
90.0
"""
return abs(angle_deg) / rate_deg_sMission software outlives its authors by decades (Voyager’s teams have turned over many times). Undocumented units and assumptions cause real failures, and good documentation is also a requirement in software-assurance standards and a precondition for others reusing your research code.
- 1. A docstring is…
- 2. Why run documentation examples automatically?
- 3. The most important thing to document for a physical quantity is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Layers of documentation
- README: what it is, how to install, a minimal example, how to cite, license.
- Docstrings: every public module, class and function.
- API reference: generated from docstrings.
- Tutorials and how-to guides: task-oriented.
- Explanation: design notes, architecture decision records (ADRs), theory.
- CHANGELOG: what changed, what breaks.
(The “Diátaxis” framework separates tutorials, how-tos, reference and explanation.)
A NumPy-style docstring
def orbital_period(a_km, mu_km3_s2=398600.4418):
"""Orbital period of a Keplerian orbit.
Parameters
----------
a_km : float
Semi-major axis [km].
mu_km3_s2 : float, optional
Gravitational parameter [km^3/s^2]; Earth by default.
Returns
-------
period_s : float
Period [s].
Examples
--------
>>> round(orbital_period(6778.0) / 60, 1)
92.6
"""- 1. The first line of a docstring should be…
- 2. Which section lists exceptions a function can raise?
- 3. Where do installation instructions belong?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.Executable documentation
- doctest:
python -m doctest module.pyorpytest --doctest-modulesruns every>>>example and compares the output. UseELLIPSISandNORMALIZE_WHITESPACEfor robust comparisons, and round floats in examples. - Notebook tutorials executed in CI (C1.9).
- Example scripts in
examples/run as tests.
Generated reference
Sphinx with autodoc, napoleon (NumPy/Google parsing) and intersphinx, or mkdocs with mkdocstrings, build HTML API references from the docstrings and type hints. Host them on Read the Docs or GitHub Pages, rebuilt on every release.
Checking docs automatically
numpydoc’s validation or pydoclint compare signatures with documented parameters (missing, extra, order), interrogate measures docstring coverage, and doctests catch stale examples, all in CI next to the linters (C2.3).
- 1. pytest --doctest-modules…
- 2. Sphinx autodoc builds…
- 3. A signature/doc mismatch checker reports…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Why docs drift
Docs that aren’t executed or checked have no feedback loop: renaming a parameter, adding a term or changing units breaks nothing, so nobody notices. Drift is predictable at the moment code changes, which is exactly when CI can catch it, by co-locating docs with code (docstrings, not wikis), executing examples, and validating signatures.
Writing for engineers
State units, frames and shapes explicitly ((N, 3) array, ECI frame, [km]), preconditions and failure behaviour, numerical accuracy and validity range, and references for the algorithm. Prefer examples to prose. Document why in design notes; the what should be clear from good names.
Versioning docs
Docs should match releases: build per version, record breaking changes in the CHANGELOG, and use deprecation warnings (warnings.warn(..., DeprecationWarning)) for a release cycle before removing an API.
- 1. The root cause of documentation drift is…
- 2. Before removing a public function you should…
- 3. Which belongs in a docstring for a state vector argument?
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Documentation, measured
Exercise 1. The parser extracts the summary, 2 parameters (with types and descriptions including units), 1 return and 1 raise from orbital_period. The signature check reports nothing missing; a planted function with a renamed parameter reports (["y"], ["z"]). Doctests catch one stale example out of two. orbital_period(6778 km) = 92.6 min, matching its own example.
Exercise 2: auditing a small library. In version 1, docstring coverage is 75% (quaternion_norm undocumented). wrap_angle documents a parameter angle that was renamed to a and omits lo. slew_time omits the newly added settle_s, and its doctest still expects 90.0 although the function now returns 95.0 (2 of 3 doctests pass). After fixing the docstrings, coverage is 100%, there are no mismatches and all doctests pass. The generated markdown API reference lists all 4 functions with signatures and summaries.
Documentation in AI, robotics and aerospace
- Interface control documents (ICDs) for telemetry and commands, generated from the same definitions as the code.
- Model cards and dataset datasheets for ML components.
- ROS package docs (rosdoc2) and Doxygen for C++ flight software.
- Research software: a README with install, example and citation (CITATION.cff) makes results reusable.
References
- PEP 257 (docstring conventions); numpydoc docstring guide (numpydoc.readthedocs.io).
- D. Procida. Diátaxis: a systematic framework for technical documentation (diataxis.fr).
- Sphinx documentation (sphinx-doc.org): autodoc, napoleon; mkdocstrings documentation.
- Python documentation: doctest.
- G. Wilson et al. (2014). “Best practices for scientific computing.” PLOS Biology, 12(1).