Type Annotations for awscrt

0.31.3 · active · verified Sat Mar 28

types-awscrt provides type annotations and code completion for the `awscrt` package, which offers Python 3 bindings for the AWS Common Runtime. It helps with static analysis and IDE support for `awscrt`'s native C libraries. The package version typically mirrors the `awscrt` version it provides types for. It is actively maintained as part of the `mypy_boto3_builder` project. [4, 7]

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic initialization of `awscrt` components. `types-awscrt` enhances this experience by providing static type checking and IDE auto-completion for `awscrt` objects and methods.

import os
import awscrt.io as io
import awscrt.auth as auth
import awscrt.s3 as s3 # Example usage

# Initialize the AWS Common Runtime's I/O and event loop
# types-awscrt provides type hints for these objects
event_loop_group: io.EventLoopGroup = io.EventLoopGroup()
host_resolver: io.DefaultHostResolver = io.DefaultHostResolver(event_loop_group)
bootstrap: io.ClientBootstrap = io.ClientBootstrap(event_loop_group, host_resolver)

# Example for AWS credentials (replace with actual logic, e.g., environment variables or assumed roles)
access_key_id = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_ACCESS_KEY')
secret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET_KEY')
session_token = os.environ.get('AWS_SESSION_TOKEN', None) # Optional

credentials: auth.AwsCredentials = auth.AwsCredentials(
    access_key_id=access_key_id,
    secret_access_key=secret_access_key,
    session_token=session_token
)

print(f"AWS CRT initialized. Credentials loaded (Access Key ID: {credentials.access_key_id}).")
# With types-awscrt installed, a type checker (like MyPy or Pyright) would validate the types above.

view raw JSON →