mypy-boto3-s3control
mypy-boto3-s3control provides type annotations for the AWS Boto3 S3Control client, including explicit type hints for clients, paginators, waiters, and TypeDefs. This significantly enhances static analysis, code completion, and overall developer experience in IDEs like VSCode and PyCharm when working with the AWS SDK for Python (Boto3). It is part of the `mypy-boto3` ecosystem, which generates these stubs based on the latest Boto3 service definitions, with regular updates following Boto3 releases.
Warnings
- breaking Python 3.8 support was removed for all `mypy-boto3` packages, including `mypy-boto3-s3control`, starting with `mypy-boto3-builder` version 8.12.0.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages with `mypy-boto3-builder` 8.12.0. While this is generally an improvement for type checker discovery, it might affect custom build systems or older IDE integrations that expect different package structures for stub files.
- breaking TypedDicts for packed method arguments may have shorter names starting with `mypy-boto3-builder` version 8.9.0. For example, `CreateDistributionRequestRequestTypeDef` might become `CreateDistributionRequestTypeDef`. This could break code explicitly referencing the older, longer TypeDef names.
- gotcha `mypy-boto3-s3control` provides *only* type annotations. You must also install `boto3` for the actual runtime functionality of the AWS SDK for Python.
- gotcha For optimal type checking and auto-completion, especially if not using the `boto3-stubs` package with extras, explicitly annotating the client variable with `S3ControlClient` (e.g., `client: S3ControlClient = boto3.client("s3control")`) is highly recommended.
- gotcha PyCharm users might experience slow performance with Literal overloads. The `mypy-boto3` documentation suggests using the `lite` versions of stub packages to mitigate this issue or disabling PyCharm's internal type checker in favor of external tools like `mypy` or `pyright`.
Install
-
pip install mypy-boto3-s3control boto3 -
pip install 'boto3-stubs[s3control]' boto3
Imports
- S3ControlClient
from mypy_boto3_s3control.client import S3ControlClient
- ListAccessPointsForDirectoryBucketsPaginator
from mypy_boto3_s3control.paginator import ListAccessPointsForDirectoryBucketsPaginator
- CreateAccessPointRequestRequestTypeDef
from mypy_boto3_s3control.type_defs import CreateAccessPointRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_s3control.client import S3ControlClient
from mypy_boto3_s3control.type_defs import ListAccessPointsResponseTypeDef
def get_s3control_client() -> S3ControlClient:
"""Returns a typed S3Control client."""
# boto3.client returns an untyped client by default.
# The explicit type annotation (S3ControlClient) provides type checking.
client: S3ControlClient = boto3.client("s3control")
return client
def list_access_points(client: S3ControlClient, account_id: str) -> ListAccessPointsResponseTypeDef:
"""Lists S3 access points with type checking."""
response: ListAccessPointsResponseTypeDef = client.list_access_points(
AccountId=account_id
)
return response
if __name__ == "__main__":
# Replace with your AWS account ID
aws_account_id = "012345678901" # os.environ.get('AWS_ACCOUNT_ID', '012345678901')
s3_control_client = get_s3control_client()
print(f"S3Control Client type: {type(s3_control_client)}")
# Example usage (will typically require valid credentials and permissions)
try:
access_points = list_access_points(s3_control_client, aws_account_id)
print(f"Found {len(access_points.get('AccessPointList', []))} S3 access points.")
except Exception as e:
print(f"Error listing access points (credentials/permissions might be needed): {e}")