Skip to content
✨ Publier v1 is live — a polished docs platform built for the open web.
On this page

SDK reference

Generate the reference pages of a Python, TypeScript, Rust or Go SDK from the language's own documentation tool, so the classes, signatures and doc comments on your site cannot drift from the code.

An SDK reference lists every module, class, function and constant of a library with its signature, parameters and docstring. Written by hand it goes stale with the first release that renames an argument. integrations.sdk generates it instead: your library’s own documentation tool writes an artifact, and Publier turns that artifact into pages on every build. The prose around the reference (when to use which client, worked scenarios) stays a hand-written guide. integrations.openapi does the same for an HTTP API.

Each language is read from the artifact its own documentation tool writes:

LanguageformatArtifact
Pythongriffegriffe’s JSON dump
TypeScripttypedocTypeDoc’s JSON output
Rustrustdocrustdoc’s JSON output
GogoThe JSON publier extract go writes from the module’s source

The quickstart uses Python; the other languages differ only in how the artifact is made and what the reader takes from it.

Quickstart

    1. Dump the package with griffe 2, by static analysis. Pin the major version so the dump’s shape does not change under you:

      Terminal window
      pip install 'griffe>=2,<3'
      griffe dump mypackage -d google -f -s src -o reference/mypackage.griffe.json

      -d is the docstring style your package uses (google, numpy or sphinx). -f writes the parsed docstring sections (arguments, returns, raises, examples) that Publier turns into tables; without it a docstring is shown as plain text. -s is where the package lives. Do not pass --force-inspection.

    2. Declare it in publier.config.yaml:

      publier.config.yaml
      integrations:
      sdk:
      - sdk: mypackage
      language: python
      format: griffe
      source: ./reference/mypackage.griffe.json
      path: /docs/sdk/python

      sdk names the SDK, and entries with the same name are one SDK in several languages. format names the artifact’s kind (the table above). source is a project-relative path or an https:// URL; a URL is fetched on every build and its redirects are followed, so the download link of a release asset works (what source accepts). path is the route the pages live under. It must sit below /docs and cannot share a path with, or nest inside, another generated path of any kind (an integrations.openapi or integrations.cli entry included). One format is allowed per sdk and language.

    3. Run publier dev or publier build. Publier reads the dump and writes the pages into src/content/docs/<path>.

What it reads from a griffe dump

The dump must come from static analysis. A dump made by dynamic inspection (--force-inspection, or a package griffe could only load by importing it) records analysis: "dynamic" on its objects, and Publier refuses it with the object’s path: inspecting a package imports and runs its code, so the artifact would not describe the package alone. Dump one package per entry.

Publier documents a symbol at the path it is exported from, not where it is defined. A class defined in a private _client module and re-exported from the package is mypackage.Client; its page is at Client, its heading ids start with mypackage.Client, and the _client module is not rendered. The rules, in order:

  • A module that lists names in __all__ documents exactly those names.
  • Otherwise a name is public unless it starts with an underscore (griffe’s own is_public verdict is used when the dump has it).
  • A submodule is rendered unless its name starts with an underscore and the parent does not list it.
  • A symbol exported at several paths is documented once, at the shortest.
  • A name imported from outside the package is not documented.

What it generates

PageFile below the folderHolds
The libraryindex.mdxThe package’s root module, titled with the library’s name: its docstring, its submodules, its classes, functions, constants and type aliases
A submodulesub/index.mdx, sub/deeper/index.mdxThe same for each submodule, at its path below the root
A classClient.mdx, sub/Other.mdxThe signature and docstring, then constructors, attributes, properties and methods

The root module is the index page, as the crate’s root page is on docs.rs, so every address is relative to the library: Client is at <path>/Client and a submodule sub at <path>/sub, whatever the package is called. A class that has members gets a page of its own, and a class without any is shown on its module’s page. Functions, constants and type aliases are shown on the module page. A meta.yaml in each folder lists the pages in the sidebar.

Every symbol is an ordinary Markdown heading whose id is its canonical path, so the table of contents, search and llms.txt see every symbol and a link survives a rewording: /docs/sdk/python/Client#mypackage.Client.check. Each page starts with an Overview section whose id is the symbol itself, and the groups (Methods, Attributes and so on) have ids such as mypackage.Client:methods.

A signature is rendered with the type names that Publier documents linked to their pages, so subject: Subject in Client.check links to the Subject page. A type that Publier does not document (a builtin, a name from another package) is shown as plain text. Parameters, return values, raised exceptions and examples from the docstring follow as tables and lists. A function or class decorated with @deprecated (from warnings or typing_extensions) carries a caution with the reason. When griffe recorded a source link, each symbol links to it.

Doc text is text

Docstrings are Markdown written by other people, so Publier writes them again from an allow-list instead of passing them through:

  • Raw HTML is dropped. The text between inline tags is kept, so a <b>bold</b> word shows as a bold word, and a block of HTML disappears.
  • Braces, angle brackets, backticks, import and export lines and other characters that MDX reads as syntax are escaped, so a docstring containing {expr} shows {expr} and never runs it.
  • A link or image keeps its address only when it is http, https, mailto, a relative path or an #anchor. A javascript: or data: link keeps its text and loses its address.
  • Headings inside a docstring move below the symbol’s own heading.
  • Code in a docstring is kept as code, with a fence longer than any backtick run inside it.

TypeScript (TypeDoc)

Make the artifact with TypeDoc’s JSON output, in CI or locally:

Terminal window
typedoc --json docs/typedoc.json src/index.ts

and point an entry at it:

publier.config.yaml
integrations:
sdk:
- sdk: my-sdk
language: typescript
format: typedoc
source: ./docs/typedoc.json
path: /docs/sdk/typescript

A package with several entry points (a root export and subpaths such as my-sdk/next) lists each one in typedoc.json:

typedoc.json
{
"entryPoints": ["src/index.ts", "src/next.ts"],
"skipErrorChecking": true
}

TypeDoc names each entry point’s module after its file, so put @module my-sdk/next in the file’s leading doc comment, or rename the modules in your release script, to name each module by the specifier a reader imports. Publier makes the module named exactly like the package (the "." export) the reference’s root page, and a module named below it (my-sdk/next) becomes next under it, so a scoped package’s pages are at <path>/SignUrlParams and <path>/next/PublicLoaderParams, never under a folder named after the scope. A package with one entry point needs none of this.

TypeDoc 0.28 loads TypeScript up to 6.0, so a project already on TypeScript 7 runs TypeDoc through npx with its own TypeScript instead of adding it to the workspace, and skipErrorChecking keeps it from needing your dependencies:

Terminal window
npx --yes -p typedoc@0.28 -p typescript@6.0 typedoc --options typedoc.json --json docs/typedoc.json

The reader accepts TypeDoc JSON schemaVersion 2.0 (TypeDoc 0.28) and refuses any other, naming the version it found. Modules and namespaces, classes, interfaces, enums, type aliases, functions, variables, constructors, methods, properties and accessors become pages; a type in a signature links to the page that documents it; @param, @returns, @throws, @example and @deprecated fill the sections. Limits: private members are not shown, pages group by kind (TypeDoc @category and @group are ignored), a source link needs an https sources[].url (give TypeDoc a sourceLinkTemplate, or run it in a git checkout with a remote). A {@link} to a documented symbol links to its page; one TypeDoc could not resolve stays as code. TypeDoc writes the source file and, from a git remote, a link to your repository for each symbol. For a private repository, remove the sources keys in your release job before you publish the file (or pass --disableSources), so the artifact names nothing a reader cannot open.

Rust (rustdoc)

Rust’s documentation tool writes JSON when you ask for it. The JSON backend is a nightly-toolchain feature, so make the file in your crate’s own release CI and publish it with the release:

Terminal window
cargo +nightly rustdoc --lib -- -Z unstable-options --output-format json

The file is target/doc/<crate>.json. Point an entry at it:

publier.config.yaml
integrations:
sdk:
- sdk: mycrate
language: rust
format: rustdoc
source: ./reference/mycrate.rustdoc.json
path: /docs/sdk/rust

source is a project-relative path or an https URL. For a crate published on crates.io, docs.rs builds the same file on every publish and serves it zstd-compressed at https://docs.rs/crate/<name>/<version>/json, or …/latest/json for the newest release; Publier decompresses it. A site that reads latest needs no release step of its own: publishing the crate is the delivery. The reader accepts one format_version of the JSON (61 in this release) and refuses any other with the version the file holds, because the format changes between nightlies: use the nightly your Publier release names, or update Publier.

A symbol is documented where it is publicly reachable, so pub use client::Client documents crate::Client and the private client module is not rendered. The pages cover modules, structs, enums with their variants, traits with their methods, functions, constants, type aliases and macros. Inherent methods appear under their type, and the traits a type implements are listed on its page; blanket and auto-trait impls are left out. Intra-doc links such as [`Client`] link to the documented item, lines hidden in doctests (# use x;) are not shown, and code blocks without a language are Rust. Limits: no source links, and # Examples style headings stay inside the item’s text.

Go (publier extract go)

Go has no documentation tool that writes JSON, so the publier CLI reads the module’s source itself. publier extract go parses the module’s own .go files; it downloads no dependencies, type-checks nothing, runs none of your code and needs no Go toolchain, a seat or the network, so it works for private and vendored modules and fits any CI. Run it from inside the module:

Terminal window
publier extract go -o go.json

Commit go.json or publish it with the release, and point an entry at it:

publier.config.yaml
integrations:
sdk:
- sdk: acme
language: go
format: go
source: ./reference/go.json
path: /docs/sdk/go

The artifact carries schemaVersion: 1. Any other version is refused with its number, so regenerate the file with a compatible publier release.

What the pages hold:

  • Every package is a page: acme for the module’s root package, acme.option for ./option, acme.audio.client for ./audio/client. A directory without a package of its own gets an empty page so the tree is whole.
  • A struct, an interface, and a defined type with fields or methods get a page with their fields and methods. Constructors (NewClient), functions, constants and variables are on the package page. A group declared together (const ( A = iota; B )) keeps its declaration and docs on its first name.
  • A signature links every name that refers to a documented symbol to its page. A name from another module links to its page on pkg.go.dev; a name from a package matched by GOPRIVATE, and anything unexported, is plain text.
  • Doc comments keep their Go doc links ([Client.Do]): a link to a documented symbol points to its page and any other link keeps its text. Comment text is sanitised like every reference: raw HTML is dropped and braces, tags and import lines show as text.
  • SDK generators such as Stainless, Speakeasy and Fern write Markdown in doc comments, which is why --comments markdown is the default. Use --comments godoc for a module written to Go’s own syntax (indented code blocks, # Heading lines, - lists, [Name]: url link definitions): the comments are converted to Markdown the way pkg.go.dev reads them, with Markdown characters in plain text escaped so ** stays literal.

Choose what is read with flags:

FlagEffect
[PATTERNS]...Packages to read, relative to the module root: ./... (the default), ./option, ./option/..., or import paths
--exclude <list>Comma-separated package patterns to skip
--exclude-symbols <list>Comma-separated symbols to leave out: Client, Client.Debug, option.WithDebugLog, with *, ? and [...] wildcards (Legacy*). A constant or variable group is left out only when every name in it matches
--goos, --goarch, --tags <list>The platform and build tags that select files (default linux, amd64, no tags)
--internalInclude internal/ packages
--no-parentRequire go.mod in the current directory instead of searching the parents, so a checkout beside others never pulls them in
--comments <syntax>How doc comments are read: markdown (the default) keeps the text as Markdown, godoc reads Go’s doc comment syntax
-o <file>Write the artifact to a file instead of stdout

Packages named main, testdata/, vendor/, nested modules and _test.go files are never read, except that Example functions in test files are attached to what they document. The module root is the nearest go.mod above the current directory, as the go command finds it. References to modules matched by the GOPRIVATE environment variable are marked private so they are not linked to pkg.go.dev.

Limits:

  • One platform per artifact. Files are selected for one GOOS and GOARCH, with cgo off and the release tags go1.1 to go1.60, so the same module gives the same artifact on any machine; a declaration that exists only on another platform is not in it. Run the command once per platform if you need to document more than one; combining them is not supported.
  • Package READMEs and package-level examples are not shown yet.
  • Go identifiers that are not ASCII are accepted, but their heading ids use - for the characters an id cannot hold.

One SDK in several languages

Entries that share an sdk id are one SDK in several languages. Give the Python and TypeScript entries of one library the same id and each its own language and path:

integrations:
sdk:
- { sdk: acme, language: python, format: griffe, source: ./acme.griffe.json, path: /docs/sdk/python }
- { sdk: acme, language: typescript, format: typedoc, source: ./acme.typedoc.json, path: /docs/sdk/typescript }

Every page of an SDK with two or more languages gets a language menu at the top of its sidebar. Choosing a language opens the same page in that language when it has one. Pages are matched by their path below the language’s folder, which is the same in every language because the root module is the index page, so python/Client and typescript/Client match. When the other language has no such page (a type that exists in one language only), the menu opens that language’s index and shows a notice that the page you were reading is not in it, the same notice a version switch uses.

The browser remembers the language you chose, per SDK id, in localStorage. Without storage (a private window) the menu still works and nothing is remembered.

A product tab can point at an SDK instead of a path:

nav:
docs:
products:
- label: SDKs
path: /docs/sdk
tabs:
- { label: Guides, href: /docs/sdk/guides }
- { label: SDK reference, sdk: acme }

The tab opens the index of the language the reader last chose, and the first listed entry’s language until they choose one. An sdk id that matches no entry is a config error. Keep an SDK’s folders under one product, so the tab and the sidebar find them together.

Product, version and status in the navigation come from your configuration, and the reference needs no tab. A docs site with no tab row (a product switcher and a sidebar) shows each language’s folder as a group in the product’s sidebar, and a sidebar scoped to one language (the tab case) starts at the library’s name, the link to its index page, with the language and release menus above it. Put a hand-written hub page at the parent path beside the generated folders, so the group has a page that says what the libraries are and links each language: for entries at /docs/sdk/python and /docs/sdk/typescript, that is src/content/docs/sdk/index.mdx. The hub is outside the folders Publier owns, so it is never rewritten.

What source accepts

source, and each source in a history list, is one of two things:

  • A path relative to the project root, read from the checkout. In publier dev a change to the file regenerates the pages.
  • An https:// URL, fetched on every build. Redirects are followed and must stay on https. The response must be 2xx and arrive within 30 seconds, and its body is the artifact itself, at most 5 MB. A body served as application/zstd (docs.rs does this) is decompressed first, and the limit applies to the decompressed text. Any other answer fails the build, naming the URL and the status.

Publier sends no cookies, token or other credentials with the request, so the URL must be readable by anyone. A private library’s artifact reaches the build as a path instead. Your CI fetches it, with a credential your CI holds; Publier never holds one.

On GitHub, no token can read a private repository’s releases without also reading its code: downloading a release asset needs the repository’s Contents: read permission, for a fine-grained token and a GitHub App alike, and that permission reads every file. Choose by what the site’s CI may see:

  • Publish the artifact as a package, so the site never reads the code. The library’s release job pushes the file to GitHub Packages (the container or npm registry), and the package’s settings give the site’s repository read access. The site’s job downloads it with its own GITHUB_TOKEN, granted packages: read and nothing else, and source names the downloaded file. There is no secret to store, and that token cannot read the library’s repository.
  • Make the artifact in the site’s own build. Check out the library in the site’s CI job, using a credential that job already holds, run the documentation tool, and point source at the file it writes. Nothing leaves your CI, but that job reads the library’s code.
  • Publish the artifact where anyone can read it (the private-repository row below). The reference pages are public on your site anyway, so the artifact shows no more than they do, once you strip the source paths TypeDoc records.

A copy of the artifact committed by hand also works as a path, and it goes stale with the library’s next release.

Deliver the artifact from your release

A manual step in a documentation pipeline is a defect: the reference should change when the library does. Make the artifact in the library’s release job and let the site read it from a stable address:

Where the library is publishedThe release jobsource
npm, Python or Go, from a public repositoryRuns the tool after the registry publish and attaches the file to the repository’s GitHub releasehttps://github.com/<owner>/<repo>/releases/latest/download/<file>
The same, from a private repositoryUploads the file to a public releases repository, on a rolling release marked pre-release so it never becomes that repository’s “latest”https://github.com/<owner>/<releases-repo>/releases/download/<tag>/<file>
crates.ioNothing: docs.rs builds the JSON on publishhttps://docs.rs/crate/<name>/latest/json

Three things to know:

  • A source URL is fetched on every build, so a missing file fails it. Publish the first artifact before you add the entry, and give a library that has not released one yet no entry.
  • Back-fill a release that predates the job by running the same workflow by hand for that tag, so the first build has a file.
  • Run the generator on every change, not only on release, with the upload skipped. A doc comment or entry point the tool cannot read then fails in the library’s own CI and not in the release that needs it.

Pages for every release

Every reference whose release has a label shows a release menu at the top of its sidebar, so readers see which version the pages describe. The label is release, else the version the artifact records (TypeDoc’s package version, rustdoc’s crate version). With one release, the menu lists that one.

history gives the badges. To also keep each earlier release readable, as docs.rs does, set releasePages: true. Every release in history is then written as a full page tree of its own below the current one, the current release stays at path, and the release menu at the top of the sidebar lists them:

integrations:
sdk:
- sdk: acme
language: python
format: griffe
source: https://github.com/acme/acme-python/releases/latest/download/acme.griffe.json
release: "0.3"
releasePages: true
history:
- { label: "0.1", source: https://github.com/acme/acme-python/releases/download/v0.1/acme.griffe.json }
- { label: "0.2", source: https://github.com/acme/acme-python/releases/download/v0.2/acme.griffe.json }

releasePages needs a history, which may be empty (before the first earlier release only the current pages are written). Each label is used in an address, so it may hold letters, digits, ., - and _. The release 0.2 is at <path>/0.2/…, with the same layout as the current one, so <path>/0.2/Client is the page <path>/Client as it was in 0.2. The release menu lists the newest first, marks it latest, and keeps the reader on the same page when the other release has it, else opens that release’s index with the same notice a version switch shows.

An earlier release is documentation of the past, so its pages carry a notice linking the current page, point their canonical address at it, are noindex, and so stay out of search, the sitemap and llms.txt. The symbol search covers the current release only. Each release’s badges compare it with the releases before it.

A release job should not need a documentation edit, so history can instead be one https address of a JSON list that the job keeps up to date, oldest first:

history: https://github.com/acme/acme-python/releases/latest/download/acme.versions.json
[
{ "label": "0.1", "source": "https://github.com/acme/acme-python/releases/download/v0.1/acme.griffe.json" },
{ "label": "0.2", "source": "https://github.com/acme/acme-python/releases/download/v0.2/acme.griffe.json" }
]

The list is fetched on every build with the same rules as a source, and each entry is validated like an inline one. A library released from CI writes the list of the releases before the one it is publishing and attaches it to that release, so latest/download always names the newest release’s list. Leave release out and Publier labels the current release with the version the artifact records (below), so a release needs no change to publier.config.yaml.

The site’s search lists SDK symbols above its page results. Type a name, or dotted segments of one: Client.check and cli.ch both find mypackage.Client.check. Matches are grouped by kind, best first, and follow the same product and version scope as page results. The build writes a symbols.json next to each reference’s pages, so symbol search needs no configuration and works for every format.

Release history badges

Nobody keeps a changelog of the reference by hand, so Publier computes one. List the earlier releases of the same artifact under history, oldest first, and label the release source describes with release:

integrations:
sdk:
- sdk: acme
language: python
format: griffe
source: ./reference/acme-0.3.griffe.json
release: "0.3"
history:
- { label: "0.1", source: ./reference/acme-0.1.griffe.json }
- { label: "0.2", source: ./reference/acme-0.2.griffe.json }

Each history source is read exactly as source is, with the same format, so a path or an https URL works. Labels must be unique and may not repeat release. With a history, the current release needs a label: release when you set it, else the version the artifact records. TypeDoc records packageVersion when it runs with --includeVersion, and rustdoc records crate_version; a leading v is dropped. A griffe dump and the Go extractor’s JSON record no version, so for them release is required. Publier compares the releases by canonical id and puts one line of badges under the symbol’s heading:

BadgeWhen
Added in 0.2The id first appears in release 0.2.
Changed in 0.3The signature differs from the release before; the latest such release is shown.
Deprecated in 0.3The id is first seen deprecated in 0.3.

Whatever the oldest release holds carries no “Added in”, since the history starts there; a deprecation or a changed signature after the oldest release still gets its badge. A re-export, and a member of a re-exported type, is compared under its definition, so moving a public export from one module to another is not an addition. An id that is missing from a release in the middle keeps its first appearance.

integrations.cli takes the same history and release: commands are compared by their path (config set) and flags by command path and flag name (login --token), and a command or flag first seen in a later release is badged in the commands table, the options table and on the command’s page.

The generated folder

Publier owns the folder a path maps to. It deletes and rewrites it on every build, and it writes a .gitignore containing * into it, so the pages are never committed. The build fails, naming the files, if the folder contains a file Publier did not generate, so keep hand-written pages (an introduction to the SDK, a getting-started guide) next to the folder rather than in it. In publier dev, a change to a local dump regenerates the pages.

Product, version and version status come from your navigation by path prefix, as for a hand-written page at that path. Pin the dump to the release it describes: commit it next to your docs, or point source at the release asset’s URL. To document several releases, give each its own entry and path, and list them under the product’s versions as the versioning guide does.

A full dump records absolute file paths and the git state of the machine that made it. Publier reads neither, but the file is a build input you commit or publish, so make the dump in your release job rather than on a laptop, or remove the filepath, relative_filepath, relative_package_filepath and git_info keys before you commit it.