Skip to content

docs(website): start the Python guide from the FastAPI template repository - #1340

Merged
SnowboardTechie merged 8 commits into
mainfrom
bryan/1184-using-python-guide
Oct 28, 2026
Merged

SnowboardTechie merged 8 commits into
mainfrom
bryan/1184-using-python-guide

Conversation

@SnowboardTechie

@SnowboardTechie SnowboardTechie commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The Python guide now starts from the FastAPI template repository 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.

@github-actions github-actions Bot added website Issues related to the website typescript Issue or PR related to TypeScript tooling labels Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Website Preview Deployed!

Preview your changes at: https://pr-1340-common-grants.agile6.workers.dev

Built from commit a8cf95f

@github-actions github-actions Bot added the cli Issue or PR related to the @common-grants/cli library label Oct 22, 2026
@SnowboardTechie
SnowboardTechie force-pushed the bryan/1184-using-python-guide branch from b6eef9b to f717929 Compare October 26, 2026 18:27
@SnowboardTechie
SnowboardTechie changed the base branch from main to karina/1310-update-python-guide October 26, 2026 18:27
@SnowboardTechie
SnowboardTechie marked this pull request as ready for review October 26, 2026 19:07
@SnowboardTechie SnowboardTechie linked an issue Oct 26, 2026 that may be closed by this pull request
5 of 6 tasks
karinamzalez added a commit that referenced this pull request Oct 27, 2026
### Summary

- Fixes #1310
- Time to review: 15 minutes

Updates the "Building a Python API" guide for `common-grants-sdk` 0.9.0
and protocol v0.5, following the same structure as the TypeScript guide
in #1345. Out of scope: moving off `cg init` to the template repository,
which #1184 and #1340 cover.

### Changes proposed

- `website/src/content/docs/guides/using-python.mdx`:
- **Setup:** prerequisites as a note, `npx @common-grants/cli@0.4.1
init`, and an accurate project tree.
- **Upgrade the SDK (new):** `poetry add common-grants-sdk@0.9.0`, a
table of SDK modules, and a note that award models and `client.awards`
follow the opportunity patterns. It also explains the 0.9 change from
camelCase to snake_case constructor arguments, which `make check-types`
flags in the template.
- **Validate your spec (new):** generate `openapi.yaml` and run `cg
check spec --protocol-version 0.5.0`.
- **Implementing services:** add `response_model_exclude_unset=True`, so
unset optional fields are left out instead of sent as `null`.
- **Adding custom fields:** replace the hand-written `CustomField`
classes with a `CustomFieldSet` plugin built with `define_plugin`,
matching the TypeScript guide.
- `website/.cspell.json`: add `bunx`, `conftest`, and `coveragerc`.

### Context for reviewers

**Check most closely that every command works in a fresh project.** The
`cg check` step needs CLI 0.5.0 from #1346, which isn't published yet.
Until it is, use that PR's build for step 6.

1. Scaffold a project, accepting the defaults:

   ```bash
   mkdir common-grants-api && cd common-grants-api
   npx @common-grants/cli@0.4.1 init --template fast-api
   make install
   ```

2. Upgrade the SDK and confirm the type errors the guide describes.
Expect 37 errors:

   ```bash
   poetry add common-grants-sdk@0.9.0
   make check-types
   ```

3. Rename the camelCase keyword arguments in `services/opportunity.py`,
`services/utils.py`, and `tests/conftest.py`. Expect 0 errors and 9
passing tests:

   ```bash
   make check-types
   make test
   ```

4. Add `response_model_exclude_unset=True` to the three route decorators
in `routes/opportunities.py`. Then confirm the list response no longer
contains `null` fields.
5. Copy the plugin snippet to `src/common_grants/schemas/plugin.py` and
the usage snippet into any module. Run it, then run `poetry run ruff
check` and `poetry run pyright` on both. Assigning the result to a
`list[OpportunityBase]` should fail pyright, and
`Paginated[Opportunity]` should pass, as the guide now says.
6. Generate and check the spec. Expect `Spec is compliant with base
spec, with 3 warnings`:

   ```bash
   make gen-openapi
npx @common-grants/cli@0.5.0 check spec openapi.yaml --protocol-version
0.5.0
   ```

7. Build the site:

   ```bash
   pnpm --filter website run build
   ```

Note for reviewers: `make checks` fails in any scaffolded project,
because `template.json` never shipped `check_domain.sh`. This guide uses
`make check-types` instead. #1347 fixes the template.

### Additional information

Output captured from a fresh scaffold with Python 3.11 and Poetry 2.5:

```
# After poetry add common-grants-sdk@0.9.0
$ make check-types
37 errors, 0 warnings, 0 informations

# After renaming the keyword arguments
$ make check-types
0 errors, 0 warnings, 0 informations
$ make test
9 passed, 1 warning

# Plugin snippet
$ poetry run python -m common_grants.use_plugin
12345
$ poetry run pyright src/common_grants/schemas/plugin.py src/common_grants/use_plugin.py
0 errors, 0 warnings, 0 informations
$ poetry run ruff check src/common_grants/schemas/plugin.py
All checks passed!

# Spec check (CLI build from #1346)
$ cg check spec openapi.yaml --protocol-version 0.5.0
0 errors, 3 warnings
Routes missing
  GET /common-grants/awards (warning)
  POST /common-grants/awards/search (warning)
  GET /common-grants/awards/{awdId} (warning)
Spec is compliant with base spec, with 3 warnings
```

`pnpm --filter website run build` passes, and prettier and cspell pass
on the changed files.
Base automatically changed from karina/1310-update-python-guide to main October 27, 2026 16:32
…itory

Replace the cg init setup with Use this template and git clone, add the template's make ci check and curl requests, and match the project tree to the template.
…e template

The template has no schemas re-export, OpportunityService, or plugin.py. Point to opportunity.py, the OpportunityRepository seam and create_app(), note that routes already omit unset fields, and drop the Pyright workaround the template's Opportunity alias makes unnecessary.
The template now depends on SDK 0.9, so the upgrade applies only to projects from an earlier template. Move it after the getting-started flow, use the ^0.9.0 range, and name the template's real camelCase arguments.
Put cg check spec in synchronized package-manager tabs and drop make check-spec, which the template does not have.
@SnowboardTechie
SnowboardTechie force-pushed the bryan/1184-using-python-guide branch from 67653fd to 04b8df8 Compare October 27, 2026 17:35

@karinamzalez karinamzalez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved! Will you merge this after common-grants/cg-api-template-fastapi#3 lands?

Quick question: The guide now pins @common-grants/cli@0.5.0 check spec in all three tabs (lines 124, 131, 138). The "If the check spec command was updated" checklist in lib/cli/DEVELOPMENT.md still lists only the FastAPI template Makefile, so the next CLI release could miss this page. Could you add this guide to that checklist?

@@ -1,23 +1,23 @@
---
title: Building a Python API

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question! the title becomes “Using Python”, but the TypeScript guide is still titled “Building a TypeScript API”. Should we match the names?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They'll match once #1341 merges. That PR retitles the TypeScript guide to "Using TypeScript".

@SnowboardTechie

Copy link
Copy Markdown
Collaborator Author

@karinamzalez Yes, I'll merge this once common-grants/cg-api-template-fastapi#3 lands. I added this guide to the check spec checklist in lib/cli/DEVELOPMENT.md in a8cf95f.

@SnowboardTechie
SnowboardTechie merged commit 9e160b1 into main Oct 28, 2026
7 checks passed
@SnowboardTechie
SnowboardTechie deleted the bryan/1184-using-python-guide branch October 28, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Issue or PR related to the @common-grants/cli library typescript Issue or PR related to TypeScript tooling website Issues related to the website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Website] Repoint the TypeScript and Python guides to the template repositories

2 participants