fix(sdk-python): remove mypy-boto3-ssm runtime dependency#165
fix(sdk-python): remove mypy-boto3-ssm runtime dependency#165
Conversation
Replace mypy_boto3_ssm.SSMClient with botocore.client.BaseClient in AwsSsmSecretProvider. The mypy_boto3_ssm package is a dev-only type stub that was imported at runtime, causing ModuleNotFoundError for consumers installing envilder from PyPI without dev extras. Bump version 0.3.0 -> 0.3.1.
Minimal per-approach examples for Python SDK (load, resolve, fluent, env routing) and .NET SDK (resolve, inject, configuration) as file-based apps.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 26 minutes and 16 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (8)
📒 Files selected for processing (2)
WalkthroughThe pull request updates the Python SDK by relaxing the type annotation for the AWS SSM secret provider to accept a generic Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/sdks/python/envilder/infrastructure/aws/aws_ssm_secret_provider.py (1)
3-3: Consider preserving static typing viaTYPE_CHECKING.Switching the runtime import to
botocore.client.BaseClientcorrectly fixes theModuleNotFoundErrorfor consumers without dev extras. However, you lose the precise typing ofSSMClientand now need# type: ignore[attr-defined]on every SSM call.An alternative keeps both runtime safety and strict typing: import
SSMClientonly underTYPE_CHECKING(sinceboto3-stubs[ssm]is already a dev dep perpyproject.toml), and annotate the parameter with a string/forward reference.♻️ Proposed refactor
from __future__ import annotations -from botocore.client import BaseClient +from typing import TYPE_CHECKING + from botocore.exceptions import ClientError from envilder.domain.ports.secret_provider import ISecretProvider +if TYPE_CHECKING: + from mypy_boto3_ssm import SSMClient + class AwsSsmSecretProvider(ISecretProvider): - def __init__(self, ssm_client: BaseClient) -> None: + def __init__(self, ssm_client: "SSMClient") -> None: if ssm_client is None: raise ValueError("ssm_client cannot be None") self._ssm_client = ssm_client @@ try: - response = self._ssm_client.get_parameter( # type: ignore[attr-defined] + response = self._ssm_client.get_parameter( Name=name, WithDecryption=True )Because of
from __future__ import annotations, the annotation never evaluates at runtime, somypy_boto3_ssmstays a pure dev-only dependency and strict mypy retains full method signatures (noattr-definedsuppression needed).Also applies to: 10-10, 20-22
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/sdks/python/envilder/infrastructure/aws/aws_ssm_secret_provider.py` at line 3, Replace the direct runtime import of botocore's BaseClient with a pattern that preserves strict typing: keep the existing runtime import of BaseClient, add a conditional import of SSMClient inside an if TYPE_CHECKING block (from mypy_boto3_ssm.client import SSMClient), and change any parameter/type annotations that currently use BaseClient to use a forward-reference/string annotation "SSMClient" (or annotate using SSMClient under TYPE_CHECKING) so callers avoid needing # type: ignore[attr-defined] while runtime remains safe; reference symbols: BaseClient, SSMClient, TYPE_CHECKING and update the function/method signatures that accept the SSM client accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/sdks/python/envilder/infrastructure/aws/aws_ssm_secret_provider.py`:
- Line 3: Replace the direct runtime import of botocore's BaseClient with a
pattern that preserves strict typing: keep the existing runtime import of
BaseClient, add a conditional import of SSMClient inside an if TYPE_CHECKING
block (from mypy_boto3_ssm.client import SSMClient), and change any
parameter/type annotations that currently use BaseClient to use a
forward-reference/string annotation "SSMClient" (or annotate using SSMClient
under TYPE_CHECKING) so callers avoid needing # type: ignore[attr-defined] while
runtime remains safe; reference symbols: BaseClient, SSMClient, TYPE_CHECKING
and update the function/method signatures that accept the SSM client
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 39e7437b-2a89-4b90-aaa4-35b62cbe6edf
⛔ Files ignored due to path filters (12)
example/sdk/dotnet/1_resolve.csis excluded by none and included by noneexample/sdk/dotnet/2_inject.csis excluded by none and included by noneexample/sdk/dotnet/3_configuration.csis excluded by none and included by noneexample/sdk/dotnet/README.mdis excluded by none and included by noneexample/sdk/python/1_load.pyis excluded by none and included by noneexample/sdk/python/2_resolve.pyis excluded by none and included by noneexample/sdk/python/3_fluent.pyis excluded by none and included by noneexample/sdk/python/4_env_routing.pyis excluded by none and included by noneexample/sdk/python/README.mdis excluded by none and included by noneexample/sdk/python/pyproject.tomlis excluded by none and included by noneexample/sdk/python/uv.lockis excluded by!**/*.lockand included by nonesrc/sdks/python/uv.lockis excluded by!**/*.lockand included bysrc/**
📒 Files selected for processing (2)
src/sdks/python/envilder/infrastructure/aws/aws_ssm_secret_provider.pysrc/sdks/python/pyproject.toml
Simple example scripts don't need a full Python project. A one-line requirements.txt is sufficient.
There was a problem hiding this comment.
Pull request overview
Fixes the Python SDK’s runtime import of a dev-only type-stubs package (mypy_boto3_ssm) by switching the AWS SSM client annotation to a runtime-available type (botocore.client.BaseClient). Also bumps the Python SDK patch version and adds runnable SDK examples for Python and .NET.
Changes:
- Replace
mypy_boto3_ssm.SSMClientruntime import withbotocore.client.BaseClientin the Python AWS SSM provider. - Bump Python SDK version
0.3.0→0.3.1(and update the SDK lockfile). - Add new example projects under
example/sdk/python/andexample/sdk/dotnet/.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/sdks/python/envilder/infrastructure/aws/aws_ssm_secret_provider.py | Removes runtime dependency on mypy_boto3_ssm by using BaseClient typing and a targeted mypy ignore. |
| src/sdks/python/pyproject.toml | Patch version bump to 0.3.1. |
| src/sdks/python/uv.lock | Lockfile updated for the SDK version bump. |
| example/sdk/python/pyproject.toml | Adds a minimal uv-managed Python example project referencing the SDK. |
| example/sdk/python/uv.lock | Adds a lockfile for the Python examples project. |
| example/sdk/python/README.md | Documents how to run the Python examples. |
| example/sdk/python/1_load.py | Example: load + inject into os.environ. |
| example/sdk/python/2_resolve.py | Example: resolve without injecting. |
| example/sdk/python/3_fluent.py | Example: fluent overrides (provider/profile). |
| example/sdk/python/4_env_routing.py | Example: environment-based map routing. |
| example/sdk/dotnet/README.md | Documents how to run the .NET examples. |
| example/sdk/dotnet/1_resolve.cs | Example: resolve secrets and print. |
| example/sdk/dotnet/2_inject.cs | Example: resolve + inject into environment. |
| example/sdk/dotnet/3_configuration.cs | Example: use Envilder as an IConfiguration source. |
Each script declares its own dependencies via inline metadata. Removes requirements.txt — uv run handles everything.
Summary
AwsSsmSecretProviderimportedmypy_boto3_ssm.SSMClientat runtime, but thepackage is a dev-only type stub. Consumers installing
envilderfrom PyPI gotModuleNotFoundError. This PR fixes the import, bumps to 0.3.1, and adds SDKusage examples for Python and .NET.
Changes
fix(sdk-python)
mypy_boto3_ssm.SSMClientwithbotocore.client.BaseClientinAwsSsmSecretProvider—botocoreis already bundled withboto3# type: ignore[attr-defined]onget_parametercall (dynamic method)0.3.0→0.3.1fix(sdk)
AWSSDK.SimpleSystemsManagementpackage reference from .NET examplesdocs(sdk)
example/sdk/python/— 4 self-contained scripts using PEP 723 inlinemetadata (
uv run 1_load.py, no setup required)example/sdk/dotnet/— 3 file-based .NET 10 apps (dotnet run 1_resolve.cs)docs(sdk-python)
0.3.1changelog entry indocs/changelogs/sdk-python.mdTesting
make check-sdk-pythonpasses (black, isort, mypy)make test-sdk-python— 54/54 tests passuv run 1_load.pyresolves secrets successfully