Description
Static type checker used
mypy (project's standard)
AWS Lambda function runtime
3.12
Powertools for AWS Lambda (Python) version
latest
Static type checker info
When using AWS Lambda Powertools with Python type hints, the SQSEvent class is properly exported and can be imported directly from aws_lambda_powertools.utilities.data_classes.
However, SQSRecord - which is closely related to SQSEvent - is only available from the internal module:
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
While this works, it creates an inconsistent developer experience when working with SQS events since:
- SQSEvent can be imported from the main module
- SQSRecord must be imported from the internal submodule
This inconsistency forces developers to know the internal package structure rather than having a clean, intuitive API.
Code snippet
# Current approach requires two different import styles:
from aws_lambda_powertools.utilities.data_classes import SQSEvent
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
def lambda_handler(event, context):
sqs_event = SQSEvent(event)
for record in sqs_event.records:
process_sqs_record(record)
def process_sqs_record(record: SQSRecord) -> None:
message_data = json.loads(record.body)
# Processing logic...
# Proposed approach would allow consistent imports:
from aws_lambda_powertools.utilities.data_classes import SQSEvent, SQSRecord # Currently not possible
def lambda_handler_improved(event, context):
sqs_event = SQSEvent(event)
for record in sqs_event.records:
process_sqs_record_improved(record)
def process_sqs_record_improved(record: SQSRecord) -> None:
message_data = json.loads(record.body)
# Processing logic...
Possible Solution
Export SQSRecord in the aws_lambda_powertools.utilities.data_classes module by adding it to the __all__
list or by explicitly exporting it in the __init__.py
file.
Suggested implementation:
In aws_lambda_powertools/utilities/data_classes/__init__.py
:
from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSEvent, SQSRecord
__all__ = [
...,
"SQSEvent",
"SQSRecord", # Add this line
...
]
This small change would improve developer experience by allowing more consistent and intuitive imports when working with SQS events.
Metadata
Metadata
Assignees
Type
Projects
Status