Type annotations for boto3 Batch

1.42.76 · active · verified Sun Mar 29

mypy-boto3-batch provides comprehensive type annotations for the AWS Boto3 Batch service, generated automatically with mypy-boto3-builder. It enhances development experience by enabling static type checking with tools like MyPy, Pyright, and improving autocompletion in IDEs such as VSCode and PyCharm. The library is actively maintained, with updates released frequently to align with new Boto3 versions and address issues.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted Batch client and perform basic operations like describing job queues and listing jobs using a paginator. The `TYPE_CHECKING` block ensures that `mypy-boto3-batch` is only a development dependency. Remember that `boto3` itself needs to be configured with AWS credentials to make actual API calls.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_batch.client import BatchClient
    from mypy_boto3_batch.type_defs import DescribeJobQueuesResponseTypeDef

    # Example of a Paginator import
    from mypy_boto3_batch.paginators import ListJobsPaginator


def get_batch_client() -> 'BatchClient':
    """Returns a type-hinted boto3 Batch client."""
    return boto3.client("batch")


def describe_queues() -> 'DescribeJobQueuesResponseTypeDef':
    """Describes Batch job queues with type hints."""
    client: BatchClient = get_batch_client()
    response = client.describe_job_queues()
    print(f"Job Queues: {len(response['jobQueues'])}")
    return response


def list_all_jobs():
    """Lists all jobs using a paginator with type hints."""
    client: BatchClient = get_batch_client()
    paginator: ListJobsPaginator = client.get_paginator('list_jobs')
    for page in paginator.paginate(jobQueue='example-queue'): # Replace 'example-queue' with an actual queue
        for job in page.get('jobSummaryList', []):
            print(f"Job ID: {job['jobId']}, Name: {job['jobName']}")

# Example usage (requires AWS credentials and an existing Batch setup)
if __name__ == '__main__':
    # This code will execute if you have AWS credentials configured
    # and an AWS Batch environment. For type checking, no actual AWS call is needed.
    # To run this, ensure boto3 is configured, e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
    # Or by using 'aws configure'
    try:
        queues_response = describe_queues()
        # You can add more complex logic here
        # list_all_jobs() # Uncomment to test paginator, requires a valid jobQueue
    except Exception as e:
        print(f"Error interacting with AWS Batch (this is expected if AWS credentials/resources are not set up): {e}")

view raw JSON →