datagrok-api 0.0.8__tar.gz → 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datagrok_api-0.1.0/PKG-INFO +104 -0
- datagrok_api-0.1.0/README.md +83 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/datagrok_client.py +13 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/__init__.py +4 -2
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/data_connection.py +33 -22
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/func.py +30 -35
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/group.py +1 -1
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/model.py +2 -2
- datagrok_api-0.1.0/datagrok_api/models/package.py +146 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/query.py +16 -28
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/script.py +26 -35
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/share_response.py +13 -15
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/__init__.py +4 -1
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/connections.py +1 -1
- datagrok_api-0.1.0/datagrok_api/resources/credentials.py +77 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/files.py +2 -2
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/functions.py +48 -0
- datagrok_api-0.1.0/datagrok_api/resources/packages.py +71 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/shares.py +1 -1
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/users.py +16 -2
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/pyproject.toml +1 -2
- datagrok_api-0.0.8/PKG-INFO +0 -171
- datagrok_api-0.0.8/README.md +0 -149
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/.gitignore +0 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/__init__.py +0 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/http_client.py +0 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/models/user.py +0 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/groups.py +0 -0
- {datagrok_api-0.0.8 → datagrok_api-0.1.0}/datagrok_api/resources/tables.py +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datagrok-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Client library for integration with datagrok API
|
|
5
|
+
Project-URL: Homepage, https://github.com/datagrok-ai/public
|
|
6
|
+
Project-URL: Issues, https://github.com/datagrok-ai/public/issues
|
|
7
|
+
Author-email: Andrew Skalkin <askalkin@datagrok.ai>, Amelichev Konstantin <kamelichev@datagrok.ai>
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Requires-Dist: pandas
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: requests-toolbelt
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: data-to-xml; extra == 'test'
|
|
17
|
+
Requires-Dist: pytest; extra == 'test'
|
|
18
|
+
Requires-Dist: pytest-item-dict; extra == 'test'
|
|
19
|
+
Requires-Dist: pytest-xml; extra == 'test'
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Datagrok python client library
|
|
23
|
+
|
|
24
|
+
This library can be used for integration with datagrok. It is a python wrapper for public API, that has OpenAPI specification available [here](http://public.datagrok.ai/api/public/api.yaml).
|
|
25
|
+
|
|
26
|
+
Refer to [Help](http://datagrok.ai/help) for more information.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
To install package, use [pip](https://pypi.org/project/pip/).
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
pip install datagrok-api
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Initialization
|
|
39
|
+
To use the API client, import `DatagrokClient`. It is recommended to use it as a context manager to ensure proper connection handling:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from datagrok_api import DatagrokClient
|
|
43
|
+
|
|
44
|
+
# Initialize with your server URL and API token
|
|
45
|
+
with DatagrokClient("https://public.datagrok.ai/api", "Bearer <your-token>") as grok:
|
|
46
|
+
me = grok.users.current()
|
|
47
|
+
print(f"Logged in as: {me.first_name} {me.last_name}")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Working with Data (Tables & Files)
|
|
51
|
+
The package uses Pandas for representation of tables and dataframes.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import pandas as pd
|
|
55
|
+
from sklearn.datasets import load_iris
|
|
56
|
+
|
|
57
|
+
# Upload a DataFrame as a table
|
|
58
|
+
iris_df = pd.DataFrame(load_iris()['data'])
|
|
59
|
+
iris_id = grok.tables.upload('iris', iris_df)['ID']
|
|
60
|
+
|
|
61
|
+
# Download a table by ID or Name
|
|
62
|
+
df = grok.tables.download(iris_id)
|
|
63
|
+
print(df.head())
|
|
64
|
+
|
|
65
|
+
# Upload a local file
|
|
66
|
+
uploaded_file = grok.files.upload("data.csv")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Functions & Connections
|
|
70
|
+
You can call server-side functions and manage data connections directly through their respective managers.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from datagrok_api.models import DataConnection, FileDataSourceType, Credentials
|
|
74
|
+
|
|
75
|
+
# Call a Datagrok function
|
|
76
|
+
result = grok.functions.call("JohnDoe:MyFunction", {"a": 1, "b": 2})
|
|
77
|
+
|
|
78
|
+
# Create and save a connection (e.g., S3)
|
|
79
|
+
creds = Credentials(accessKey="aws-key", secretKey="aws-secret")
|
|
80
|
+
conn = DataConnection(
|
|
81
|
+
name="My S3 Bucket",
|
|
82
|
+
data_source=FileDataSourceType.S3,
|
|
83
|
+
bucket="my-bucket",
|
|
84
|
+
region="us-east-1",
|
|
85
|
+
credentials=creds
|
|
86
|
+
)
|
|
87
|
+
saved_conn = grok.connections.save(conn)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Group Management
|
|
91
|
+
Manage user groups and metadata.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
# Search for a group and update its properties
|
|
95
|
+
groups = grok.groups.find("Chemists")
|
|
96
|
+
if groups:
|
|
97
|
+
group = groups[0]
|
|
98
|
+
group.description = "Updated description for the team"
|
|
99
|
+
grok.groups.save(group)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
See [License](https://github.com/datagrok-ai/public/blob/master/LICENSE.md).
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Datagrok python client library
|
|
2
|
+
|
|
3
|
+
This library can be used for integration with datagrok. It is a python wrapper for public API, that has OpenAPI specification available [here](http://public.datagrok.ai/api/public/api.yaml).
|
|
4
|
+
|
|
5
|
+
Refer to [Help](http://datagrok.ai/help) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
To install package, use [pip](https://pypi.org/project/pip/).
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
pip install datagrok-api
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Initialization
|
|
18
|
+
To use the API client, import `DatagrokClient`. It is recommended to use it as a context manager to ensure proper connection handling:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from datagrok_api import DatagrokClient
|
|
22
|
+
|
|
23
|
+
# Initialize with your server URL and API token
|
|
24
|
+
with DatagrokClient("https://public.datagrok.ai/api", "Bearer <your-token>") as grok:
|
|
25
|
+
me = grok.users.current()
|
|
26
|
+
print(f"Logged in as: {me.first_name} {me.last_name}")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Working with Data (Tables & Files)
|
|
30
|
+
The package uses Pandas for representation of tables and dataframes.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import pandas as pd
|
|
34
|
+
from sklearn.datasets import load_iris
|
|
35
|
+
|
|
36
|
+
# Upload a DataFrame as a table
|
|
37
|
+
iris_df = pd.DataFrame(load_iris()['data'])
|
|
38
|
+
iris_id = grok.tables.upload('iris', iris_df)['ID']
|
|
39
|
+
|
|
40
|
+
# Download a table by ID or Name
|
|
41
|
+
df = grok.tables.download(iris_id)
|
|
42
|
+
print(df.head())
|
|
43
|
+
|
|
44
|
+
# Upload a local file
|
|
45
|
+
uploaded_file = grok.files.upload("data.csv")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Functions & Connections
|
|
49
|
+
You can call server-side functions and manage data connections directly through their respective managers.
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from datagrok_api.models import DataConnection, FileDataSourceType, Credentials
|
|
53
|
+
|
|
54
|
+
# Call a Datagrok function
|
|
55
|
+
result = grok.functions.call("JohnDoe:MyFunction", {"a": 1, "b": 2})
|
|
56
|
+
|
|
57
|
+
# Create and save a connection (e.g., S3)
|
|
58
|
+
creds = Credentials(accessKey="aws-key", secretKey="aws-secret")
|
|
59
|
+
conn = DataConnection(
|
|
60
|
+
name="My S3 Bucket",
|
|
61
|
+
data_source=FileDataSourceType.S3,
|
|
62
|
+
bucket="my-bucket",
|
|
63
|
+
region="us-east-1",
|
|
64
|
+
credentials=creds
|
|
65
|
+
)
|
|
66
|
+
saved_conn = grok.connections.save(conn)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Group Management
|
|
70
|
+
Manage user groups and metadata.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# Search for a group and update its properties
|
|
74
|
+
groups = grok.groups.find("Chemists")
|
|
75
|
+
if groups:
|
|
76
|
+
group = groups[0]
|
|
77
|
+
group.description = "Updated description for the team"
|
|
78
|
+
grok.groups.save(group)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
See [License](https://github.com/datagrok-ai/public/blob/master/LICENSE.md).
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from datagrok_api.http_client import HttpClient
|
|
2
2
|
from datagrok_api.resources.connections import ConnectionsClient
|
|
3
|
+
from datagrok_api.resources.credentials import CredentialsClient
|
|
3
4
|
from datagrok_api.resources.files import FilesClient
|
|
4
5
|
from datagrok_api.resources.functions import FunctionsClient
|
|
5
6
|
from datagrok_api.resources.groups import GroupsClient
|
|
7
|
+
from datagrok_api.resources.packages import PackagesClient, PublishedPackagesClient
|
|
6
8
|
from datagrok_api.resources.shares import SharesClient
|
|
7
9
|
from datagrok_api.resources.tables import TablesClient
|
|
8
10
|
from datagrok_api.resources.users import UsersClient
|
|
@@ -40,9 +42,17 @@ class DatagrokClient:
|
|
|
40
42
|
Provides information about platform users.
|
|
41
43
|
connections : ConnectionsClient
|
|
42
44
|
Interact with DataConnections (e.g., Postgres, Snowflake, S3, etc.).
|
|
45
|
+
packages : PackagesClient
|
|
46
|
+
List and retrieve Datagrok packages.
|
|
47
|
+
published_packages : PublishedPackagesClient
|
|
48
|
+
List and retrieve published package versions.
|
|
49
|
+
credentials : CredentialsClient
|
|
50
|
+
Manage credentials for any entity (connections, packages, etc.).
|
|
43
51
|
|
|
44
52
|
Examples
|
|
45
53
|
--------
|
|
54
|
+
Initialize a client
|
|
55
|
+
|
|
46
56
|
>>> from datagrok_api import DatagrokClient
|
|
47
57
|
|
|
48
58
|
>>> grok = DatagrokClient(base_url="https://public.datagrok.ai/api", api_key="Bearer <your-token>")
|
|
@@ -93,6 +103,9 @@ class DatagrokClient:
|
|
|
93
103
|
self.shares = SharesClient(client=self._http)
|
|
94
104
|
self.users = UsersClient(client=self._http)
|
|
95
105
|
self.connections = ConnectionsClient(client=self._http)
|
|
106
|
+
self.packages = PackagesClient(client=self._http)
|
|
107
|
+
self.published_packages = PublishedPackagesClient(client=self._http)
|
|
108
|
+
self.credentials = CredentialsClient(client=self._http)
|
|
96
109
|
|
|
97
110
|
|
|
98
111
|
def close(self):
|
|
@@ -5,10 +5,12 @@ from .script import Script, ScriptLanguage
|
|
|
5
5
|
from .func import Func, FuncParam, PropertyType
|
|
6
6
|
from .model import Model
|
|
7
7
|
from .data_connection import DataConnection, Credentials, DatabaseDataSourceType, FileDataSourceType, DataSourceType
|
|
8
|
+
from .package import Package, PublishedPackage
|
|
8
9
|
from .share_response import ShareResponse
|
|
9
10
|
|
|
10
11
|
__all__ = [
|
|
11
12
|
"User", "Group", "DataQuery", "Script", "ScriptLanguage",
|
|
12
|
-
"Func", "FuncParam", "PropertyType", "Model", "DataConnection", "ShareResponse",
|
|
13
|
-
"DatabaseDataSourceType", "Credentials", "FileDataSourceType", "DataSourceType"
|
|
13
|
+
"Func", "FuncParam", "PropertyType", "Model", "DataConnection", "ShareResponse",
|
|
14
|
+
"DatabaseDataSourceType", "Credentials", "FileDataSourceType", "DataSourceType",
|
|
15
|
+
"Package", "PublishedPackage"
|
|
14
16
|
]
|
|
@@ -2,6 +2,7 @@ from enum import Enum
|
|
|
2
2
|
from typing import List, Optional, Union
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from datagrok_api.models.model import Model, NamedModel
|
|
5
|
+
from datagrok_api.models.group import Group
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class DataSourceType(str, Enum):
|
|
@@ -93,7 +94,7 @@ class Credentials(Model):
|
|
|
93
94
|
Allows dynamic setting and getting of credential fields like login, password,
|
|
94
95
|
access keys, or tokens depending on the data source.
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
Attributes
|
|
97
98
|
----------
|
|
98
99
|
**kwargs : dict
|
|
99
100
|
Arbitrary credential fields passed as key-value pairs.
|
|
@@ -112,28 +113,38 @@ class Credentials(Model):
|
|
|
112
113
|
>>> print(aws_creds.access_key) # Access AWS access key
|
|
113
114
|
>>> aws_creds.secret_key = "NEW_SECRET" # Update secret key dynamically
|
|
114
115
|
"""
|
|
115
|
-
_explicit_attrs = {"id", "parameters", "open_parameters"}
|
|
116
|
-
def __init__(self, **kwargs):
|
|
116
|
+
_explicit_attrs = {"id", "parameters", "open_parameters", "entity_bind_id", "group"}
|
|
117
|
+
def __init__(self, entity_bind_id: Optional[str] = None, group: Optional['Group'] = None, **kwargs):
|
|
117
118
|
super().__init__(None)
|
|
118
119
|
self.parameters = dict(kwargs)
|
|
119
120
|
self.open_parameters = dict()
|
|
121
|
+
self.entity_bind_id = entity_bind_id
|
|
122
|
+
self.group = group
|
|
120
123
|
|
|
121
124
|
def get(self, key, default=None):
|
|
122
125
|
return self.parameters.get(key, default)
|
|
123
126
|
|
|
124
127
|
def to_dict(self):
|
|
125
|
-
|
|
128
|
+
d = {
|
|
126
129
|
"id": self.id,
|
|
127
130
|
"parameters": self.parameters,
|
|
128
|
-
"openParameters": self.open_parameters
|
|
129
|
-
|
|
131
|
+
"openParameters": self.open_parameters,
|
|
132
|
+
"entityBindId": self.entity_bind_id,
|
|
133
|
+
}
|
|
134
|
+
if self.group is not None:
|
|
135
|
+
d["group"] = self.group.to_dict()
|
|
136
|
+
return d
|
|
130
137
|
|
|
131
138
|
@classmethod
|
|
132
139
|
def from_dict(cls, data: dict) -> 'Credentials':
|
|
133
|
-
|
|
140
|
+
group_data = data.get('group')
|
|
141
|
+
group = Group.from_dict(group_data) if group_data else None
|
|
142
|
+
creds = cls(entity_bind_id=data.get('entityBindId'),
|
|
143
|
+
group=group,
|
|
144
|
+
**data.get('parameters', {}))
|
|
134
145
|
creds.id = data.get('id')
|
|
135
146
|
creds.open_parameters = data.get('openParameters', {})
|
|
136
|
-
return creds
|
|
147
|
+
return creds
|
|
137
148
|
|
|
138
149
|
def __getattr__(self, name):
|
|
139
150
|
if name in self.parameters:
|
|
@@ -156,7 +167,7 @@ class DataConnection(NamedModel):
|
|
|
156
167
|
"""
|
|
157
168
|
Represents a data connection in Datagrok.
|
|
158
169
|
|
|
159
|
-
|
|
170
|
+
Attributes
|
|
160
171
|
----------
|
|
161
172
|
name : Optional[str]
|
|
162
173
|
Internal name of the model, used as an identifier.
|
|
@@ -186,25 +197,25 @@ class DataConnection(NamedModel):
|
|
|
186
197
|
Create a connection to a Postgres database with login parameters
|
|
187
198
|
|
|
188
199
|
>>> conn_pg = DataConnection(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
200
|
+
... name="my_postgres_conn",
|
|
201
|
+
... data_source=DataSourceType.Postgres,
|
|
202
|
+
... server="localhost",
|
|
203
|
+
... port=5432,
|
|
204
|
+
... db="mydb",
|
|
205
|
+
... new Credentials(login="postgres", password="postgres")
|
|
206
|
+
... )
|
|
196
207
|
>>> print(conn_pg.host) # Access arbitrary parameter
|
|
197
208
|
>>> conn_pg.password = "new_password" # Update arbitrary parameter
|
|
198
209
|
|
|
199
210
|
Create a connection to an S3 bucket with different parameters
|
|
200
211
|
|
|
201
212
|
>>> conn_s3 = DataConnection(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
)
|
|
213
|
+
... name="my_s3_conn",
|
|
214
|
+
... data_source=DataSourceType.S3,
|
|
215
|
+
... bucket="my-bucket",
|
|
216
|
+
... region="us-west-2",
|
|
217
|
+
... new Credentials(accessKey="AKIA...", secretKey="...")
|
|
218
|
+
... )
|
|
208
219
|
>>> print(conn_s3.bucket) # Access bucket name
|
|
209
220
|
>>> conn_s3.region = "us-east-1" # Update region dynamically
|
|
210
221
|
"""
|
|
@@ -33,7 +33,12 @@ class FuncParam:
|
|
|
33
33
|
|
|
34
34
|
@classmethod
|
|
35
35
|
def from_dict(cls, data: dict) -> 'FuncParam':
|
|
36
|
-
|
|
36
|
+
prop_type = data.get("propertyType")
|
|
37
|
+
try:
|
|
38
|
+
prop_type = PropertyType(prop_type)
|
|
39
|
+
except ValueError:
|
|
40
|
+
pass
|
|
41
|
+
return cls(name=data.get("name"), type=prop_type, is_input=data.get("isInput", True))
|
|
37
42
|
|
|
38
43
|
class Func(NamedModel):
|
|
39
44
|
"""
|
|
@@ -45,28 +50,28 @@ class Func(NamedModel):
|
|
|
45
50
|
define, discover, secure, and execute platform capabilities.
|
|
46
51
|
|
|
47
52
|
Examples of functions in Grok include:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
* Querying an external PostgreSQL database
|
|
54
|
+
* Executing JavaScript code in the browser that uses Grok APIs
|
|
55
|
+
* Performing mathematical calculations (e.g., `Sin(PI)`)
|
|
56
|
+
* Modifying datasets (e.g., deleting a column)
|
|
57
|
+
* Sending an email
|
|
58
|
+
* Applying a predictive model to a dataset
|
|
59
|
+
* Calculating molecular properties via a Python script
|
|
60
|
+
* Displaying interactive dialogs
|
|
56
61
|
|
|
57
62
|
Despite their differences (server-side vs client-side execution,
|
|
58
63
|
computational vs UI-based tasks), all functions share a common
|
|
59
64
|
set of capabilities:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
* **Scriptable**: Callable from the console or scripts.
|
|
66
|
+
* **Findable**: Searchable through the "Help | Functions" interface.
|
|
67
|
+
* **Introspectable**: Metadata about parameters is programmatically accessible.
|
|
68
|
+
* **Secure**: Access can be restricted via privileges or user groups.
|
|
69
|
+
* **Auditable**: Execution history and parameters are tracked.
|
|
70
|
+
* **Runnable**: The platform can dynamically generate UI for parameters.
|
|
71
|
+
* **Linkable**: Functions can be linked in dashboards, conversations, etc.
|
|
72
|
+
* **Composable**: Usable in workflow designers and query transformations.
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
Attributes
|
|
70
75
|
----------
|
|
71
76
|
source : Optional[str], default='function'
|
|
72
77
|
Identifies the origin or type of function (e.g., `"function"`, `"sql-query"`, `"js-script"`).
|
|
@@ -81,9 +86,6 @@ class Func(NamedModel):
|
|
|
81
86
|
**kwargs
|
|
82
87
|
Additional arguments passed to the parent `NamedModel` initializer,
|
|
83
88
|
such as `id`, `name`, `friendly_name`, `created_on`, `updated_on`, and `namespace`.
|
|
84
|
-
|
|
85
|
-
Attributes
|
|
86
|
-
----------
|
|
87
89
|
params : list of FuncParam
|
|
88
90
|
Parameter definitions (both input and output).
|
|
89
91
|
source : str
|
|
@@ -94,24 +96,10 @@ class Func(NamedModel):
|
|
|
94
96
|
Human-readable description.
|
|
95
97
|
options : dict
|
|
96
98
|
Function-specific settings.
|
|
97
|
-
|
|
98
|
-
Properties
|
|
99
|
-
----------
|
|
100
99
|
input_params : list of FuncParam
|
|
101
100
|
Parameters marked as inputs to the function.
|
|
102
101
|
output_params : list of FuncParam
|
|
103
102
|
Parameters marked as outputs from the function.
|
|
104
|
-
|
|
105
|
-
Methods
|
|
106
|
-
-------
|
|
107
|
-
to_dict() -> dict
|
|
108
|
-
Serializes the function to a dictionary for API usage.
|
|
109
|
-
register_subclass(source: str) -> Callable
|
|
110
|
-
Class decorator for registering a `Func` subclass for a specific `source`.
|
|
111
|
-
from_dict(data: dict) -> Func
|
|
112
|
-
Creates a `Func` (or registered subclass) instance from a dictionary.
|
|
113
|
-
_from_dict(data: dict) -> Func
|
|
114
|
-
Internal constructor used by `from_dict`.
|
|
115
103
|
"""
|
|
116
104
|
SOURCE = "function"
|
|
117
105
|
_registry: Dict[str, Type["Func"]] = {}
|
|
@@ -154,9 +142,16 @@ class Func(NamedModel):
|
|
|
154
142
|
return subclass
|
|
155
143
|
return decorator
|
|
156
144
|
|
|
145
|
+
_type_to_source = {
|
|
146
|
+
"Script": "script",
|
|
147
|
+
"DataQuery": "data-query",
|
|
148
|
+
}
|
|
149
|
+
|
|
157
150
|
@classmethod
|
|
158
151
|
def from_dict(cls, data: dict) -> "Func":
|
|
159
152
|
source = data.get("source")
|
|
153
|
+
if source is None:
|
|
154
|
+
source = Func._type_to_source.get(data.get("#type"))
|
|
160
155
|
subclass = Func._registry.get(source, cls)
|
|
161
156
|
return subclass._from_dict(data)
|
|
162
157
|
|
|
@@ -10,7 +10,7 @@ class Model(ABC):
|
|
|
10
10
|
It handles unique identification of model instances and ensures each instance
|
|
11
11
|
has a valid ID.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Attributes
|
|
14
14
|
----------
|
|
15
15
|
id : str
|
|
16
16
|
Unique identifier for the model instance. Can be None for new instances
|
|
@@ -39,7 +39,7 @@ class Model(ABC):
|
|
|
39
39
|
class NamedModel(Model, ABC):
|
|
40
40
|
"""NamedModel class that contains some common fields of Datagrok entities.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
Attributes
|
|
43
43
|
----------
|
|
44
44
|
name : Optional[str]
|
|
45
45
|
Internal name of the model, used as an identifier.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from datagrok_api.models.model import NamedModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Package(NamedModel):
|
|
7
|
+
"""
|
|
8
|
+
Represents a Datagrok package (plugin).
|
|
9
|
+
|
|
10
|
+
Attributes
|
|
11
|
+
----------
|
|
12
|
+
full_name : Optional[str]
|
|
13
|
+
Full package name (e.g., npm scope name).
|
|
14
|
+
description : Optional[str]
|
|
15
|
+
Package description.
|
|
16
|
+
category : Optional[str]
|
|
17
|
+
Package category.
|
|
18
|
+
image_url : Optional[str]
|
|
19
|
+
URL of the package icon/image.
|
|
20
|
+
url : Optional[str]
|
|
21
|
+
Package repository or homepage URL.
|
|
22
|
+
"""
|
|
23
|
+
def __init__(self,
|
|
24
|
+
name: str,
|
|
25
|
+
id: Optional[str] = None,
|
|
26
|
+
friendly_name: Optional[str] = None,
|
|
27
|
+
full_name: Optional[str] = None,
|
|
28
|
+
description: Optional[str] = None,
|
|
29
|
+
category: Optional[str] = None,
|
|
30
|
+
image_url: Optional[str] = None,
|
|
31
|
+
url: Optional[str] = None,
|
|
32
|
+
created_on: Optional[datetime] = None,
|
|
33
|
+
updated_on: Optional[datetime] = None):
|
|
34
|
+
super().__init__(id=id, name=name, friendly_name=friendly_name,
|
|
35
|
+
created_on=created_on, updated_on=updated_on)
|
|
36
|
+
self.full_name = full_name
|
|
37
|
+
self.description = description
|
|
38
|
+
self.category = category
|
|
39
|
+
self.image_url = image_url
|
|
40
|
+
self.url = url
|
|
41
|
+
|
|
42
|
+
def to_dict(self):
|
|
43
|
+
return {
|
|
44
|
+
"id": self.id,
|
|
45
|
+
"name": self.name,
|
|
46
|
+
"friendlyName": self.friendly_name,
|
|
47
|
+
"fullName": self.full_name,
|
|
48
|
+
"description": self.description,
|
|
49
|
+
"category": self.category,
|
|
50
|
+
"imageUrl": self.image_url,
|
|
51
|
+
"url": self.url,
|
|
52
|
+
"createdOn": self.created_on.isoformat() if self.created_on else None,
|
|
53
|
+
"updatedOn": self.updated_on.isoformat() if self.updated_on else None,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@classmethod
|
|
57
|
+
def from_dict(cls, data: dict) -> 'Package':
|
|
58
|
+
pkg = cls(
|
|
59
|
+
name=data.get("name", ""),
|
|
60
|
+
id=data.get("id"),
|
|
61
|
+
friendly_name=data.get("friendlyName"),
|
|
62
|
+
full_name=data.get("fullName"),
|
|
63
|
+
description=data.get("description"),
|
|
64
|
+
category=data.get("category"),
|
|
65
|
+
image_url=data.get("imageUrl"),
|
|
66
|
+
url=data.get("url"),
|
|
67
|
+
)
|
|
68
|
+
created_str = data.get("createdOn")
|
|
69
|
+
pkg.created_on = datetime.fromisoformat(created_str) if created_str else None
|
|
70
|
+
updated_str = data.get("updatedOn")
|
|
71
|
+
pkg.updated_on = datetime.fromisoformat(updated_str) if updated_str else None
|
|
72
|
+
return pkg
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class PublishedPackage(NamedModel):
|
|
76
|
+
"""
|
|
77
|
+
Represents a published version of a Datagrok package.
|
|
78
|
+
|
|
79
|
+
Attributes
|
|
80
|
+
----------
|
|
81
|
+
version : Optional[str]
|
|
82
|
+
Version string (e.g., "1.2.3").
|
|
83
|
+
is_current : bool
|
|
84
|
+
Whether this is the currently active version.
|
|
85
|
+
debug : bool
|
|
86
|
+
Whether this is a debug (dev) build.
|
|
87
|
+
package_author : Optional[str]
|
|
88
|
+
Author of the package.
|
|
89
|
+
published_on : Optional[datetime]
|
|
90
|
+
When this version was published.
|
|
91
|
+
commit : Optional[str]
|
|
92
|
+
Git commit hash.
|
|
93
|
+
"""
|
|
94
|
+
def __init__(self,
|
|
95
|
+
name: str,
|
|
96
|
+
id: Optional[str] = None,
|
|
97
|
+
friendly_name: Optional[str] = None,
|
|
98
|
+
version: Optional[str] = None,
|
|
99
|
+
is_current: bool = False,
|
|
100
|
+
debug: bool = False,
|
|
101
|
+
package_author: Optional[str] = None,
|
|
102
|
+
published_on: Optional[datetime] = None,
|
|
103
|
+
commit: Optional[str] = None,
|
|
104
|
+
created_on: Optional[datetime] = None,
|
|
105
|
+
updated_on: Optional[datetime] = None):
|
|
106
|
+
super().__init__(id=id, name=name, friendly_name=friendly_name,
|
|
107
|
+
created_on=created_on, updated_on=updated_on)
|
|
108
|
+
self.version = version
|
|
109
|
+
self.is_current = is_current
|
|
110
|
+
self.debug = debug
|
|
111
|
+
self.package_author = package_author
|
|
112
|
+
self.published_on = published_on
|
|
113
|
+
self.commit = commit
|
|
114
|
+
|
|
115
|
+
def to_dict(self):
|
|
116
|
+
return {
|
|
117
|
+
"id": self.id,
|
|
118
|
+
"name": self.name,
|
|
119
|
+
"friendlyName": self.friendly_name,
|
|
120
|
+
"version": self.version,
|
|
121
|
+
"isCurrent": self.is_current,
|
|
122
|
+
"debug": self.debug,
|
|
123
|
+
"packageAuthor": self.package_author,
|
|
124
|
+
"publishedOn": self.published_on.isoformat() if self.published_on else None,
|
|
125
|
+
"commit": self.commit,
|
|
126
|
+
"createdOn": self.created_on.isoformat() if self.created_on else None,
|
|
127
|
+
"updatedOn": self.updated_on.isoformat() if self.updated_on else None,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@classmethod
|
|
131
|
+
def from_dict(cls, data: dict) -> 'PublishedPackage':
|
|
132
|
+
pkg = cls(
|
|
133
|
+
name=data.get("name", ""),
|
|
134
|
+
id=data.get("id"),
|
|
135
|
+
friendly_name=data.get("friendlyName"),
|
|
136
|
+
version=data.get("version"),
|
|
137
|
+
is_current=data.get("isCurrent", False),
|
|
138
|
+
debug=data.get("debug", False),
|
|
139
|
+
package_author=data.get("packageAuthor"),
|
|
140
|
+
commit=data.get("commit"),
|
|
141
|
+
)
|
|
142
|
+
for field, key in [("created_on", "createdOn"), ("updated_on", "updatedOn"), ("published_on", "publishedOn")]:
|
|
143
|
+
val = data.get(key)
|
|
144
|
+
if val:
|
|
145
|
+
setattr(pkg, field, datetime.fromisoformat(val))
|
|
146
|
+
return pkg
|