PY: make fhirpy the default python client (swap simple/fhirpy examples)#186
Merged
Conversation
ryukzak
commented
Jun 18, 2026
Collaborator
Author
|
Plan for these comments:
|
50980ed to
9590468
Compare
1969c6b to
a98ec29
Compare
- python-r4-us-core: uses the default fhirpy client (no explicit option); the fhirpy AsyncFHIRClient demo is demo.py (renamed from client.py — it is a demo, not a Client class) and serializes via the generated serialize() helper - python-r4 (renamed from python-fhirpy): the simple requests Client, generated with client: "none" - Makefile/CI: rename the python-fhirpy targets/jobs/paths to python-r4 - READMEs: fix client descriptions, unwrap hard-wrapped paragraphs; add a Markdown no-wrap rule to CLAUDE.md - No example uses the deprecated fhirpyClient flag anymore
a98ec29 to
8fc0455
Compare
Collaborator
Author
|
All comments addressed (force-pushed 8fc0455):
Verified: python-r4-us-core mypy clean + 70 offline tests + fhir_types determinism; python-r4 |
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.
Make the
fhirpyasync client the default for the Python examples, and move the simplerequestsclient to its own example. Stacked on #185 (python-example-decouple), so this PR shows only the client swap.Changes
python-r4-us-core→ fhirpy client (default).generate.tsnow usesfhirpyClient: true(keptsnake_case, since the profile tests depend on it).client.py/test_sdk.pyuse the fhirpyAsyncFHIRClient; because the models are snake_case with FHIR camelCase aliases, the client serializes withby_alias=True. The committedfhir_types/is regenerated. Profile/offline tests are unchanged.python-fhirpy→ simplerequestsclient.generate.tsusesfhirpyClient: false+snake_case; it now hosts the reusableClientclass (basic auth + CRUD/search) reused from python-r4-us-core's old client.Generator fix (the interesting bit)
fhirpy's
AsyncFHIRClientmethods are generic overTResource, bound to aResourceProtocolwith a settableresourceType. The camelCase models satisfied this with a realresourceTypefield; the snake_case models expose the discriminator asresource_type(aliasresourceType) and only setresourceTypeat runtime via a__pydantic_init_subclass__hook — invisible to mypy. So fhirpy calls failed type-checking.Fix in the generated
FhirpyBaseModel(assets/api/writer-generator/python/fhirpy_base_model.py): declare aTYPE_CHECKING-only instance annotation— a settable instance attr (satisfies the protocol bound + class access), defaulted (so the pydantic mypy plugin treats it as optional, not a required ctor arg), and TYPE_CHECKING-only (zero runtime change; the hook still sets the real value).
ClassVarwas tried first but can't satisfy a settable protocol member.Verification
mypy --config-file mypy.ini .clean (42 files), 70 offline/profile tests pass,test_sdk.py(fhirpy) imports/type-checks, committedfhir_typesmatches a fresh generation.mypy --strict .clean (154 files).tsc+ biome clean; python writer snapshot test green.test_sdk.pyCRUD (both examples) requires Aidbox → runs in CI.Makefileandsdk-tests.ymlneed no change — the targets/jobs run mypy/pytest/diff-check on whatever each example generates.Note on naming
python-fhirpynow hosts the simplerequestsclient (the fhirpy client moved topython-r4-us-core), so the directory name is now misleading. I left the name as-is per the request; happy to rename it (e.g.python-simple-client) as a follow-up.