Repository navigation
docs(website): update the Python guide for SDK 0.9 and v0.5 - #1348
Merged
Merged
Conversation
- Upgrade the scaffolded project to common-grants-sdk 0.9.0 and explain the snake_case constructor rename that make check-types flags. - Validate the generated spec against protocol v0.5 with cg check. - Omit unset optional fields from responses with response_model_exclude_unset. - Replace the hand-rolled custom field classes with a CustomFieldSet plugin, matching the TypeScript guide. - Add bunx, conftest, and coveragerc to the website cspell words. Refs #1310
Contributor
|
🚀 Website Preview Deployed! Preview your changes at: https://pr-1348-common-grants.agile6.workers.dev Built from commit 45cc82d |
- Say that pyright treats the custom-fields type parameter as invariant and show the typed Paginated and Filtered responses to use instead. - Add a module docstring to the plugin snippet so the template's ruff config passes. - Use python3 --version, add the poetry env use tip, list package-lock.json among the scaffold leftovers, and add conftest.py to the project tree. - Scope make check-spec to cg 0.5.0 or later and add the Ctrl+C note.
SnowboardTechie
self-requested a review
October 26, 2026 15:16
SnowboardTechie
approved these changes
Oct 26, 2026
SnowboardTechie
left a comment
Collaborator
There was a problem hiding this comment.
Looked through this, really nice work. I ran the guide end to end against SDK 0.9.0, the fast-api template and #1346's CLI, and every step held.
SnowboardTechie
added a commit
that referenced
this pull request
Oct 28, 2026
…itory (#1340) ### Summary - Part of #1184 - Builds on #1348, now merged; rebased onto `main`. - Depends on common-grants/cg-api-template-fastapi#3 (SDK 0.9 in the template) and on the CLI 0.5.0 release (#1346) for the spec-check step. - Time to review: 10 minutes The Python guide now starts from the [FastAPI template repository](https://github.com/common-grants/cg-api-template-fastapi) instead of `cg init`, which ADR 0029 retires. A reader goes from "Use this template" to a working first request. ### Changes proposed On top of #1348: - Getting started: "Use this template" and `git clone` replace `mkdir` and `cg init`. Adds the template's `make ci` check and three `curl` requests. The project tree matches the template. - Corrections for the template: `schemas/opportunity.py`, the `OpportunityRepository` interface and `create_app()` replace file and class names the template doesn't have. The custom-fields plugin goes in `opportunity.py`, so the Pyright workaround is no longer needed. - "Upgrade the SDK" becomes "Upgrading from an earlier SDK", after the getting-started flow, for projects on SDK 0.8. It uses `^0.9.0` and names the template's real renames: `SearchSorting(sort_by=..., sortOrder=...)` and `PaginatedBodyParams(page_size=...)` in tests. - The spec check runs in synchronized pnpm, npm, and bun tabs. Removes `make check-spec`, which the template doesn't have. - Title: "Using Python". - Removes this page from the `cg init` checklist in `lib/cli/DEVELOPMENT.md`. Kept from #1348: the page structure, the SDK module table and awards note, the snake_case explanation, spec validation, data validation, and the plugin example. ### Context for reviewers Each change is its own commit, so the diff can be read commit by commit. ### Additional information Every documented command ran on a fresh clone of template PR 3 (`3a5cc86`), including the custom-fields plugin. `make ci` passed (109 tests), and the spec check passed through pnpm, npm, and bun with the CLI packed from #1346 (3 award-route warnings). Following the upgrade section on template `main` (`c5e11ca`, SDK 0.8.1) gives a passing `make ci` on SDK 0.9. The website build, lint, format, and spell checks pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updates the "Building a Python API" guide for
common-grants-sdk0.9.0 and protocol v0.5, following the same structure as the TypeScript guide in #1345. Out of scope: moving offcg initto the template repository, which #1184 and #1340 cover.Changes proposed
website/src/content/docs/guides/using-python.mdx:npx @common-grants/cli@0.4.1 init, and an accurate project tree.poetry add common-grants-sdk@0.9.0, a table of SDK modules, and a note that award models andclient.awardsfollow the opportunity patterns. It also explains the 0.9 change from camelCase to snake_case constructor arguments, whichmake check-typesflags in the template.openapi.yamland runcg check spec --protocol-version 0.5.0.response_model_exclude_unset=True, so unset optional fields are left out instead of sent asnull.CustomFieldclasses with aCustomFieldSetplugin built withdefine_plugin, matching the TypeScript guide.website/.cspell.json: addbunx,conftest, andcoveragerc.Context for reviewers
Check most closely that every command works in a fresh project. The
cg checkstep needs CLI 0.5.0 from #1346, which isn't published yet. Until it is, use that PR's build for step 6.Scaffold a project, accepting the defaults:
Upgrade the SDK and confirm the type errors the guide describes. Expect 37 errors:
Rename the camelCase keyword arguments in
services/opportunity.py,services/utils.py, andtests/conftest.py. Expect 0 errors and 9 passing tests:make check-types make testAdd
response_model_exclude_unset=Trueto the three route decorators inroutes/opportunities.py. Then confirm the list response no longer containsnullfields.Copy the plugin snippet to
src/common_grants/schemas/plugin.pyand the usage snippet into any module. Run it, then runpoetry run ruff checkandpoetry run pyrighton both. Assigning the result to alist[OpportunityBase]should fail pyright, andPaginated[Opportunity]should pass, as the guide now says.Generate and check the spec. Expect
Spec is compliant with base spec, with 3 warnings:Build the site:
Note for reviewers:
make checksfails in any scaffolded project, becausetemplate.jsonnever shippedcheck_domain.sh. This guide usesmake check-typesinstead. #1347 fixes the template.Additional information
Output captured from a fresh scaffold with Python 3.11 and Poetry 2.5:
pnpm --filter website run buildpasses, and prettier and cspell pass on the changed files.