You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-4Lines changed: 69 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,8 +28,10 @@ from asktable import Asktable
28
28
29
29
client = Asktable()
30
30
31
-
datasource = client.datasources.list()
32
-
print(datasource.items)
31
+
datasource = client.datasources.create(
32
+
engine="mysql",
33
+
)
34
+
print(datasource.id)
33
35
```
34
36
35
37
While you can provide an `api_key` keyword argument,
@@ -49,8 +51,10 @@ client = AsyncAsktable()
49
51
50
52
51
53
asyncdefmain() -> None:
52
-
datasource =await client.datasources.list()
53
-
print(datasource.items)
54
+
datasource =await client.datasources.create(
55
+
engine="mysql",
56
+
)
57
+
print(datasource.id)
54
58
55
59
56
60
asyncio.run(main())
@@ -67,6 +71,67 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
67
71
68
72
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
69
73
74
+
## Pagination
75
+
76
+
List methods in the Asktable API are paginated.
77
+
78
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
79
+
80
+
```python
81
+
from asktable import Asktable
82
+
83
+
client = Asktable()
84
+
85
+
all_datasources = []
86
+
# Automatically fetches more pages as needed.
87
+
for datasource in client.datasources.list():
88
+
# Do something with datasource here
89
+
all_datasources.append(datasource)
90
+
print(all_datasources)
91
+
```
92
+
93
+
Or, asynchronously:
94
+
95
+
```python
96
+
import asyncio
97
+
from asktable import AsyncAsktable
98
+
99
+
client = AsyncAsktable()
100
+
101
+
102
+
asyncdefmain() -> None:
103
+
all_datasources = []
104
+
# Iterate through items across all pages, issuing requests as needed.
105
+
asyncfor datasource in client.datasources.list():
106
+
all_datasources.append(datasource)
107
+
print(all_datasources)
108
+
109
+
110
+
asyncio.run(main())
111
+
```
112
+
113
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
114
+
115
+
```python
116
+
first_page =await client.datasources.list()
117
+
if first_page.has_next_page():
118
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
119
+
next_page =await first_page.get_next_page()
120
+
print(f"number of items we just fetched: {len(next_page.items)}")
121
+
122
+
# Remove `await` for non-async usage.
123
+
```
124
+
125
+
Or just work directly with the returned data:
126
+
127
+
```python
128
+
first_page =await client.datasources.list()
129
+
for datasource in first_page.items:
130
+
print(datasource.id)
131
+
132
+
# Remove `await` for non-async usage.
133
+
```
134
+
70
135
## Handling errors
71
136
72
137
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `asktable.APIConnectionError` is raised.
0 commit comments