FunctionsClient
Client for interacting with Datagrok's Functions API. This client provides methods to call, retrieve, list, and create functions (including queries and scripts) on a Datagrok instance. It supports direct execution of functions with parameters.
Examples
Create Script
>>> from datagrok_api import DatagrokClient
>>> from datagrok_api.models import Func, Script, ScriptLanguage, DataQuery
>>> grok = DatagrokClient(base_url="https://public.datagrok.ai/api", api_key="Bearer <your-token>")
>>> script = grok.functions.create_script(script="print('Hello from Datagrok!')", name="My Script")
>>> print(script.script)
print('Hello from Datagrok!')
Create DataQuery
>>> conn = grok.connections.get("JohnDoe:Chembl")
>>> query = grok.functions.create_query(conn=conn, query="select id from molecules limit 100", name="Molecules")
Execute query
>>> res = grok.functions.call(query)
Get all scripts
>>> r_scripts = grok.functions.list_scripts()
Methods
__init__()
call()
Call a Datagrok function with the specified parameters.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | Grok Name of the function to call |
| parameters | Dict[str, Any] | Dictionary of parameters to pass to the function |
Returns
| Type | Description |
|---|---|
| Any | The result of the function call |
get()
Get detailed information about a specific Func.
Parameters
| Name | Type | Description |
|---|---|---|
| id | str | ID or Grok Name of the Func to retrieve |
Returns
| Type | Description |
|---|---|
| Func | Func instance with detailed information |
list()
List funcs from Datagrok with optional filtering.
Parameters
| Name | Type | Description |
|---|---|---|
| smart_filter | Optional[str] | Optional smart search filter to apply |
Returns
| Type | Description |
|---|---|
| List[Func] | List of Func instances matching the criteria |
list_queries()
List all queries available in Datagrok.
Returns
| Type | Description |
|---|---|
| List[DataQuery] | List of DataQuery instances. |
list_scripts()
List all scripts available in Datagrok.
Returns
| Type | Description |
|---|---|
| List[Script] | List of DataQuery instances. |
create_query()
Create and save a new data query in Datagrok.
Parameters
| Name | Type | Description |
|---|---|---|
| connection | DataConnection | The data connection to execute the query on. |
| query | str | The SQL or query string to execute. |
| name | str, optional | Optional name for the query. |
Returns
| Type | Description |
|---|---|
| DataQuery | The created DataQuery instance. |
create_script()
Create and save a new script in Datagrok.
Parameters
| Name | Type | Description |
|---|---|---|
| script | str | The script source code. |
| name | str, optional | Optional name for the script. |
Returns
| Type | Description |
|---|---|
| Script | The created Script instance. |