Skip to content

docs(api): Python API reference for cldk 2.0.0 - #17

Open
rahlk wants to merge 4 commits into
astrofrom
docs/issue-14-python-api-reference
Open

rahlk wants to merge 4 commits into
astrofrom
docs/issue-14-python-api-reference

Conversation

@rahlk

@rahlk rahlk commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Closes #14. Supersedes #8.

This PR rewrites the Python API reference (/reference/python-api/) for cldk 2.0.0, and adds two pages: "Results and errors" and "Tree-sitter utilities". It also updates the generator that writes the reference from the SDK docstrings, and it adds a link check to the build.

Merge order

Merge #15 first, then #16, then this PR, back to back.

Commits

The four commits are easier to review one by one:

  1. scripts/gen_api_docs.py and the griffe pin. The generator changes are listed below.
  2. The regenerated reference. Only the blocks between the CLDK:API markers change, plus the two new pages and their sidebar entries.
  3. The authored text of all seven pages. No line between the markers changes in this commit.
  4. starlight-links-validator and the edit link.

Each commit builds.

The pages

Each language page has three parts: an overview, a worked example on a pinned sample project, and the generated reference.

Page What it gives a first-time reader
index.md Install (Python 3.11 to 3.14, quoted extras, SYSTEM_PYTHON), how the three factories fit together, the reference pages, the shared and the language-only methods, analysis levels, the Python value-flow caveat
core.md The factories and their keyword-only parameters, analysis levels, the local and Neo4j backends, the cache rules, an errors table, worked examples on Commons CLI 1.7.0, Flask 3.1.3 and Zod v4.6.7, and the upgrade from 1.5.0
python.md PythonAnalysis on Flask: setup and SYSTEM_PYTHON, the four levels, names, the call graph, a worked example, a task table, Neo4j, errors
java.md JavaAnalysis on Commons CLI: the java extra, the JDK and Maven, test sources, names (fully qualified parameter types), a worked example with taint, what Java refuses, the cache, Neo4j
typescript.md TypeScriptAnalysis on Zod: what a run does to the project, levels, the cache trap, key formats, entrypoints, the Neo4j limit for declaration merging, errors
results.md (new) Bounded results, paging, the result types, how to read a taint result, the default bounds, and the exceptions
treesitter.md (new) TreesitterJava, TreesitterPython, TreesitterSanitizer, and the move from the 1.x source_code mode

Each page also has an "Errors in the generated reference" aside. It lists the SDK docstring errors that break user code, for example page.has_more, sl.truncated, create(String), and the CRUD accessors. Remove each item when the SDK fixes the docstring.

The generator

  • Signatures. They show the keyword-only * and positional-only /. 57 public methods take keyword-only parameters, and the old signatures invited a TypeError. They also show default values as literals (page_size: int = 10000) and @staticmethod or @classmethod, and they wrap long lines.
  • Returns sections. Each one is a single item (returns_multiple_items=False). Before, 103 of 124 split into one bullet per source line.
  • Conversion to Markdown. Sphinx roles, :: literal blocks, RST links and .. deprecated:: become Markdown, Python code fences and Starlight asides. Prose dashes become commas or parentheses.
  • Attribute tables. They merge the class docstring's descriptions, list inherited fields, and hide pydantic internals. Type aliases such as TSType get entries.
  • Method index. Each facade class opens with a linked method index, because the method headings are below the page TOC.
  • New sections. AnalysisLevel and the backend configs (core), the Java projections and enums, and the two new pages.
  • Filters to review. Bracketed spec ids such as "(leg 1.5, E6-E8)" are stripped from the docstring text, because a reader cannot look them up. Two TreesitterSanitizer doctests that fail on cldk 2.0.0 are left out (FAILING_EXAMPLES) while the docstring holds them word for word.
  • Determinism. Output is byte-identical between runs. A run like the deploy run (Python 3.12, python-sdk at v2.0.0, scripts/requirements.txt) gives the committed pages.

How the changes were checked

Open items

  • No workflow builds a pull request. A new SDK release that renames a linked method fails the next deploy, which is the intent of the validator. A pull_request build would catch it earlier.
  • The generated text keeps maintainer notes, benchmark names and modal verbs from the SDK docstrings. Notes on the pages tell readers to ignore them.
  • 22 TypeScriptAnalysis methods have no docstring, so their rows in the method index have no summary.

SDK problems found on the way

The docs work around these, and each one needs an SDK or analyzer fix:

  1. CLDK.python() raises RuntimeError in a run from a virtual environment. codeanalyzer-python reads sys.base_executable instead of sys._base_executable. Present in 1.5.3 through 1.6.2. The pages give the SYSTEM_PYTHON workaround.
  2. TypeScript reuses a cached analysis at any level. It also reuses one after source edits, and a target_files run writes over it. The pages tell readers to pass eager=True.
  3. Python and TypeScript taint and resolve_value raise SelectorNotInGraph below the needed level. They do this for a correct name, instead of giving the level message.
  4. The unresolved ledger of taint is always empty. No backend writes unresolved_dispatch.
  5. The factories raise three different exceptions without project_path.
  6. The docstring errors listed in the asides above.

rahlk added 4 commits October 16, 2026 15:23
…ed types (#14)

scripts/gen_api_docs.py:
- Signatures show the keyword-only '*' and positional-only '/', the
  literal value of a default constant, and @staticmethod, @classmethod
  or @Property. A long signature wraps one parameter per line.
- Docstrings parse with returns_multiple_items=False, so a Returns
  section is one item. Sphinx roles, '::' literal blocks, RST links and
  '.. deprecated::' become Markdown, code fences and Starlight asides.
  Prose dashes become commas or parentheses, because the site uses no
  em-dash and the build turns '--' into one.
- Attribute tables merge the class docstring's Attributes section, list
  the fields of private base classes, and hide pydantic internals.
- Each facade class opens with a linked method index.
- PAGES takes a member allowlist and can hide a module docstring. New
  sections: AnalysisLevel and the backend configs (core), the Java
  projections and enums, a results-and-errors page and a tree-sitter
  page. Module-level aliases such as TSType render as entries.
- Two TreesitterSanitizer doctests that fail on cldk 2.0.0 are left out
  while the docstring holds them word for word (FAILING_EXAMPLES).

scripts/requirements.txt pins griffe==2.3.2, so a regeneration with the
deploy workflow gives the committed pages byte for byte.
Run the updated generator against the cldk 2.0.0 release. Only the
blocks between the CLDK:API markers change on the existing pages. The
new pages results.md and treesitter.md hold their generated block, and
the sidebar lists them under Python SDK.

This supersedes #8, which changed only the version strings.
Each page now gives an overview, a worked example on a pinned sample
project and then the generated reference. Every sample ran on
cldk==2.0.0, and every output comes from that run.

- index.md: install, the three factories, the reference pages, the
  shared and the language-only methods, levels, the Python caveat.
- core.md: factories, analysis levels, backends and Neo4j, the cache,
  errors, worked examples, the upgrade from 1.5.0.
- python.md, java.md, typescript.md: setup per language (SYSTEM_PYTHON,
  the java extra with a JDK and Maven, npm), levels, names and keys, a
  worked example, a task table, the Neo4j backend and errors.
- results.md, treesitter.md: how to read bounded results and taint
  results, the exceptions, and the tree-sitter helpers.

Dead links to /cocoa/ and /guides/common-tasks/ are gone. An aside on
each page lists the SDK docstring errors that break user code, until
the SDK fixes them.
…tro (#14)

Add starlight-links-validator 0.19.2. astro build now fails on a broken
internal link or anchor in any page. The dead /cocoa/ and
/guides/common-tasks/ links on the reference pages had survived because
no check ran.

The "Edit page" link pointed at the main branch, but astro is the
default branch and the only branch that deploys.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python API reference: correct and complete it for cldk 2.0.0

1 participant