composapy 0.2.1__tar.gz → 0.13.2__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.
- composapy-0.13.2/PKG-INFO +308 -0
- composapy-0.13.2/README.md +286 -0
- composapy-0.13.2/composapy/__init__.py +13 -0
- composapy-0.13.2/composapy/api.py +12 -0
- composapy-0.13.2/composapy/auth.py +7 -0
- composapy-0.13.2/composapy/bindings.py +30 -0
- composapy-0.13.2/composapy/config.py +130 -0
- composapy-0.13.2/composapy/dataflow/api.py +157 -0
- composapy-0.13.2/composapy/dataflow/const.py +3 -0
- composapy-0.13.2/composapy/dataflow/io.py +72 -0
- composapy-0.13.2/composapy/dataflow/models.py +396 -0
- composapy-0.13.2/composapy/decorators.py +31 -0
- composapy-0.13.2/composapy/interactive/itable.py +109 -0
- composapy-0.13.2/composapy/interactive/options.py +3 -0
- composapy-0.13.2/composapy/key/__init__.py +0 -0
- composapy-0.13.2/composapy/key/api.py +101 -0
- composapy-0.13.2/composapy/key/models.py +135 -0
- composapy-0.13.2/composapy/loader.py +165 -0
- composapy-0.13.2/composapy/magics.py +73 -0
- composapy-0.13.2/composapy/mixins.py +61 -0
- composapy-0.13.2/composapy/notebook/__init__.py +0 -0
- composapy-0.13.2/composapy/notebook/inject.py +73 -0
- composapy-0.13.2/composapy/notebook/nb_wrap.py +113 -0
- composapy-0.13.2/composapy/notebook/nbr_globals.py +2 -0
- composapy-0.13.2/composapy/notebook/script_wrap.py +52 -0
- composapy-0.13.2/composapy/patch/__init__.py +76 -0
- composapy-0.13.2/composapy/patch/execution_handle.py +44 -0
- composapy-0.13.2/composapy/patch/file_reference.py +128 -0
- composapy-0.13.2/composapy/patch/queryview.py +15 -0
- composapy-0.13.2/composapy/patch/table.py +359 -0
- composapy-0.13.2/composapy/queryview/__init__.py +0 -0
- composapy-0.13.2/composapy/queryview/api.py +212 -0
- composapy-0.13.2/composapy/queryview/const.py +5 -0
- composapy-0.13.2/composapy/queryview/models.py +269 -0
- composapy-0.13.2/composapy/session.py +289 -0
- composapy-0.13.2/composapy/static/datatables_template.html +107 -0
- {composapy-0.2.1/src → composapy-0.13.2}/composapy/stream.py +1 -1
- composapy-0.13.2/composapy/testdlls.py +36 -0
- composapy-0.13.2/composapy/utils.py +54 -0
- composapy-0.13.2/composapy.egg-info/PKG-INFO +308 -0
- composapy-0.13.2/composapy.egg-info/SOURCES.txt +105 -0
- composapy-0.13.2/composapy.egg-info/requires.txt +8 -0
- {composapy-0.2.1/src → composapy-0.13.2}/composapy.egg-info/top_level.txt +1 -0
- {composapy-0.2.1 → composapy-0.13.2}/setup.cfg +19 -7
- composapy-0.13.2/tests/__init__.py +0 -0
- composapy-0.13.2/tests/conftest.py +366 -0
- composapy-0.13.2/tests/test_api.py +280 -0
- composapy-0.13.2/tests/test_key.py +72 -0
- composapy-0.13.2/tests/test_loader.py +90 -0
- composapy-0.13.2/tests/test_models.py +95 -0
- composapy-0.13.2/tests/test_queryview.py +492 -0
- composapy-0.13.2/tests/test_session.py +90 -0
- composapy-0.13.2/tests/test_windows_auth.py +205 -0
- composapy-0.2.1/PKG-INFO +0 -20
- composapy-0.2.1/README.md +0 -1
- composapy-0.2.1/src/composapy/__init__.py +0 -2
- composapy-0.2.1/src/composapy/api.py +0 -10
- composapy-0.2.1/src/composapy/dataflow/api.py +0 -97
- composapy-0.2.1/src/composapy/dataflow/models.py +0 -272
- composapy-0.2.1/src/composapy/loader.py +0 -54
- composapy-0.2.1/src/composapy/mixins.py +0 -119
- composapy-0.2.1/src/composapy/queryview/api.py +0 -100
- composapy-0.2.1/src/composapy/session.py +0 -62
- composapy-0.2.1/src/composapy.egg-info/PKG-INFO +0 -20
- composapy-0.2.1/src/composapy.egg-info/SOURCES.txt +0 -19
- {composapy-0.2.1 → composapy-0.13.2}/LICENSE +0 -0
- {composapy-0.2.1/src → composapy-0.13.2}/composapy/dataflow/__init__.py +0 -0
- {composapy-0.2.1/src/composapy/queryview → composapy-0.13.2/composapy/interactive}/__init__.py +0 -0
- {composapy-0.2.1/src → composapy-0.13.2}/composapy.egg-info/dependency_links.txt +0 -0
- {composapy-0.2.1 → composapy-0.13.2}/pyproject.toml +0 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: composapy
|
|
3
|
+
Version: 0.13.2
|
|
4
|
+
Summary: ComposableAnalytics csharp binding for python
|
|
5
|
+
Home-page: https://github.com/ComposableAnalytics/Composapy
|
|
6
|
+
Author: Composable
|
|
7
|
+
Author-email: support@composableanalytics.com
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/ComposableAnalytics/Composapy/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.7.1
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Provides-Extra: deps
|
|
16
|
+
Requires-Dist: pythonnet==3.0.1; extra == "deps"
|
|
17
|
+
Requires-Dist: clr-loader==0.2.5; extra == "deps"
|
|
18
|
+
Requires-Dist: numpy<=1.25.0; extra == "deps"
|
|
19
|
+
Requires-Dist: pandas<=2.0.3; extra == "deps"
|
|
20
|
+
Requires-Dist: papermill; extra == "deps"
|
|
21
|
+
Requires-Dist: json-fix; extra == "deps"
|
|
22
|
+
|
|
23
|
+
# Composapy
|
|
24
|
+
|
|
25
|
+
DataLabs comes pre-installed with Composapy, a python package that makes it easy to
|
|
26
|
+
programmatically interface with Composable. Composapy allows you to interactively author, execute
|
|
27
|
+
and retrieve results from DataFlows (Directed Acyclic Graphs, DAGs).
|
|
28
|
+
|
|
29
|
+
Visit our [ReadTheDocs](https://composapy.readthedocs.io/) page a more detailed look at
|
|
30
|
+
Composapy.
|
|
31
|
+
|
|
32
|
+
- [Session](#session)
|
|
33
|
+
- [Register a Session](#register-a-session)
|
|
34
|
+
- [DataFlow](#dataflow)
|
|
35
|
+
- [Create and Save a DataFlow](#create-and-save-a-dataflow)
|
|
36
|
+
- [Run a DataFlow](#run-a-dataflow)
|
|
37
|
+
- [DataFlowObject and DataFlowRun Modules](#dataflowobject-and-dataflowrun-modules)
|
|
38
|
+
- [DataFlowObject and DataFlowRun Input](#dataflowobject-and-dataflowrun-input)
|
|
39
|
+
- [DataFlowRun Result](#dataflowrun-result)
|
|
40
|
+
- [Key](#key)
|
|
41
|
+
- [Retrieve Key](#retrieve-key)
|
|
42
|
+
- [Register Key](#register-key)
|
|
43
|
+
- [Search for Key](#search-for-key)
|
|
44
|
+
- [QueryView](#queryview)
|
|
45
|
+
- [Create and Connect to a QueryView Driver](#create-and-connect-to-a-queryview-driver)
|
|
46
|
+
- [Run a Query](#run-a-query)
|
|
47
|
+
- [SQL Magic Commands](#sql-magic-commands)
|
|
48
|
+
- [Run a Saved QueryView](#run-a-saved-queryview)
|
|
49
|
+
- [Interactive Table Output](#interactive-table-output)
|
|
50
|
+
- [QueryView Driver Output](#queryview-driver-output)
|
|
51
|
+
- [SQL Cell Magic Output](#sql-cell-magic-output)
|
|
52
|
+
- [Saved QueryView Output](#saved-queryview-output)
|
|
53
|
+
- [Table Contract Output](#table-contract-output)
|
|
54
|
+
- [Additional Information](#additional-information)
|
|
55
|
+
|
|
56
|
+
## Session
|
|
57
|
+
|
|
58
|
+
[ReadTheDocs - Session](https://composapy.readthedocs.io/reference/composapy-session.html)
|
|
59
|
+
|
|
60
|
+
### Register a Session
|
|
61
|
+
|
|
62
|
+
Composapy looks for the environment variable `APPLICATION_URI` by default (set by DataLabs). If you are using Composapy outside of the datalabs environment and the `APPLICATION_URI`
|
|
63
|
+
environment variable is not set, you can set it with keyword argument `uri`. You can create a session with Windows Authentication (if you are in DataLab, this will be the same as the
|
|
64
|
+
key on the DataLab edit screen), [`string`] API Token (can be generated on the composable website), or with a [`tuple[str, str]`] username/password combination.
|
|
65
|
+
|
|
66
|
+
```python pycharm={"name": "#%%\n"}
|
|
67
|
+
from composapy.session import Session
|
|
68
|
+
from composapy.auth import AuthMode
|
|
69
|
+
|
|
70
|
+
session = Session(auth_mode=AuthMode.WINDOWS)
|
|
71
|
+
session = Session(auth_mode=AuthMode.TOKEN, credentials="<your-api-token-here>", uri="http://localhost/CompAnalytics/")
|
|
72
|
+
session = Session(auth_mode=AuthMode.FORM, credentials=("username", "password"))
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
After creating a session, register it (future operations use this session by _default_). Optionally, enable the `save` flag to write to a local config file for automatical loading/registration on next Composapy import.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
session.register()
|
|
79
|
+
session.register(save=True)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You can also call `get_session` to get the currently registered session.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from composapy.session import get_session
|
|
86
|
+
|
|
87
|
+
session = get_session()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## DataFlow
|
|
91
|
+
|
|
92
|
+
[ReadTheDocs - DataFlow](https://composapy.readthedocs.io/reference/composapy-dataflow/index.html)
|
|
93
|
+
|
|
94
|
+
### Create and Save a DataFlow
|
|
95
|
+
|
|
96
|
+
[DataFlowObject's](#dataflowobject) can be initialized with the [DataFlow API](#dataflow) method - [create](#create). It takes either a json string (_kwarg_ `json`) or path to a json file (_kwarg_ `file_path`) as parameters. Call the `save` method on an unsaved `DataFlowObject` to save it in the Composable database. Saving it will make give it an `id`, making it available for use in the [Composable Designer](https://github.com/ComposableAnalytics/Docs/blob/master/docs/DataFlows/02.Composable-Designer.md).
|
|
97
|
+
|
|
98
|
+
```python pycharm={"name": "#%%\n"}
|
|
99
|
+
from composapy.dataflow.api import DataFlow
|
|
100
|
+
|
|
101
|
+
dataflow_object = DataFlow.create(file_path="simple-dataflow.json") # DataFlowObject(id=None)
|
|
102
|
+
dataflow_object = DataFlow.create(file_path="simple-dataflow.json").save() # DataFlowObject(id=123456)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Run a DataFlow
|
|
106
|
+
|
|
107
|
+
To run a saved DataFlow, you can retrieve the `appId` in the DataFlow's URL.
|
|
108
|
+
|
|
109
|
+
```python pycharm={"name": "#%%\n"}
|
|
110
|
+
dataflow_run = DataFlow.run(444333) # DataFlowRun(id=444333)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
To run a DataFlow that has external input modules, use the `external_inputs` kwarg, which is a dictionary with key equal to the external modules name field and the value equal to what you want to pass in.
|
|
114
|
+
|
|
115
|
+
```python pycharm={"name": "#%%\n"}
|
|
116
|
+
dataflow_run = DataFlow.run(444333, external_inputs={"a_string_external_input": "foo string"}) # DataFlowRun(id=444333)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### DataFlowObject and DataFlowRun Modules
|
|
120
|
+
|
|
121
|
+
```python pycharm={"name": "#%%\n"}
|
|
122
|
+
dataflow_run.modules[0] # Module(name='Calculator', type=Calculator)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### DataFlowObject and DataFlowRun Input
|
|
126
|
+
|
|
127
|
+
```python pycharm={"name": "#%%\n"}
|
|
128
|
+
dataflow_object.modules.filter(name="calc module name")[0].inputs.first() # Input(name=Param1, type=Double, value=1.0)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### DataFlowRun Result
|
|
132
|
+
|
|
133
|
+
```python pycharm={"name": "#%%\n"}
|
|
134
|
+
dataflow_run.modules.get(name="string module name").result # Result(name='foo name', type=String, value='foo value')
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Key
|
|
138
|
+
|
|
139
|
+
[ReadTheDocs - Key](https://composapy.readthedocs.io/reference/composapy-key/index.html)
|
|
140
|
+
|
|
141
|
+
### Retrieve Key
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
A Composapy Key can be retrieved using the python Key API.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from composapy.key.api import Key
|
|
148
|
+
|
|
149
|
+
key_object = Key.get(123456) # KeyObject(name='some name', type='StringConnectionSettings')
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Optionally, if your key name is unique, you can retrieve it by name.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
key_object = Key.get(name="a unique name") # KeyObject(name='a unique name', type='SqlConnectionSettings')
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Register Key
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
Similar to Session, KeyObjects can be registered with the `save=True` flag. This will save the key id in the working directory's "composapy.ini" file, which will then be loaded when the Composapy package is imported.
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
key_object.register(save=True)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
You can retrieve the currently registered key_object with `get_key_object`.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from composapy.key.models import get_key_object
|
|
171
|
+
|
|
172
|
+
get_key_object() # KeyObject(name='a unique name', type='SqlConnectionSettings')
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Search for Key
|
|
176
|
+
|
|
177
|
+
Keys can be searched by name. It returns a list of key objects.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
key_objects = Key.search("same name") # [KeyObject(name='same name', type='SqlConnectionSettings'), KeyObject(name='same name', type='StringConnectionSettings')]
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## QueryView
|
|
184
|
+
|
|
185
|
+
[ReadTheDocs - QueryView](https://composapy.readthedocs.io/reference/composapy-queryview/index.html)
|
|
186
|
+
|
|
187
|
+
### Create and Connect to a QueryView Driver
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from composapy.queryview.api import QueryView
|
|
191
|
+
|
|
192
|
+
driver = QueryView.driver() # you can create a driver and then connect with a key...
|
|
193
|
+
driver.connect(key_object)
|
|
194
|
+
|
|
195
|
+
driver = QueryView.driver(key_object) # ... or create a driver using the key as an argument
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
If there is a currently registered key, there is no need to pass the key to the driver object; the driver will be automatically initialized with the database connection.
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
QueryView.driver()
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Run a Query
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
df = driver.run("select * from table_name") # returns a Pandas DataFrame of your query
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### SQL Magic Commands
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
In a notebook (IPython) environment, custom sql magic commands are loaded on import with Composapy. Note that both `%sql` and `%%sql` require a registered Session and KeyObject. Both can be loaded on import if saved in the "composapy.ini" config file. See [register-session](#register-a-session) and [register-key](#register-key).
|
|
214
|
+
|
|
215
|
+
```python vscode={"languageId": "sql"}
|
|
216
|
+
%sql select * from some_table --returns the same result as QueryView.driver("select * from some_table")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Instead of doing line magic (only takes that line as input), you can alternatively do cell magic (takes entire cell as input).
|
|
220
|
+
|
|
221
|
+
```sql vscode={"languageId": "sql"}
|
|
222
|
+
select
|
|
223
|
+
*
|
|
224
|
+
from
|
|
225
|
+
some_table
|
|
226
|
+
where
|
|
227
|
+
some_id is not null
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
`%%sql` cell magic also supports options to customize the query execution, such as setting a timeout value or capturing the output of the query into a Python variable. Run %%sql? for detailed documentation.
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
### Run a Saved QueryView
|
|
234
|
+
|
|
235
|
+
To run a saved QueryView, you can retrieve the ID in the QueryView's URL and invoke the static `run` method without needing to create a driver object.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from composapy.queryview.api import QueryView
|
|
239
|
+
|
|
240
|
+
QueryView.run(123456) # returns a Pandas DataFrame with the query results
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
If the QueryView has literal or filter inputs, you can optionally pass values and operators to the `run` method using the `inputs` argument. This argument must be a dictionary whose keys are the display name of the input. There are two possible formats for the dictionary values, depending on the kind of input:
|
|
244
|
+
|
|
245
|
+
1. [LITERAL, FILTER] A single Python primitive (`int`, `bool`, `str`, `float`). The default operator will be used for filter inputs in this case.
|
|
246
|
+
2. [FILTER] A tuple of size two in the form `(val, operator)` where `val` is the primitive input value and `operator` is one of the acceptable QueryView input operators (=, !=, >, <, >=, <=, LIKE)
|
|
247
|
+
|
|
248
|
+
As of Composapy 0.13.1, multi-choice inputs are supported. To pass a multi-choice input, sets, tuples, and lists that contain primitive values are accepted. Due to the current nature of filter inputs requiring tuple format, literal multi-choice inputs must be passed as a tuple containing a set, tuple, or list of primitive values, like so, for instance: [{item1,item2}]. This is in order to preserve parsing logic for filter inputs, which would follow a similar format: [{item1,item2},operator].
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
QueryView.run(123456, inputs={"displayName1": "val1", "displayName2": (100, "!=")})
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Interactive Table Output
|
|
255
|
+
|
|
256
|
+
Some operations that return Pandas DataFrames can also be run in interactive mode, which renders the data as an interactive DataTable with server-side processing for pagination. There are four main operations that can return interactive tables:
|
|
257
|
+
1. QueryView driver output
|
|
258
|
+
2. `%%sql` cell magic output
|
|
259
|
+
3. Saved QueryView output
|
|
260
|
+
4. Table contract output
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
#### QueryView Driver Output
|
|
265
|
+
When creating a QueryView driver, set `interactive=True`:
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
from composapy.queryview.api import QueryView
|
|
269
|
+
QueryView.driver(interactive=True)
|
|
270
|
+
driver.run("select * from table")
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Note that unlike other QueryView driver settings, `interactive` can only be set when `driver()` is called, not when `run()` is called.
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
#### SQL Cell Magic Output
|
|
277
|
+
Simply pass the `-i` flag to the `%%sql` magic command:
|
|
278
|
+
|
|
279
|
+
```sql vscode={"languageId": "sql"} magic_args="-i"
|
|
280
|
+
select * from table
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
#### Saved QueryView Output
|
|
284
|
+
When running a saved QueryView, pass the `interactive=True` argument to `run()`:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from composapy.queryview.api import QueryView
|
|
288
|
+
QueryView.run(12345, interactive=True)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Note that the paging options set in the QueryView will be respected. If no paging options are set, Auto Paging will be used.
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
#### Table Contract Output
|
|
295
|
+
When a table contract is passed into a DataLab (either via running a DataFlow or as a notebook runner input), it can be viewed interactively by setting a global option. The below example runs a DataFlow that contains an Odbc Query module, which has a Table output:
|
|
296
|
+
|
|
297
|
+
```python
|
|
298
|
+
import composapy.interactive.options as iopts
|
|
299
|
+
iopts.SHOW_INTERACTIVE_TABLES = True
|
|
300
|
+
|
|
301
|
+
from composapy.dataflow.api import DataFlow
|
|
302
|
+
table_contract = DataFlow.run(1234).modules.get(name="Odbc Query").result.value
|
|
303
|
+
table_contract # NOTE: you can also use display(table_contract), but don't use print(table_contract)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Additional Information
|
|
307
|
+
|
|
308
|
+
Also, if you want to interface with <a href="https://github.com/pythonnet/pythonnet" target="_blank">pythonnet</a> more closely, you can find our csharp documentation <a href="https://dev.composable.ai/api/CompAnalytics.Contracts.html" target="_blank">here</a>.
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# Composapy
|
|
2
|
+
|
|
3
|
+
DataLabs comes pre-installed with Composapy, a python package that makes it easy to
|
|
4
|
+
programmatically interface with Composable. Composapy allows you to interactively author, execute
|
|
5
|
+
and retrieve results from DataFlows (Directed Acyclic Graphs, DAGs).
|
|
6
|
+
|
|
7
|
+
Visit our [ReadTheDocs](https://composapy.readthedocs.io/) page a more detailed look at
|
|
8
|
+
Composapy.
|
|
9
|
+
|
|
10
|
+
- [Session](#session)
|
|
11
|
+
- [Register a Session](#register-a-session)
|
|
12
|
+
- [DataFlow](#dataflow)
|
|
13
|
+
- [Create and Save a DataFlow](#create-and-save-a-dataflow)
|
|
14
|
+
- [Run a DataFlow](#run-a-dataflow)
|
|
15
|
+
- [DataFlowObject and DataFlowRun Modules](#dataflowobject-and-dataflowrun-modules)
|
|
16
|
+
- [DataFlowObject and DataFlowRun Input](#dataflowobject-and-dataflowrun-input)
|
|
17
|
+
- [DataFlowRun Result](#dataflowrun-result)
|
|
18
|
+
- [Key](#key)
|
|
19
|
+
- [Retrieve Key](#retrieve-key)
|
|
20
|
+
- [Register Key](#register-key)
|
|
21
|
+
- [Search for Key](#search-for-key)
|
|
22
|
+
- [QueryView](#queryview)
|
|
23
|
+
- [Create and Connect to a QueryView Driver](#create-and-connect-to-a-queryview-driver)
|
|
24
|
+
- [Run a Query](#run-a-query)
|
|
25
|
+
- [SQL Magic Commands](#sql-magic-commands)
|
|
26
|
+
- [Run a Saved QueryView](#run-a-saved-queryview)
|
|
27
|
+
- [Interactive Table Output](#interactive-table-output)
|
|
28
|
+
- [QueryView Driver Output](#queryview-driver-output)
|
|
29
|
+
- [SQL Cell Magic Output](#sql-cell-magic-output)
|
|
30
|
+
- [Saved QueryView Output](#saved-queryview-output)
|
|
31
|
+
- [Table Contract Output](#table-contract-output)
|
|
32
|
+
- [Additional Information](#additional-information)
|
|
33
|
+
|
|
34
|
+
## Session
|
|
35
|
+
|
|
36
|
+
[ReadTheDocs - Session](https://composapy.readthedocs.io/reference/composapy-session.html)
|
|
37
|
+
|
|
38
|
+
### Register a Session
|
|
39
|
+
|
|
40
|
+
Composapy looks for the environment variable `APPLICATION_URI` by default (set by DataLabs). If you are using Composapy outside of the datalabs environment and the `APPLICATION_URI`
|
|
41
|
+
environment variable is not set, you can set it with keyword argument `uri`. You can create a session with Windows Authentication (if you are in DataLab, this will be the same as the
|
|
42
|
+
key on the DataLab edit screen), [`string`] API Token (can be generated on the composable website), or with a [`tuple[str, str]`] username/password combination.
|
|
43
|
+
|
|
44
|
+
```python pycharm={"name": "#%%\n"}
|
|
45
|
+
from composapy.session import Session
|
|
46
|
+
from composapy.auth import AuthMode
|
|
47
|
+
|
|
48
|
+
session = Session(auth_mode=AuthMode.WINDOWS)
|
|
49
|
+
session = Session(auth_mode=AuthMode.TOKEN, credentials="<your-api-token-here>", uri="http://localhost/CompAnalytics/")
|
|
50
|
+
session = Session(auth_mode=AuthMode.FORM, credentials=("username", "password"))
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
After creating a session, register it (future operations use this session by _default_). Optionally, enable the `save` flag to write to a local config file for automatical loading/registration on next Composapy import.
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
session.register()
|
|
57
|
+
session.register(save=True)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
You can also call `get_session` to get the currently registered session.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from composapy.session import get_session
|
|
64
|
+
|
|
65
|
+
session = get_session()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## DataFlow
|
|
69
|
+
|
|
70
|
+
[ReadTheDocs - DataFlow](https://composapy.readthedocs.io/reference/composapy-dataflow/index.html)
|
|
71
|
+
|
|
72
|
+
### Create and Save a DataFlow
|
|
73
|
+
|
|
74
|
+
[DataFlowObject's](#dataflowobject) can be initialized with the [DataFlow API](#dataflow) method - [create](#create). It takes either a json string (_kwarg_ `json`) or path to a json file (_kwarg_ `file_path`) as parameters. Call the `save` method on an unsaved `DataFlowObject` to save it in the Composable database. Saving it will make give it an `id`, making it available for use in the [Composable Designer](https://github.com/ComposableAnalytics/Docs/blob/master/docs/DataFlows/02.Composable-Designer.md).
|
|
75
|
+
|
|
76
|
+
```python pycharm={"name": "#%%\n"}
|
|
77
|
+
from composapy.dataflow.api import DataFlow
|
|
78
|
+
|
|
79
|
+
dataflow_object = DataFlow.create(file_path="simple-dataflow.json") # DataFlowObject(id=None)
|
|
80
|
+
dataflow_object = DataFlow.create(file_path="simple-dataflow.json").save() # DataFlowObject(id=123456)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Run a DataFlow
|
|
84
|
+
|
|
85
|
+
To run a saved DataFlow, you can retrieve the `appId` in the DataFlow's URL.
|
|
86
|
+
|
|
87
|
+
```python pycharm={"name": "#%%\n"}
|
|
88
|
+
dataflow_run = DataFlow.run(444333) # DataFlowRun(id=444333)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
To run a DataFlow that has external input modules, use the `external_inputs` kwarg, which is a dictionary with key equal to the external modules name field and the value equal to what you want to pass in.
|
|
92
|
+
|
|
93
|
+
```python pycharm={"name": "#%%\n"}
|
|
94
|
+
dataflow_run = DataFlow.run(444333, external_inputs={"a_string_external_input": "foo string"}) # DataFlowRun(id=444333)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### DataFlowObject and DataFlowRun Modules
|
|
98
|
+
|
|
99
|
+
```python pycharm={"name": "#%%\n"}
|
|
100
|
+
dataflow_run.modules[0] # Module(name='Calculator', type=Calculator)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### DataFlowObject and DataFlowRun Input
|
|
104
|
+
|
|
105
|
+
```python pycharm={"name": "#%%\n"}
|
|
106
|
+
dataflow_object.modules.filter(name="calc module name")[0].inputs.first() # Input(name=Param1, type=Double, value=1.0)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### DataFlowRun Result
|
|
110
|
+
|
|
111
|
+
```python pycharm={"name": "#%%\n"}
|
|
112
|
+
dataflow_run.modules.get(name="string module name").result # Result(name='foo name', type=String, value='foo value')
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Key
|
|
116
|
+
|
|
117
|
+
[ReadTheDocs - Key](https://composapy.readthedocs.io/reference/composapy-key/index.html)
|
|
118
|
+
|
|
119
|
+
### Retrieve Key
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
A Composapy Key can be retrieved using the python Key API.
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from composapy.key.api import Key
|
|
126
|
+
|
|
127
|
+
key_object = Key.get(123456) # KeyObject(name='some name', type='StringConnectionSettings')
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Optionally, if your key name is unique, you can retrieve it by name.
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
key_object = Key.get(name="a unique name") # KeyObject(name='a unique name', type='SqlConnectionSettings')
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Register Key
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Similar to Session, KeyObjects can be registered with the `save=True` flag. This will save the key id in the working directory's "composapy.ini" file, which will then be loaded when the Composapy package is imported.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
key_object.register(save=True)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
You can retrieve the currently registered key_object with `get_key_object`.
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from composapy.key.models import get_key_object
|
|
149
|
+
|
|
150
|
+
get_key_object() # KeyObject(name='a unique name', type='SqlConnectionSettings')
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Search for Key
|
|
154
|
+
|
|
155
|
+
Keys can be searched by name. It returns a list of key objects.
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
key_objects = Key.search("same name") # [KeyObject(name='same name', type='SqlConnectionSettings'), KeyObject(name='same name', type='StringConnectionSettings')]
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## QueryView
|
|
162
|
+
|
|
163
|
+
[ReadTheDocs - QueryView](https://composapy.readthedocs.io/reference/composapy-queryview/index.html)
|
|
164
|
+
|
|
165
|
+
### Create and Connect to a QueryView Driver
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
from composapy.queryview.api import QueryView
|
|
169
|
+
|
|
170
|
+
driver = QueryView.driver() # you can create a driver and then connect with a key...
|
|
171
|
+
driver.connect(key_object)
|
|
172
|
+
|
|
173
|
+
driver = QueryView.driver(key_object) # ... or create a driver using the key as an argument
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
If there is a currently registered key, there is no need to pass the key to the driver object; the driver will be automatically initialized with the database connection.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
QueryView.driver()
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Run a Query
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
df = driver.run("select * from table_name") # returns a Pandas DataFrame of your query
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### SQL Magic Commands
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
In a notebook (IPython) environment, custom sql magic commands are loaded on import with Composapy. Note that both `%sql` and `%%sql` require a registered Session and KeyObject. Both can be loaded on import if saved in the "composapy.ini" config file. See [register-session](#register-a-session) and [register-key](#register-key).
|
|
192
|
+
|
|
193
|
+
```python vscode={"languageId": "sql"}
|
|
194
|
+
%sql select * from some_table --returns the same result as QueryView.driver("select * from some_table")
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Instead of doing line magic (only takes that line as input), you can alternatively do cell magic (takes entire cell as input).
|
|
198
|
+
|
|
199
|
+
```sql vscode={"languageId": "sql"}
|
|
200
|
+
select
|
|
201
|
+
*
|
|
202
|
+
from
|
|
203
|
+
some_table
|
|
204
|
+
where
|
|
205
|
+
some_id is not null
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`%%sql` cell magic also supports options to customize the query execution, such as setting a timeout value or capturing the output of the query into a Python variable. Run %%sql? for detailed documentation.
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
### Run a Saved QueryView
|
|
212
|
+
|
|
213
|
+
To run a saved QueryView, you can retrieve the ID in the QueryView's URL and invoke the static `run` method without needing to create a driver object.
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
from composapy.queryview.api import QueryView
|
|
217
|
+
|
|
218
|
+
QueryView.run(123456) # returns a Pandas DataFrame with the query results
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
If the QueryView has literal or filter inputs, you can optionally pass values and operators to the `run` method using the `inputs` argument. This argument must be a dictionary whose keys are the display name of the input. There are two possible formats for the dictionary values, depending on the kind of input:
|
|
222
|
+
|
|
223
|
+
1. [LITERAL, FILTER] A single Python primitive (`int`, `bool`, `str`, `float`). The default operator will be used for filter inputs in this case.
|
|
224
|
+
2. [FILTER] A tuple of size two in the form `(val, operator)` where `val` is the primitive input value and `operator` is one of the acceptable QueryView input operators (=, !=, >, <, >=, <=, LIKE)
|
|
225
|
+
|
|
226
|
+
As of Composapy 0.13.1, multi-choice inputs are supported. To pass a multi-choice input, sets, tuples, and lists that contain primitive values are accepted. Due to the current nature of filter inputs requiring tuple format, literal multi-choice inputs must be passed as a tuple containing a set, tuple, or list of primitive values, like so, for instance: [{item1,item2}]. This is in order to preserve parsing logic for filter inputs, which would follow a similar format: [{item1,item2},operator].
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
QueryView.run(123456, inputs={"displayName1": "val1", "displayName2": (100, "!=")})
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Interactive Table Output
|
|
233
|
+
|
|
234
|
+
Some operations that return Pandas DataFrames can also be run in interactive mode, which renders the data as an interactive DataTable with server-side processing for pagination. There are four main operations that can return interactive tables:
|
|
235
|
+
1. QueryView driver output
|
|
236
|
+
2. `%%sql` cell magic output
|
|
237
|
+
3. Saved QueryView output
|
|
238
|
+
4. Table contract output
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
#### QueryView Driver Output
|
|
243
|
+
When creating a QueryView driver, set `interactive=True`:
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
from composapy.queryview.api import QueryView
|
|
247
|
+
QueryView.driver(interactive=True)
|
|
248
|
+
driver.run("select * from table")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Note that unlike other QueryView driver settings, `interactive` can only be set when `driver()` is called, not when `run()` is called.
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
#### SQL Cell Magic Output
|
|
255
|
+
Simply pass the `-i` flag to the `%%sql` magic command:
|
|
256
|
+
|
|
257
|
+
```sql vscode={"languageId": "sql"} magic_args="-i"
|
|
258
|
+
select * from table
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### Saved QueryView Output
|
|
262
|
+
When running a saved QueryView, pass the `interactive=True` argument to `run()`:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from composapy.queryview.api import QueryView
|
|
266
|
+
QueryView.run(12345, interactive=True)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Note that the paging options set in the QueryView will be respected. If no paging options are set, Auto Paging will be used.
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
#### Table Contract Output
|
|
273
|
+
When a table contract is passed into a DataLab (either via running a DataFlow or as a notebook runner input), it can be viewed interactively by setting a global option. The below example runs a DataFlow that contains an Odbc Query module, which has a Table output:
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
import composapy.interactive.options as iopts
|
|
277
|
+
iopts.SHOW_INTERACTIVE_TABLES = True
|
|
278
|
+
|
|
279
|
+
from composapy.dataflow.api import DataFlow
|
|
280
|
+
table_contract = DataFlow.run(1234).modules.get(name="Odbc Query").result.value
|
|
281
|
+
table_contract # NOTE: you can also use display(table_contract), but don't use print(table_contract)
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Additional Information
|
|
285
|
+
|
|
286
|
+
Also, if you want to interface with <a href="https://github.com/pythonnet/pythonnet" target="_blank">pythonnet</a> more closely, you can find our csharp documentation <a href="https://dev.composable.ai/api/CompAnalytics.Contracts.html" target="_blank">here</a>.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .dataflow import *
|
|
2
|
+
from .queryview import *
|
|
3
|
+
|
|
4
|
+
from .loader import load_init
|
|
5
|
+
|
|
6
|
+
load_init()
|
|
7
|
+
|
|
8
|
+
from composapy.patch.file_reference import *
|
|
9
|
+
from composapy.patch.table import *
|
|
10
|
+
from composapy.patch.execution_handle import *
|
|
11
|
+
from composapy.patch.queryview import *
|
|
12
|
+
|
|
13
|
+
from composapy.utils import file_ref
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from System import TimeSpan
|
|
2
|
+
from System.ServiceModel import WebHttpBinding
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def configure_binding(service_name: str, binding: WebHttpBinding) -> WebHttpBinding:
|
|
6
|
+
if service_name in _service_binding_configs.keys():
|
|
7
|
+
binding = _service_binding_configs[service_name](binding)
|
|
8
|
+
return binding
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def query_view_binding(binding: WebHttpBinding):
|
|
12
|
+
binding.OpenTimeout = TimeSpan.MaxValue
|
|
13
|
+
binding.CloseTimeout = TimeSpan.MaxValue
|
|
14
|
+
binding.SendTimeout = TimeSpan.MaxValue
|
|
15
|
+
binding.ReceiveTimeout = TimeSpan.MaxValue
|
|
16
|
+
return binding
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def data_flow_binding(binding: WebHttpBinding):
|
|
20
|
+
binding.OpenTimeout = TimeSpan.MaxValue
|
|
21
|
+
binding.CloseTimeout = TimeSpan.MaxValue
|
|
22
|
+
binding.SendTimeout = TimeSpan.MaxValue
|
|
23
|
+
binding.ReceiveTimeout = TimeSpan.MaxValue
|
|
24
|
+
return binding
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_service_binding_configs = {
|
|
28
|
+
"QueryViewService": query_view_binding,
|
|
29
|
+
"ApplicationService": data_flow_binding,
|
|
30
|
+
}
|