mypy-boto3-codeguruprofiler Type Stubs
mypy-boto3-codeguruprofiler provides comprehensive type annotations for the `boto3` CodeGuruProfiler service, enhancing code quality and developer experience by enabling static type checking with tools like `mypy` and improving IDE autocompletion. Currently at version 1.42.3, it is part of the `mypy-boto3` ecosystem, which sees frequent updates, typically aligning with `boto3` releases and undergoing major revisions with its `mypy-boto3-builder`.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` 8.12.0 (the generator for these stubs), meaning `mypy-boto3-codeguruprofiler` and other generated packages now require Python 3.9 or higher.
- breaking Starting from `mypy-boto3-builder` 8.12.0, all packages migrated to PEP 561 compliant distribution. While individual service packages like `mypy-boto3-codeguruprofiler` still work, the recommended installation for multiple services is `pip install 'types-boto3[SERVICE1,SERVICE2]'`.
- breaking In `mypy-boto3-builder` 8.9.0, TypeDefs for packed method arguments were refactored to use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Additionally, conflicting `Extra` postfixes were moved to the end (`CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). This might impact existing code that directly references these specific TypeDef names.
- gotcha PyCharm users might experience slow performance and high CPU usage due to Literal overloads (issue PY-40997).
- gotcha When using `if TYPE_CHECKING:` guards to make type stubs a `dev` dependency, `pylint` might complain about undefined variables in the runtime branch.
Install
-
pip install mypy-boto3-codeguruprofiler boto3 mypy
Imports
- CodeGuruProfilerClient
from mypy_boto3_codeguruprofiler.client import CodeGuruProfilerClient
- ListProfilingGroupsOutputTypeDef
from mypy_boto3_codeguruprofiler.type_defs import ListProfilingGroupsOutputTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
import os
# Ensure you have AWS credentials configured (e.g., via environment variables or ~/.aws/credentials)
# For a runnable example, we use a default session.
if TYPE_CHECKING:
from mypy_boto3_codeguruprofiler.client import CodeGuruProfilerClient
from mypy_boto3_codeguruprofiler.type_defs import ListProfilingGroupsOutputTypeDef
# Initialize boto3 client with explicit type annotation
# This enables IDE autocompletion and static type checking by mypy.
client: "CodeGuruProfilerClient" = boto3.client("codeguruprofiler")
try:
# Example API call with type-hinted response
response: "ListProfilingGroupsOutputTypeDef" = client.list_profiling_groups()
print("Successfully listed CodeGuruProfiler profiling groups:")
if response.get("profilingGroups"):
for group in response["profilingGroups"]:
print(f" - Name: {group.get('name')}, Arn: {group.get('arn')}")
else:
print(" No profiling groups found.")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your AWS credentials are configured and you have permissions to list CodeGuruProfiler profiling groups.")