mypy-boto3-finspace Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-finspace provides type annotations (type stubs) for the boto3 Finspace service, enabling static type checking with tools like MyPy. It ensures your boto3 code interacting with AWS Finspace is type-safe. The current version is 1.42.3, which aligns with a specific boto3 version, and updates are released regularly in sync with new boto3 releases and the underlying mypy-boto3-builder.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a boto3 Finspace client and use it with type hints provided by `mypy-boto3-finspace`. The `TYPE_CHECKING` guard ensures that type stub imports do not affect runtime behavior. It fetches a list of Finspace environments, illustrating type-safe interaction.

import boto3
import os
from typing import TYPE_CHECKING

# Only import type stubs when type checking
if TYPE_CHECKING:
    from mypy_boto3_finspace.client import FinspaceClient
    from mypy_boto3_finspace.type_defs import ListEnvironmentsResponseTypeDef

# Create a boto3 client (runtime object)
client = boto3.client(
    "finspace",
    aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
    aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
    region_name=os.environ.get('AWS_REGION', 'us-east-1')
)

# Type hint the client for static analysis (optional at runtime, crucial for mypy)
if TYPE_CHECKING:
    finspace_client: FinspaceClient = client
else:
    finspace_client = client

try:
    # Use the client with type-checked arguments and return types
    response: ListEnvironmentsResponseTypeDef = finspace_client.list_environments()
    print("Finspace Environments:")
    for env in response.get('environments', []):
        print(f"  - {env.get('name')} ({env.get('status')})")
except Exception as e:
    print(f"Error listing Finspace environments: {e}")

view raw JSON →