Type annotations for boto3 RAM service
mypy-boto3-ram provides type annotations for the AWS Resource Access Manager (RAM) service for boto3, ensuring type-checking and autocompletion in IDEs. It is currently at version 1.42.59, and is part of the actively maintained `mypy-boto3` family, which frequently updates to match new `boto3` versions and includes features from `mypy-boto3-builder`.
Warnings
- breaking Python 3.8 support has been removed in mypy-boto3-builder version 8.12.0 and later packages. Users on Python 3.8 will need to upgrade to Python 3.9+ or use an older version of mypy-boto3-ram.
- breaking TypeDef names were changed in mypy-boto3-builder 8.9.0. This includes shortening packed method argument TypeDefs (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and moving `Extra` postfixes for conflicting names. Code relying on explicit TypeDef imports might break.
- gotcha Mismatching versions of `boto3` and `mypy-boto3-ram` can lead to incorrect type hints or `mypy` errors. `mypy-boto3-ram` versions generally correspond to compatible `boto3` versions (e.g., `mypy-boto3-ram 1.42.59` is for `boto3 1.42.59`).
- gotcha While `mypy-boto3-ram` is a standalone package, for comprehensive `boto3` type-hinting, especially for `Session.client()` and `Session.resource()` overloads without explicit annotations, installing `boto3-stubs[ram]` is often recommended. Standalone packages might require more explicit type annotations in some IDEs.
- gotcha Pylint might report 'undefined variable' errors when using `from typing import TYPE_CHECKING` blocks to conditionally import `mypy-boto3` types. This is a known issue with Pylint's interaction with `TYPE_CHECKING`.
- gotcha PyCharm users might experience slow performance or high CPU usage due to `Literal` overloads in `boto3-stubs` packages. The `lite` versions of the stubs are provided as a workaround.
Install
-
pip install mypy-boto3-ram -
pip install 'boto3-stubs[ram]'
Imports
- RAMClient
from mypy_boto3_ram import RAMClient
Quickstart
import boto3
from mypy_boto3_ram import RAMClient
import os
def list_resource_shares_typed() -> None:
# It's recommended to explicitly type the client for full type-checking benefits
# Especially if not installing the full 'boto3-stubs' package
client: RAMClient = boto3.client("ram", region_name=os.environ.get('AWS_REGION', 'us-east-1'))
# The client methods are now fully type-checked
response = client.list_resource_shares(resourceOwner='SELF')
print("Resource Shares:")
for share in response.get('resourceShares', []):
print(f" - {share['name']} ({share['status']})")
if __name__ == "__main__":
# Ensure AWS credentials/config are set up, e.g., via environment variables or ~/.aws/credentials
# For this example, we're using a dummy region name; replace with actual if needed.
list_resource_shares_typed()