mypy-boto3-sagemaker-edge Type Annotations
mypy-boto3-sagemaker-edge provides type annotations for the boto3 SagemakerEdgeManager client, enhancing type checking capabilities for tools like MyPy, VSCode, and PyCharm. It is automatically generated by the `mypy-boto3-builder` and released frequently, typically in sync with `boto3` versions, to ensure up-to-date and accurate type hints. The current version is 1.42.3.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` (version 8.12.0) and consequently for all generated `mypy-boto3-*` packages. Users must use Python 3.9 or higher.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages in `mypy-boto3-builder` 8.12.0. This change affects how type checkers locate stubs. If you experience issues, ensure your type checker (e.g., MyPy, Pyright) is up-to-date and configured correctly to discover installed stub packages.
- gotcha For optimal type checking, the `mypy-boto3-sagemaker-edge` package version should align closely with your installed `boto3` version. Mismatching versions (e.g., using `mypy-boto3-sagemaker-edge==1.42.x` with `boto3==1.34.x`) can lead to incorrect or missing type hints.
- gotcha To prevent `mypy-boto3-*` packages from becoming runtime dependencies, it is best practice to import the type hints only within an `if TYPE_CHECKING:` block. This avoids shipping type stubs with your production code.
- deprecated The `sms-voice` service was removed and is no longer supported starting with `mypy-boto3-builder` 8.11.0. Users of `sms-voice` should migrate to `pinpoint-sms-voice`. While not directly related to `sagemaker-edge`, this highlights potential service deprecations across the `mypy-boto3` ecosystem.
- gotcha PyCharm users might experience performance issues due to Literal overloads. For better IDE performance, consider installing `boto3-stubs-lite` (if available for the specific service) or disable PyCharm's built-in type checker and rely on `mypy` or `pyright` instead.
Install
-
pip install mypy-boto3-sagemaker-edge boto3
Imports
- SagemakerEdgeManagerClient
from typing import TYPE_CHECKING import boto3 if TYPE_CHECKING: from mypy_boto3_sagemaker_edge.client import SagemakerEdgeManagerClient from mypy_boto3_sagemaker_edge.type_defs import SendHeartbeatRequestRequestTypeDef def get_client() -> SagemakerEdgeManagerClient: return boto3.client("sagemaker-edge")
Quickstart
import boto3
from typing import TYPE_CHECKING
import os
if TYPE_CHECKING:
from mypy_boto3_sagemaker_edge.client import SagemakerEdgeManagerClient
from mypy_boto3_sagemaker_edge.type_defs import SendHeartbeatRequestRequestTypeDef
# Configure AWS credentials and region (replace with your actual configuration)
# For quickstart, using environment variables or placeholder for simplicity
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
os.environ['AWS_REGION_NAME'] = os.environ.get('AWS_REGION_NAME', 'us-east-1')
def main():
# Initialize the Sagemaker Edge Manager client with type hints
client: SagemakerEdgeManagerClient = boto3.client("sagemaker-edge")
# Example: Prepare a request for sending heartbeat with type definition
heartbeat_request: SendHeartbeatRequestRequestTypeDef = {
"AgentMetrics": [], # List of AgentMetricTypeDef
"Models": [] # List of ModelTypeDef
}
try:
# Call an operation on the client
response = client.send_heartbeat(**heartbeat_request)
print("Heartbeat sent successfully.")
print(f"Response Metadata: {response['ResponseMetadata']}")
except client.exceptions.InternalServiceException as e:
print(f"Error sending heartbeat: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
if __name__ == "__main__":
main()