Type annotations for boto3 Batch

raw JSON →
1.42.76 verified Tue May 12 auth: no python install: verified

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.

pip install boto3 mypy-boto3-batch
error ModuleNotFoundError: No module named 'mypy-boto3-batch'
cause The `mypy-boto3-batch` library or its parent `boto3-stubs` package, which provides type annotations for the AWS Batch service, has not been installed in your Python environment.
fix
Install the library using pip: python -m pip install mypy-boto3-batch or python -m pip install 'boto3-stubs[batch]'.
error ImportError: cannot import name 'BatchClient' from 'mypy_boto3' (or similar for 'batch')
cause You are attempting to import the `BatchClient` type directly from the top-level `mypy_boto3` package or an incorrect submodule. The type annotations for specific AWS services like Batch are located in their own dedicated `mypy-boto3-<service_name>` package.
fix
Import BatchClient from the specific mypy_boto3_batch.client module: from mypy_boto3_batch.client import BatchClient.
error mypy: Unexpected keyword argument "<argument_name>" for "<method_name>" of "BatchClient"
cause Mypy cannot correctly infer the types for `boto3` client methods or their arguments when the `boto3` client is not explicitly type-hinted with the `mypy-boto3-batch` types. This often happens if the generic `boto3.client()` return type is used.
fix
Explicitly type-hint your Batch client with BatchClient from mypy_boto3_batch.client. For example: from mypy_boto3_batch.client import BatchClient import boto3 def get_batch_client() -> BatchClient: return boto3.client('batch') batch_client: BatchClient = get_batch_client().
error mypy: Cannot find implementation or library stub for module 'boto3'
cause Mypy is unable to locate the installed `boto3-stubs` or `mypy-boto3-batch` type annotation packages. This can be due to an incorrect Mypy configuration, environment issues (e.g., virtual environment not active), or Mypy not following imports correctly.
fix
Ensure boto3-stubs (or mypy-boto3-batch) is installed in the environment Mypy is running in. Verify your Mypy configuration (e.g., mypy.ini) to ensure mypy_path is correctly set if needed, or temporarily remove --ignore-missing-imports to surface more specific errors. python -m pip install 'boto3-stubs[batch]'.
breaking Support for Python 3.8 has been removed across all `mypy-boto3-*` packages, starting with `mypy-boto3-builder` version 8.12.0.
fix Upgrade your Python environment to 3.9 or newer.
breaking TypeDef naming conventions were changed, potentially affecting custom code that directly imports and uses generated TypeDefs. For instance, `CreateDistributionRequestRequestTypeDef` might become `CreateDistributionRequestTypeDef`, and `Extra` postfixes are moved to the end.
fix Review your code for direct `TypeDef` imports and adjust names according to the updated conventions. Refer to the `mypy-boto3-builder` changelog for specific renaming patterns.
gotcha When using PyCharm, performance issues with `Literal` overloads have been reported (issue PY-40997). This may lead to slow performance and high CPU usage.
fix Consider using `boto3-stubs-lite` (if available for Batch), disabling PyCharm's internal type checker in favor of MyPy or Pyright, or relying on explicit type annotations rather than full overload inference. Install `mypy` or `pyright` and configure PyCharm to use them.
gotcha For optimal IDE autocompletion and type checking, especially in VSCode without Pylance, explicit type annotations for `boto3.client()` calls are recommended, even if `boto3-stubs` provides some implicit type discovery.
fix Always add explicit type hints like `client: BatchClient = boto3.client('batch')` to leverage the full power of the stubs.
gotcha To avoid `mypy-boto3-batch` becoming a production dependency and to prevent `pylint` complaints about undefined variables when the stub package is not installed in production, it is recommended to wrap stub imports within a `if TYPE_CHECKING:` block.
fix Enclose all `mypy_boto3_batch` imports within `from typing import TYPE_CHECKING; if TYPE_CHECKING: ...` blocks. For runtime use, fallback to `object` or remove type hints.
breaking Boto3 itself will no longer support Python 3.9 starting April 29, 2026. It is recommended to upgrade to Python 3.10 or later for continued service updates, bug fixes, and security updates.
fix Upgrade your Python environment to 3.10 or newer.
pip install 'boto3-stubs[batch]'
python os / libc variant status wheel install import disk
3.10 alpine (musl) batch wheel - - 20.2M
3.10 alpine (musl) batch - - - -
3.10 alpine (musl) boto3 wheel - 0.66s 51.3M
3.10 alpine (musl) boto3 - - 0.60s 51.1M
3.10 slim (glibc) batch wheel 7.6s - 21M
3.10 slim (glibc) batch - - - -
3.10 slim (glibc) boto3 wheel 4.2s 0.48s 52M
3.10 slim (glibc) boto3 - - 0.48s 52M
3.11 alpine (musl) batch wheel - - 22.1M
3.11 alpine (musl) batch - - - -
3.11 alpine (musl) boto3 wheel - 0.83s 54.4M
3.11 alpine (musl) boto3 - - 0.96s 54.2M
3.11 slim (glibc) batch wheel 3.6s - 23M
3.11 slim (glibc) batch - - - -
3.11 slim (glibc) boto3 wheel 3.8s 0.74s 55M
3.11 slim (glibc) boto3 - - 0.72s 55M
3.12 alpine (musl) batch wheel - - 13.6M
3.12 alpine (musl) batch - - - -
3.12 alpine (musl) boto3 wheel - 0.74s 45.6M
3.12 alpine (musl) boto3 - - 0.73s 45.4M
3.12 slim (glibc) batch wheel 2.6s - 14M
3.12 slim (glibc) batch - - - -
3.12 slim (glibc) boto3 wheel 3.2s 0.71s 46M
3.12 slim (glibc) boto3 - - 0.72s 46M
3.13 alpine (musl) batch wheel - - 13.4M
3.13 alpine (musl) batch - - - -
3.13 alpine (musl) boto3 wheel - 0.67s 45.4M
3.13 alpine (musl) boto3 - - 0.72s 45.0M
3.13 slim (glibc) batch wheel 2.4s - 14M
3.13 slim (glibc) batch - - - -
3.13 slim (glibc) boto3 wheel 3.1s 0.72s 46M
3.13 slim (glibc) boto3 - - 0.71s 46M
3.9 alpine (musl) batch wheel - - 19.7M
3.9 alpine (musl) batch - - - -
3.9 alpine (musl) boto3 wheel - 0.49s 50.8M
3.9 alpine (musl) boto3 - - 0.51s 50.6M
3.9 slim (glibc) batch wheel 8.9s - 20M
3.9 slim (glibc) batch - - - -
3.9 slim (glibc) boto3 wheel 4.9s 0.45s 51M
3.9 slim (glibc) boto3 - - 0.44s 51M

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}")