Type annotations for boto3 Glue
mypy-boto3-glue provides comprehensive type annotations for the AWS boto3 Glue client, enabling static type checking with tools like MyPy, Pyright, and enhanced IDE auto-completion. It is automatically generated by mypy-boto3-builder and currently aligns with boto3 version 1.42.70, with frequent updates following new boto3 releases.
Warnings
- breaking The underlying `mypy-boto3-builder` (version 8.12.0 and later) removed support for Python 3.8. `mypy-boto3-glue` 1.42.70 and newer officially requires Python 3.9 or higher. Projects on Python 3.8 must pin to an older version of `mypy-boto3-glue`.
- breaking Starting with `mypy-boto3-builder` 8.9.0, some TypeDef names for method arguments were shortened or had 'Extra' postfixes moved. This could break existing type annotations in your code if you explicitly reference these TypeDefs.
- gotcha For users migrating from very old `mypy-boto3` installations (before `boto3-stubs`), the legacy `mypy-boto3` modules are no longer generated alongside `boto3-stubs` by the builder. Ensure you are importing directly from service-specific packages like `mypy_boto3_glue` or using `boto3-stubs[glue]` extras.
- gotcha PyCharm users might experience performance issues due to Literal overloads. The `mypy-boto3-builder` documentation suggests using `boto3-stubs-lite` as a workaround for this known PyCharm issue.
Install
-
pip install mypy-boto3-glue boto3 -
pip install 'boto3-stubs[glue]' boto3
Imports
- GlueClient
from mypy_boto3_glue.client import GlueClient
- GluePaginator
from mypy_boto3_glue.paginators import ListCrawlersPaginator
- GlueTypeDef
from mypy_boto3_glue.type_defs import JobRunTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
from mypy_boto3_glue.client import GlueClient
# Ensure boto3 is configured, e.g., via AWS environment variables or ~/.aws/credentials
# client = boto3.client('glue') # Inferred type in modern IDEs/mypy
def get_typed_glue_client() -> GlueClient:
"""Returns a type-hinted Glue client."""
return boto3.client('glue')
if TYPE_CHECKING:
# Example usage with type checking
glue_client: GlueClient = get_typed_glue_client()
response = glue_client.list_crawlers(MaxResults=10)
for crawler in response.get('Crawlers', []):
print(f"Crawler Name: {crawler.get('Name')}")
print("Glue client configured. Run type checker (e.g., mypy) for full benefits.")