Skip to main content

Documentation style guide

How documentation is written and enforced in the sasvi SDK. Two layers: docstrings (in code, the source of truth for the API reference) and prose docs (the narrative under website/docs/).

Docstrings​

Every public symbol in src/sasvi carries a Google-style docstring. This is gate-enforced by ruff D (Google convention) and by tools.check_docstrings (the authoritative AST checker, because ruff's D rules silently skip some large modules). tests/, tools/, scripts/, and the sasvi.types re-export shims are exempt.

What every symbol needs​

SymbolRequirement
ModuleOne-line (or short) summary of the module's role.
ClassOne sentence on what the object represents.
Function / methodSummary line; an Args: entry for every parameter, *args and **kwargs included; Returns: for anything non-trivial.
@propertyDescribe the value, not the type. Write """The alert's Data Hub id.""", never """The id.""".
__init__Args: documenting each parameter.
Magic methodsA brief real sentence ("""Return a debug representation.""").
@overload stubNo docstring (ruff D418 forbids it); document the implementation.

tests/test_handwritten_contracts.py enforces the Args: rule on every public handwritten function and method in src/sasvi. Each parameter needs its own name: entry in the Args: section; a name that only appears in the prose does not count, and there is no list of exceptions. When a **kwargs is passed on to another call, its entry names that call. The CLI is exempt because Typer commands document their options in help= strings.

Raises: is required​

The SDK's contract is that failures surface as typed sasvi.errors subclasses. Every public method that raises must document it, naming the concrete type:

def create(self, *, body: Any) -> DataStoreRecord | None:
"""Create a data store from a raw payload.

Args:
body: Raw or generated data-store create payload.

Returns:
The created data-store record, or ``None`` when the server returns no body.

Raises:
AdminOperationError: If the server rejects the payload.
"""

Only document raises the method actually produces. Trace the raise sites, and never fabricate a Raises: for an error that cannot occur.

Style rules​

  • Imperative mood for the summary line ("Return...", "Create...", not "Returns...").
  • Line length 100 (ruff-enforced); wrap long docstrings.
  • No F-<n> fix numbers in a public docstring. The API reference is generated from docstrings, and a reader cannot follow the number anywhere. Say what the code does in plain words and put the history in a # F-<n>: comment directly below the docstring. tools.check_docstrings fails the gate on a public module, class, callable or attribute docstring that contains one. Private names are exempt.
  • Match the surrounding file's idiom; don't introduce a second style in one file.

Prose docs (website/docs/)​

The narrative layer. The information architecture:

KindLocationPurpose
Quickstart / conceptswebsite/docs/, website/docs/concepts/Orientation and mental models.
Guideswebsite/docs/Guides/Task-oriented, per-domain how-tos with runnable examples.
Recipeswebsite/docs/Guides/recipes/Short, single-task snippets.
API referencewebsite/docs/api/generated/Generated from docstrings. Never hand-edited.

Rules​

  • Do not hand-write API pages. The reference under website/docs/api/generated/ is produced by scripts/build_docs.sh. Write narrative in a guide and link to the generated page.
  • Every public module goes in pydoc-markdown.yml. Packages belong under packages:, single-file modules under modules:. Listing a package under modules: renders its __init__.py alone, so every re-exported class comes out as a bare heading with no signature and no members. That is how the whole feature layer came to be published as a list of names.
  • A private module that defines a public export also goes under modules:. RequestPreview is exported from sasvi.search but defined in sasvi._preview, so without an entry it renders nowhere. tests/test_docs_coverage.py::test_every_public_export_appears_in_the_reference fails when a name in an __all__ has no heading.
  • Use current API in every example. The async convention is the _async suffix (never the old a-prefix); the admin namespace is client.admin (never client.config). Verify method names against the source.
  • Link to generated reference pages at ../api/generated/sasvi/<pkg>/, not to hand-written API pages.
  • Docusaurus builds with onBrokenLinks: "throw" and onBrokenAnchors: "throw", so a link to a missing page or a missing heading fails CI. Keep both valid.
  • Every new page goes in website/sidebars.ts. Docusaurus routes a page whether or not the sidebar names it, so an unlisted page is built, indexed and in the sitemap while no navigation reaches it. Add it there, or to the exclude list in website/docusaurus.config.ts if it is internal. tests/test_docs_coverage.py::test_every_docs_page_is_reachable_or_excluded fails otherwise.
  • No em dashes in prose. End the sentence, or use a comma for a subordinate clause. In a list item, write **Term.** Detail.
  • Headings are sentence case. ## Working with alerts, not ## Working With Alerts.
  • Nothing checks those last two automatically; they are enforced in review.

Writing a new guide​

Mirror an existing strong guide (website/docs/Guides/documents.md, website/docs/Guides/alerts.md): a short intro, task-oriented sections with fenced python examples, a note on sync-only vs async surfaces where relevant, an error-behavior subsection, and a "Go further" footer linking to the generated reference and the related guides. Recipes and concept pages end the same way. Add the new guide to the "How-to Guides" category in website/sidebars.ts.

Python snippets are checked​

tests/test_docs_snippets.py parses every ```python block under website/docs/ and holds it to the real package: the block must parse, from sasvi... imports must resolve, and SVIClient(...) / SVIConfig(...) keywords must match the actual signature. A backticked name ending in Error, Report, Record, Handle, Service, Manager, Policy, Provider or Config must exist in the SDK, so prose cannot invent a type either.

Two escapes:

  • A block whose first line is # Before shows an API that is gone. It is skipped, because it is meant not to work any more.
  • SVIClient(...) with a literal ellipsis is read as a placeholder, not a call.

A block can also be run, not only parsed. Put <!-- executed: <group> --> on the line before the fence and tests/test_docs_executed_snippets.py executes every fence in that group in order, in one namespace, against an httpx2.MockTransport; the recipe Mock the SDK in pytest uses the mock-transport group. Opt an example in when its output is part of the claim the page makes.