Type annotations for boto3 ServerlessApplicationRepository
mypy-boto3-serverlessrepo provides static type annotations for the boto3 ServerlessApplicationRepository service, compatible with tools like VSCode, PyCharm, mypy, and pyright. It is part of the larger mypy-boto3 project, with packages updated hourly from boto3 documentation to ensure compatibility and accuracy. The current version is 1.42.3.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 must use older versions or upgrade Python.
- breaking The `mypy-boto3` project (which generates this stub package) migrated to PEP 561-compliant package structure. This might require updates to import paths for some internal or advanced usages, though standard client/type_def imports remain consistent.
- breaking TypedDict naming conventions were updated in `mypy-boto3-builder` 8.9.0. Many `RequestRequestTypeDef` and `ExtraRequestTypeDef` names were shortened (e.g., `CreateApplicationRequestRequestTypeDef` became `CreateApplicationRequestTypeDef`).
- gotcha This library provides *only* type annotations (stubs) for `boto3`. You must install the `boto3` library separately for your application to function at runtime.
- gotcha For optimal IDE autocomplete and type checking, especially in VSCode and PyCharm, it is highly recommended to use explicit type annotations for `boto3.client()` and `boto3.session.client()` calls.
- gotcha When using `Pylint`, type checking dependencies might cause false positives for undefined variables if not handled carefully.
Install
-
pip install mypy-boto3-serverlessrepo boto3 -
pip install mypy-boto3-serverlessrepo mypy
Imports
- ServerlessApplicationRepositoryClient
from mypy_boto3_serverlessrepo.client import ServerlessApplicationRepositoryClient
- CreateApplicationRequestTypeDef
from mypy_boto3_serverlessrepo.type_defs import CreateApplicationRequestTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
from mypy_boto3_serverlessrepo.client import ServerlessApplicationRepositoryClient
from mypy_boto3_serverlessrepo.type_defs import CreateApplicationRequestTypeDef
# Boto3 client without type hints (mypy/IDE might infer, but explicit is better)
client_untyped = boto3.client('serverlessrepo')
# Boto3 client with explicit type hints
if TYPE_CHECKING:
client: ServerlessApplicationRepositoryClient = boto3.client('serverlessrepo')
else:
client = boto3.client('serverlessrepo')
# Example using a TypedDict for request parameters
application_params: CreateApplicationRequestTypeDef = {
'Author': 'MyCompany',
'Description': 'A sample serverless application.',
'Name': 'MySampleApp',
'HomePageUrl': 'https://example.com/myapp',
'Labels': ['python', 'example'],
'SourceCodeUrl': 'https://github.com/mycompany/myapp'
}
try:
# In a real scenario, you'd add necessary fields like 'AppTemplateBody' or 'SemanticVersion'
# For a quickstart, we'll just demonstrate the client type checking.
# This call would typically fail without required fields or actual template body.
# response = client.create_application(**application_params)
print("Client type checking is active.")
print(f"Expected return type for list_applications: {{client.list_applications.__annotations__.get('return')}}")
except Exception as e:
print(f"An error occurred (expected for incomplete example): {e}")