Skip to main content

DatagrokClient

A client for interacting with the Datagrok API. This class provides convenient access to various Datagrok resources such as files, tables, users, groups, functions, shares, and data connections. It handles authentication and wraps lower-level HTTP calls with resource clients.

Examples

Initialize a client

>>> from datagrok_api import DatagrokClient
>>> grok = DatagrokClient(base_url="https://public.datagrok.ai/api", api_key="Bearer <your-token>")

Download table from server as pd.DataFrame

>>> tables = grok.tables.download("JohnDoe:MyTable")

Run a server-side function

>>> result = grok.functions.call("JohnDoe:MyFunction", {"a": 1, "b": 2})
>>> print(result)

Upload a local file

>>> uploaded_file = grok.files.upload("data.csv")

Get current user info

>>> me = grok.users.current()
>>> print(me.first_name)

Find and update a group

>>> group = grok.groups.find("Chemists")[0]
>>> group.description = "Updated description"
>>> grok.groups.save(group)

Create or modify a connection

>>> from datagrok_api.models import DataConnection, FileDataSourceType, Credentials
>>> creds = Credentials(accessKey="aws-key", secretKey="aws-secret")
>>> conn = DataConnection(name="My S3 Bucket", data_source=FileDataSourceType.S3, bucket="my-bucket", region="eu-west-1", credentials=creds)
>>> conn = grok.connections.save(conn)

Use as a context manager (auto closes session)

>>> with DatagrokClient("https://public.datagrok.ai/api", "Bearer <your-token>") as grok:
... print(grok.users.current().name)

Attributes

NameTypeDescription
filesFilesClientAccess to file operations like upload, download, and sync.
functionsFunctionsClientAllows calling and managing Datagrok functions.
groupsGroupsClientProvides access to user and group management operations.
tablesTablesClientAllows reading and uploading Datagrok tables (datasets).
sharesSharesClientManage entity sharing and permissions.
usersUsersClientProvides information about platform users.
connectionsConnectionsClientInteract with DataConnections (e.g., Postgres, Snowflake, S3, etc.).

Methods

__init__()

close()

__enter__()

__exit__()