Skip to content

Commit 5486edd

Browse files
rest_api: Renames JSONResponsePaginator to JSONLinkPaginator. (#523)
* rest_api: Renames JSONResponsePaginator to JSONLinkPaginator. * bumps dlt dependency to have renamed JSONLinkPaginator * dlt requirements check also accepts url with pointer to branch, tag, or commit so that CI checks pass when we depend on an open PR in dlt-core
1 parent 7e888b3 commit 5486edd

12 files changed

+37
-47
lines changed

check-requirements.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"E.g. dlt>=0.3.5,<0.4.0"
2424
)
2525

26+
27+
def has_url_with_pin(dlt_req: Requirement) -> bool:
28+
"""Checks if the url contains a reference to a branch, tag, or commit"""
29+
return dlt_req.url is not None and "@" in dlt_req.url
30+
31+
2632
for source in source_dirs:
2733
req_path = source.joinpath("requirements.txt")
2834
if not req_path.is_file():
@@ -54,7 +60,7 @@
5460
)
5561
error = True
5662
continue
57-
if not dlt_req.specifier:
63+
if not dlt_req.specifier and not has_url_with_pin(dlt_req):
5864
print(
5965
f"ERROR: Source {source.name} dlt requirement '{dlt_req}' has no version constraint. {error_msg_suffix}"
6066
)

poetry.lock

Lines changed: 5 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ packages = [{include = "sources"}]
1212

1313
[tool.poetry.dependencies]
1414
python = ">=3.8.1,<3.13"
15-
dlt = {version = "0.5.1", allow-prereleases = true, extras = ["redshift", "bigquery", "postgres", "duckdb"]}
15+
dlt = {version = "0.5.2a1", allow-prereleases = true, extras = ["redshift", "bigquery", "postgres", "duckdb"]}
1616
graphlib-backport = {version = "*", python = "<3.9"}
1717

1818
[tool.poetry.group.dev.dependencies]
@@ -108,4 +108,4 @@ requires = ["poetry-core"]
108108
build-backend = "poetry.core.masonry.api"
109109

110110
[tool.black]
111-
include = '.*py$'
111+
include = '.*py$'

sources/rest_api/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ Possible paginators are:
130130
| Paginator | String Alias | Note |
131131
| --------- | ------------ | ---- |
132132
| BasePaginator | | |
133-
| HeaderLinkPaginator | `header_links` | |
134-
| JSONResponsePaginator | `json_links` | The pagination metainformation is in a node of the JSON response (see example below) |
133+
| HeaderLinkPaginator | `header_link` | |
134+
| JSONLinkPaginator | `json_link` | The pagination metainformation is in a node of the JSON response (see example below) |
135135
| SinglePagePaginator | `single_page` | The response will be interpreted as a single-page response, ignoring possible pagination metadata |
136136

137-
Usage example of the `JSONResponsePaginator`, for a response with the URL of the next page located at `paging.next`:
137+
Usage example of the `JSONLinkPaginator`, for a response with the URL of the next page located at `paging.next`:
138138
```python
139-
"paginator": JSONResponsePaginator(
140-
next_key=["paging", "next"]
139+
"paginator": JSONLinkPaginator(
140+
next_url_path="paging.next"]
141141
)
142142
```
143143

@@ -215,4 +215,4 @@ Resources with the name different from the endpoint string will be:
215215
```
216216
In case you need to have a resource with a name different from the table created, you can pass the property `table_name` too.
217217

218-
For the other properties, see the [resource_defaults](#resource_defaults) above.
218+
For the other properties, see the [resource_defaults](#resource_defaults) above.

sources/rest_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def rest_api_source(
7979
pokemon_source = rest_api_source({
8080
"client": {
8181
"base_url": "https://pokeapi.co/api/v2/",
82-
"paginator": "json_response",
82+
"paginator": "json_link",
8383
},
8484
"endpoints": {
8585
"pokemon": {

sources/rest_api/config_setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
BasePaginator,
3030
SinglePagePaginator,
3131
HeaderLinkPaginator,
32-
JSONResponsePaginator,
32+
JSONLinkPaginator,
3333
JSONResponseCursorPaginator,
3434
OffsetPaginator,
3535
PageNumberPaginator,
@@ -60,7 +60,7 @@
6060

6161

6262
PAGINATOR_MAP: Dict[PaginatorType, Type[BasePaginator]] = {
63-
"json_response": JSONResponsePaginator,
63+
"json_link": JSONLinkPaginator,
6464
"header_link": HeaderLinkPaginator,
6565
"auto": None,
6666
"single_page": SinglePagePaginator,

sources/rest_api/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dlt>=0.4.11
1+
dlt>=0.5.2a1

sources/rest_api/typing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from dlt.sources.helpers.rest_client.paginators import (
3131
SinglePagePaginator,
3232
HeaderLinkPaginator,
33-
JSONResponsePaginator,
33+
JSONLinkPaginator,
3434
JSONResponseCursorPaginator,
3535
OffsetPaginator,
3636
PageNumberPaginator,
@@ -43,7 +43,7 @@
4343
)
4444

4545
PaginatorType = Literal[
46-
"json_response",
46+
"json_link",
4747
"header_link",
4848
"auto",
4949
"single_page",
@@ -84,7 +84,7 @@ class HeaderLinkPaginatorConfig(PaginatorTypeConfig, total=False):
8484
links_next_key: Optional[str]
8585

8686

87-
class JSONResponsePaginatorConfig(PaginatorTypeConfig, total=False):
87+
class JSONLinkPaginatorConfig(PaginatorTypeConfig, total=False):
8888
"""Locates the next page URL within the JSON response body. The key
8989
containing the URL can be specified using a JSON path."""
9090

@@ -104,12 +104,12 @@ class JSONResponseCursorPaginatorConfig(PaginatorTypeConfig, total=False):
104104
PageNumberPaginatorConfig,
105105
OffsetPaginatorConfig,
106106
HeaderLinkPaginatorConfig,
107-
JSONResponsePaginatorConfig,
107+
JSONLinkPaginatorConfig,
108108
JSONResponseCursorPaginatorConfig,
109109
BasePaginator,
110110
SinglePagePaginator,
111111
HeaderLinkPaginator,
112-
JSONResponsePaginator,
112+
JSONLinkPaginator,
113113
JSONResponseCursorPaginator,
114114
OffsetPaginator,
115115
PageNumberPaginator,

sources/rest_api_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def load_pokemon() -> None:
116116
"client": {
117117
"base_url": "https://pokeapi.co/api/v2/",
118118
# If you leave out the paginator, it will be inferred from the API:
119-
# paginator: "json_response",
119+
# paginator: "json_link",
120120
},
121121
"resource_defaults": {
122122
"endpoint": {

tests/rest_api/source_configs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class CustomOAuthAuth(OAuth2AuthBase):
137137
"params": {
138138
"limit": 100,
139139
},
140-
"paginator": "json_response",
140+
"paginator": "json_link",
141141
},
142142
},
143143
],
@@ -217,7 +217,7 @@ class CustomOAuthAuth(OAuth2AuthBase):
217217
"initial_value": "2024-01-25T11:21:28Z",
218218
},
219219
},
220-
"paginator": "json_response",
220+
"paginator": "json_link",
221221
},
222222
},
223223
],
@@ -232,7 +232,7 @@ class CustomOAuthAuth(OAuth2AuthBase):
232232
"params": {
233233
"limit": 100,
234234
},
235-
"paginator": "json_response",
235+
"paginator": "json_link",
236236
"incremental": {
237237
"start_param": "since",
238238
"end_param": "until",
@@ -313,7 +313,7 @@ class CustomOAuthAuth(OAuth2AuthBase):
313313
{"type": "page_number", "page": 10, "base_page": 1, "total_path": "response.pages"},
314314
{"type": "offset", "limit": 100, "maximum_offset": 1000},
315315
{"type": "header_link", "links_next_key": "next_page"},
316-
{"type": "json_response", "next_url_path": "response.nex_page_link"},
316+
{"type": "json_link", "next_url_path": "response.nex_page_link"},
317317
{"type": "cursor", "cursor_param": "cursor"},
318318
]
319319

0 commit comments

Comments
 (0)