|
4 | 4 | [](https://pypi.org/project/foundry-platform-sdk/) |
5 | 5 | [](https://opensource.org/licenses/Apache-2.0) |
6 | 6 |
|
7 | | -> [!WARNING] |
8 | | -> This SDK is incubating and subject to change. |
9 | | - |
10 | 7 | The Foundry Platform SDK is a Python SDK built on top of the Foundry API. |
11 | 8 | Review [Foundry API documentation](https://www.palantir.com/docs/foundry/api/) for more details. |
12 | 9 |
|
@@ -308,23 +305,95 @@ To iterate over all items, you can simply create a `ResourceIterator` instance a |
308 | 305 | for item in client.datasets.Dataset.Branch.list(dataset_rid): |
309 | 306 | print(item) |
310 | 307 |
|
| 308 | +# Or, you can collect all the items in a list |
| 309 | +results = list(client.datasets.Dataset.Branch.list(dataset_rid)) |
| 310 | + |
311 | 311 | ``` |
312 | 312 |
|
313 | 313 | This will automatically fetch and iterate through all the pages of data from the specified API endpoint. For more granular control, you can manually fetch each page using the `next_page_token`. |
314 | 314 |
|
315 | 315 | ```python |
316 | | -page = client.datasets.Dataset.Branch.list(dataset_rid, page_size=page_size) |
317 | | - |
318 | | -while page.next_page_token: |
| 316 | +next_page_token: Optional[str] = None |
| 317 | +while True: |
| 318 | + page = client.datasets.Dataset.Branch.list( |
| 319 | + dataset_rid, page_size=page_size, page_token=next_page_token |
| 320 | + ) |
319 | 321 | for branch in page.data: |
320 | 322 | print(branch) |
321 | 323 |
|
322 | | - page = client.datasets.Dataset.Branch.list( |
323 | | - dataset_rid, page_size=page_size, page_token=page.next_page_token |
| 324 | + if page.next_page_token is None: |
| 325 | + break |
| 326 | + |
| 327 | + next_page_token = page.next_page_token |
| 328 | + |
| 329 | +``` |
| 330 | + |
| 331 | +### Asynchronous Pagination (Beta) |
| 332 | + |
| 333 | +> [!WARNING] |
| 334 | +> The asynchronous client is in beta and may change in future releases. |
| 335 | + |
| 336 | +When using the `AsyncFoundryClient` client, pagination works similar to the synchronous client |
| 337 | +but you need to use `async for` to iterate over the results. Here's an example: |
| 338 | + |
| 339 | + |
| 340 | +```python |
| 341 | +async for item in client.datasets.Dataset.Branch.list(dataset_rid): |
| 342 | + print(item) |
| 343 | + |
| 344 | +# Or, you can collect all the items in a list |
| 345 | +results = [item async for item in client.datasets.Dataset.Branch.list(dataset_rid)] |
| 346 | + |
| 347 | +``` |
| 348 | + |
| 349 | +For more control over asynchronous pagination, you can manually handle the pagination |
| 350 | +tokens and use the `with_raw_response` utility to fetch each page. |
| 351 | + |
| 352 | + |
| 353 | +```python |
| 354 | +next_page_token: Optional[str] = None |
| 355 | +while True: |
| 356 | + response = await client.client.datasets.Dataset.Branch.with_raw_response.list( |
| 357 | + dataset_rid, page_token=next_page_token |
324 | 358 | ) |
325 | 359 |
|
| 360 | + page = response.decode() |
| 361 | + for item in page.data: |
| 362 | + print(item) |
| 363 | + |
| 364 | + if page.next_page_token is None: |
| 365 | + break |
| 366 | + |
| 367 | + next_page_token = page.next_page_token |
| 368 | + |
| 369 | +``` |
| 370 | + |
| 371 | +<a id="async-client"></a> |
| 372 | +### Asynchronous Client (Beta) |
| 373 | + |
| 374 | +> [!WARNING] |
| 375 | +> The asynchronous client is in beta and may change in future releases. |
| 376 | + |
| 377 | +This SDK supports creating an asynchronous client, just import and instantiate the |
| 378 | +`AsyncFoundryClient` instead of the `FoundryClient`. |
| 379 | + |
| 380 | +```python |
| 381 | +from foundry import AsyncFoundryClient |
| 382 | +import foundry |
| 383 | +import asyncio |
| 384 | +from pprint import pprint |
| 385 | + |
| 386 | +async def main(): |
| 387 | + client = AsyncFoundryClient(...) |
| 388 | + response = await client.datasets.Dataset.Branch.create(dataset_rid, name=name, transaction_rid=transaction_rid) |
| 389 | + pprint(response) |
| 390 | + |
| 391 | +if __name__ == "__main__": |
| 392 | + asyncio.run(main()) |
326 | 393 | ``` |
327 | 394 |
|
| 395 | +When using asynchronous clients, you'll just need to use the `await` keyword when calling APIs. Otherwise, the behaviour |
| 396 | +between the `FoundryClient` and `AsyncFoundryClient` is nearly identical. |
328 | 397 |
|
329 | 398 | <a id="binary-streaming"></a> |
330 | 399 | ## Streaming |
|
0 commit comments