Skip to content

Enhancement: Export SQSRecord in main data_classes module #6637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AlisonVilela opened this issue May 9, 2025 · 1 comment
Open

Enhancement: Export SQSRecord in main data_classes module #6637

AlisonVilela opened this issue May 9, 2025 · 1 comment
Labels
triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.)

Comments

@AlisonVilela
Copy link

AlisonVilela commented May 9, 2025

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:

  1. SQSEvent can be imported from the main module
  2. 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.

@AlisonVilela AlisonVilela added triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.) labels May 9, 2025
Copy link

boring-cyborg bot commented May 9, 2025

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@AlisonVilela AlisonVilela changed the title SQSRecord not exported in data_classes module Enhancement: Export SQSRecord in main data_classes module May 9, 2025
AlisonVilela added a commit to AlisonVilela/powertools-lambda-python that referenced this issue May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.)
Projects
Development

No branches or pull requests

1 participant