mypy-boto3-codeguru-security
mypy-boto3-codeguru-security provides type annotations for the `boto3` AWS SDK for Python, specifically for the CodeGuruSecurity service. These stubs enable static type checkers like Mypy to validate `boto3` calls, improving code quality and catching errors early. It is part of the `mypy-boto3-builder` ecosystem, which maintains a regular release cadence to stay in sync with `boto3` updates. The current version is 1.42.3.
Warnings
- breaking The `mypy-boto3-builder` (which generates this stub package) dropped support for Python 3.8 in version 8.12.0. All generated stub packages now require Python 3.9 or newer.
- gotcha This package provides only type stubs and does not install `boto3` itself. You must explicitly install `boto3` alongside this stub package for your application to function at runtime.
- breaking For advanced users who directly import `TypeDef` objects, `mypy-boto3-builder` version 8.9.0 introduced breaking changes to TypeDef naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`).
- gotcha AWS service names can occasionally change or be deprecated (e.g., 'sms-voice' to 'pinpoint-sms-voice' in older builder versions). While 'codeguru-security' is stable, be aware that the specific stub package you need might change if the underlying AWS service name evolves.
Install
-
pip install mypy-boto3-codeguru-security boto3 -
pip install mypy
Imports
- CodeGuruSecurityClient
from mypy_boto3_codeguru_security.client import CodeGuruSecurityClient
- ListFindingsResponseTypeDef
from mypy_boto3_codeguru_security.type_defs import ListFindingsResponseTypeDef
Quickstart
import boto3
from mypy_boto3_codeguru_security.client import CodeGuruSecurityClient
from mypy_boto3_codeguru_security.type_defs import ListFindingsResponseTypeDef
def get_codeguru_security_client() -> CodeGuruSecurityClient:
"""Initializes and returns a CodeGuruSecurity client with type hints."""
# boto3 automatically picks up credentials from environment variables or IAM roles
# For local testing, ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN (optional) are set.
return boto3.client("codeguru-security")
def list_all_findings(client: CodeGuruSecurityClient) -> None:
"""Lists CodeGuruSecurity findings and prints their IDs."""
print("Listing CodeGuruSecurity findings...")
paginator = client.get_paginator("list_findings")
page_iterator = paginator.paginate()
found_findings = 0
for page in page_iterator:
page_data: ListFindingsResponseTypeDef = page
for finding in page_data.get("findings", []):
print(f" Finding ID: {finding.get('id')}")
found_findings += 1
if found_findings == 0:
print(" No findings found.")
else:
print(f"Found {found_findings} findings.")
if __name__ == "__main__":
# Example usage
codeguru_client = get_codeguru_security_client()
list_all_findings(codeguru_client)