mypy-boto3-billing

1.42.26 · active · verified Sat Apr 11

mypy-boto3-billing provides type annotations for the AWS boto3 Billing service. It's part of the `mypy-boto3` project, which generates type stubs for all boto3 services. The library is actively maintained, with frequent updates corresponding to boto3 releases and improvements from the `mypy-boto3-builder`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a boto3 Billing client with type annotations from `mypy-boto3-billing` and make a simple API call. It correctly hints the `client` variable for static analysis.

import boto3
from mypy_boto3_billing.client import BillingClient
import os

# Ensure AWS credentials are set up (e.g., via environment variables or ~/.aws/credentials)
# For a runnable example, we'll use dummy credentials if not found
os.environ.setdefault('AWS_ACCESS_KEY_ID', 'test')
os.environ.setdefault('AWS_SECRET_ACCESS_KEY', 'test')
os.environ.setdefault('AWS_SESSION_TOKEN', 'test')
os.environ.setdefault('AWS_DEFAULT_REGION', 'us-east-1')

def get_billing_summary():
    client: BillingClient = boto3.client('billing')
    try:
        response = client.list_billing_groups(
            Filters={'And': [{'AttributeValue': 'active', 'AttributeName': 'Status'}]},
            MaxResults=5
        )
        print("Successfully retrieved billing groups summary.")
        for group in response.get('BillingGroups', []):
            print(f"  Billing Group ARN: {group.get('Arn')}, Name: {group.get('Name')}")
    except Exception as e:
        print(f"Error retrieving billing groups: {e}")

if __name__ == '__main__':
    get_billing_summary()

view raw JSON →