Type Annotations for boto3 Invoicing
mypy-boto3-invoicing provides comprehensive type annotations for the AWS boto3 Invoicing service. It offers static type checking compatibility for `boto3.client("invoicing")`, `boto3.resource("invoicing")`, and associated response/request `TypeDefs`, enhancing developer experience with auto-completion and early error detection. The library is automatically generated and regularly updated to reflect the latest boto3 versions.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and subsequent releases. Projects using `mypy-boto3` packages must now use Python 3.9 or newer.
- breaking In `mypy-boto3-builder` version 8.9.0, there were breaking changes to TypeDef naming conventions. Specifically, `RequestRequestTypeDef` was shortened to `RequestTypeDef` (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and `Extra` postfixes in conflicting TypeDefs were moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).
- gotcha This library provides *only type stubs* and does not replace the `boto3` library itself. You must install `boto3` separately for your code to function at runtime. `mypy-boto3-invoicing` merely adds static type-checking capabilities.
Install
-
pip install mypy-boto3-invoicing boto3 mypy
Imports
- InvoicingClient
from mypy_boto3_invoicing.client import InvoicingClient
- GetInvoicesOutputTypeDef
from mypy_boto3_invoicing.type_defs import GetInvoicesOutputTypeDef
Quickstart
import boto3
from mypy_boto3_invoicing.client import InvoicingClient
from mypy_boto3_invoicing.type_defs import GetInvoicesOutputTypeDef
def get_invoices(invoice_id: str) -> GetInvoicesOutputTypeDef:
# Using type annotation for the client enables auto-completion and type checking
client: InvoicingClient = boto3.client("invoicing")
response: GetInvoicesOutputTypeDef = client.get_invoices(InvoiceId=invoice_id)
print(f"Invoice Status: {response.get('Status')}")
return response
# Example usage (replace with actual invoice ID if running)
if __name__ == "__main__":
# Invoicing is not a public AWS service, this is a placeholder example.
# Replace with actual Invoicing API calls if available or adapt for other boto3 services.
try:
# This call will likely fail for a non-existent/public 'invoicing' service.
# The purpose here is to demonstrate type hinting.
result = get_invoices(invoice_id="invoice-123")
except Exception as e:
print(f"Caught expected exception for example: {e}")