This is an automated email from the ASF dual-hosted git repository. emaynard pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push: new ad959fb99 Add PyIceberg example (#2315) ad959fb99 is described below commit ad959fb99b9412338fa16c58bd42a38d3ffd0fb9 Author: Frederic Khayat <61949371+fredkha...@users.noreply.github.com> AuthorDate: Wed Aug 13 20:43:30 2025 +0200 Add PyIceberg example (#2315) It is not obvious how to connect PyIceberg to a Polaris catalog. This PR clears that up by providing an example in the getting-started section of the documentation. --- .../unreleased/getting-started/using-polaris.md | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/site/content/in-dev/unreleased/getting-started/using-polaris.md b/site/content/in-dev/unreleased/getting-started/using-polaris.md index 39a53ff97..857b086e3 100644 --- a/site/content/in-dev/unreleased/getting-started/using-polaris.md +++ b/site/content/in-dev/unreleased/getting-started/using-polaris.md @@ -285,6 +285,51 @@ SELECT * FROM iceberg.quickstart_schema.quickstart_table; org.apache.iceberg.exceptions.ForbiddenException: Forbidden: Principal 'quickstart_user' with activated PrincipalRoles '[]' and activated grants via '[quickstart_catalog_role, quickstart_user_role]' is not authorized for op LOAD_TABLE_WITH_READ_DELEGATION ``` +### Connecting with PyIceberg + +#### Using Credentials + +```python +from pyiceberg.catalog import load_catalog + +catalog = load_catalog( + type='rest', + uri='http://localhost:8181/api/catalog', + warehouse='quickstart_catalog', + scope="PRINCIPAL_ROLE:ALL", + credential=f"{CLIENT_ID}:{CLIENT_SECRET}", +) +``` + +If the `load_catalog` function is used with credentials, then PyIceberg will automatically request an authorization token from the `v1/oauth/tokens` endpoint, and will later use this token to prove its identity to the Polaris Catalog. + +#### Using a Token + +```python +from pyiceberg.catalog import load_catalog +import requests + +# Step 1: Get OAuth token +response = requests.post( + "http://localhost:8181/api/catalog/v1/oauth/tokens", + auth =(CLIENT_ID, CLIENT_SECRET), + data = { + "grant_type": "client_credentials", + "scope": "PRINCIPAL_ROLE:ALL" + }) +token = response.json()["access_token"] + +# Step 2: Load the catalog using the token +catalog = load_catalog( + type='rest', + uri='http://localhost:8181/api/catalog', + warehouse='quickstart_catalog', + token=token, +) +``` + +It is possible to use `load_catalog` function by providing an authorization token directly. This method is useful when using an external identity provider (e.g. Google Identity). + ### Connecting Using REST APIs To access Polaris from the host machine, first request an access token: