Type annotations for boto3 Cost and Usage Report (CUR)
mypy-boto3-cur provides type annotations for the boto3 Cost and Usage Report (CUR) service, ensuring static type checking compatibility for your AWS Python applications. It aligns with the boto3 version 1.42.3 and is generated using mypy-boto3-builder 8.12.0. The library helps catch potential type-related errors at development time.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated this package), support for Python 3.8 was removed across all `mypy-boto3` packages. Ensure your project targets Python 3.9 or newer.
- breaking Major version `8.9.0` of `mypy-boto3-builder` introduced breaking changes to `TypeDef` naming conventions for method arguments (e.g., `CreateDistributionRequestRequestTypeDef` was shortened to `CreateDistributionRequestTypeDef`) and postfix ordering (`Extra` moved to end). While not specific to CUR, such changes apply generally to generated services.
- gotcha For optimal autocompletion and type inference in some IDEs (e.g., VSCode), it is recommended to explicitly type annotate `boto3.Session().client('service_name')` calls with the `Client` type from the specific `mypy-boto3-<service>` package (e.g., `client: CURClient = session.client('cur')`).
- gotcha This library provides type stubs for `boto3`. You must have `boto3` itself installed in your environment for the runtime functionality. This `mypy-boto3-cur` package is purely for static type checking.
Install
-
pip install mypy-boto3-cur -
pip install 'boto3-stubs[cur]'
Imports
- CURClient
from mypy_boto3_cur.client import CURClient
- CostandUsageReportServicePaginatorTypeDef
from mypy_boto3_cur.paginators import CostandUsageReportServicePaginatorTypeDef
- ReportLimitExceededExceptionTypeDef
from mypy_boto3_cur.type_defs import ReportLimitExceededExceptionTypeDef
- ReportDefinitionTypeDef
from mypy_boto3_cur.type_defs import ReportDefinitionTypeDef
- ReportFormatType
from mypy_boto3_cur.literals import ReportFormatType
Quickstart
import boto3
from mypy_boto3_cur.client import CURClient
from mypy_boto3_cur.type_defs import DescribeReportDefinitionsResponseTypeDef
import os
def get_cur_client() -> CURClient:
"""Returns a typed CUR client."""
session = boto3.Session(region_name=os.environ.get('AWS_REGION', 'us-east-1'))
client: CURClient = session.client("cur")
return client
def list_cur_definitions():
"""Lists Cost and Usage Report definitions with type hints."""
cur_client = get_cur_client()
response: DescribeReportDefinitionsResponseTypeDef = cur_client.describe_report_definitions()
print("Report Definitions:")
for report in response.get("ReportDefinitions", []):
print(f" - {report['ReportName']} (Status: {report['ReportStatus']})")
if __name__ == "__main__":
# Ensure AWS credentials/region are configured in environment or ~/.aws/credentials
# For example: export AWS_REGION='us-east-1'
# To run this, you would typically need 'boto3' installed alongside 'mypy-boto3-cur'
list_cur_definitions()