Skip to content
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

DynamoDB Table Resource should support Pagination for Scan and Query #2039

Open
rbu opened this issue Jul 15, 2019 · 6 comments
Open

DynamoDB Table Resource should support Pagination for Scan and Query #2039

rbu opened this issue Jul 15, 2019 · 6 comments
Labels
dynamodb feature-request This issue requests a feature. needs-review p2 This is a standard priority issue pagination resources

Comments

@rbu
Copy link

rbu commented Jul 15, 2019

The boto3 "Table" Resource API does not provide easy access to paged results when using Scan or Query actions. That's unlike other high level boto3 Resource APIs like S3 which supports s3.Bucket('bucket').objects.pages().

The underlying DynamoDB client supports pagination, which leaves the boto3 user with the choice between nice attribute access + ugly pagination or ugly attribute access + nice pagination, which is unfortunate.

@swetashre swetashre self-assigned this Jul 16, 2019
@swetashre
Copy link
Contributor

swetashre commented Jul 16, 2019

@rbu - Thank you for your post. I will mark this as feature request.

@tomislacker
Copy link

@rbu Thank you much for this, I'm also interested. I'm surprised by there being relatively little activity on this issue. But I suppose if the consumers of DynamoDB that aren't using some sort of ORM already are the main ones affected; I'm not really surprised. They're already dealing a lot with some gnarly JSON blobs.

corpulentcoffee added a commit to corpulentcoffee/dotfiles that referenced this issue Mar 6, 2021
The client supports paginators whereas the table supports high-level
operations.

See <boto/boto3#2039>.
@swetashre swetashre assigned kdaily and unassigned swetashre Mar 25, 2021
@kdaily kdaily removed their assignment Nov 20, 2021
@kevindixon
Copy link

Any update on this feature request - is it planned at all?

@systematicguy
Copy link

What is holding up this issue? Could I help?

@aBurmeseDev aBurmeseDev added the p2 This is a standard priority issue label Nov 11, 2022
@aBurmeseDev
Copy link
Contributor

Thank you all for checking in and apologies for the delay.

We created a backlog item to look into this feature request and if anyone wants to share additional use cases or feedback then please feel free to leave a comment. Although we can't give a definite timeline at the moment, we'll make sure to keep it posted as soon as we have an update and please feel free to check back here in the future.

@mrtj
Copy link

mrtj commented Sep 6, 2023

I use a very simple implementation:

from typing import Callable, Dict, Iterator

def dynamodb_paginator(action: Callable, kwargs: Dict) -> Iterator[Dict]:
    while True:
        response = action(**kwargs)
        for item in response["Items"]:
            yield item
        if "LastEvaluatedKey" in response:
            kwargs["ExclusiveStartKey"] = response["LastEvaluatedKey"]
        else:
            break

Usage:

session = boto3.Session()
dynamodb = session.resource("dynamodb")
table = dynamodb.Table("my_table")
scan_kwargs = { "ScanFilter": ... }  # set here the arguments you would use in the scan() method call
for item in dynamodb_paginator(table.scan, scan_kwargs):
    ... # do something with the item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamodb feature-request This issue requests a feature. needs-review p2 This is a standard priority issue pagination resources
Projects
None yet
Development

No branches or pull requests

9 participants