dlt-hub / verified-sources

Contribute to dlt verified sources 🔥
https://dlthub.com/docs/walkthroughs/add-a-verified-source
Apache License 2.0
74 stars 50 forks source link

rest_api: pluggable paginators #514

Closed burnash closed 4 months ago

burnash commented 5 months ago

Background

Currently in rest_api source, we have a predefined set of paginators to handle various API pagination methods. (E.g. JSONResponsePaginator, HeaderLinkPaginator, SinglePagePaginator, etc.). This works well for built-in paginators, it lacks flexibility for users who wish to introduce custom pagination logic specific to their needs.

Problem

Users must modify the rest_api.config_setup.PAGINATOR_MAP to add new paginators.

Proposal

Introduce a pluggable paginator system that allows users to define and register custom paginators dynamically. This should have a registration function to add new paginators to the existing paginator map and check for duplicates.

Future enhancement can include using entry points for plugin discovery, allowing users to define and load custom paginators from external packages.

Example

from dlt.sources.helpers.rest_client.paginators import BasePaginator

class CustomPaginator(BasePaginator):
    ...

# Register the custom paginator
register_paginator("custom_paginator", CustomPaginator)

Tasks

willi-mueller commented 4 months ago

The same holds true for authenticators.