Skip to content

Commit 78fc7ac

Browse files
authored
Update README.md
1 parent cebbcd4 commit 78fc7ac

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

README.md

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,49 @@ If you modified environment variables (for Windows or Linux) restart your InterS
1919

2020
# Use
2121

22-
1. Call: `do ##class(isc.py.Callout).Setup()` once per systems start (add to ZSTART: [docs](https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GSTU_customize#GSTU_customize_startstop), [sample](https://gist.githubusercontent.com/eduard93/412ed81e2bf619269ab4a49d939d2304/raw/c9d5f922827db5052b6e1195616d333ffe7dc1ec/%2525ZSTART)).
23-
2. Call main method (can be called many times, context persists): `write ##class(isc.py.Callout).SimpleString(code, data)`
24-
3. Call: `do ##class(isc.py.Callout).Finalize()` to free Python context.
25-
4. Call: `write ##class(isc.py.Callout).Unload()` to free callout library.
22+
1. Call: `set sc = ##class(isc.py.Callout).Setup()` once per systems start (add to ZSTART: [docs](https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GSTU_customize#GSTU_customize_startstop), [sample](https://gist.githubusercontent.com/eduard93/412ed81e2bf619269ab4a49d939d2304/raw/c9d5f922827db5052b6e1195616d333ffe7dc1ec/%2525ZSTART)).
23+
2. Call main method (can be called many times, context persists): `write ##class(isc.py.Main).SimpleString(code, variable, , .result)`
24+
3. Call: `set sc = ##class(isc.py.Callout).Finalize()` to free Python context.
25+
4. Call: `set sc = ##class(isc.py.Callout).Unload()` to free callout library.
2626

2727
```
28-
do ##class(isc.py.Callout).Setup()
29-
write ##class(isc.py.Callout).SimpleString("x='ПРИВЕТ'","x")
30-
write ##class(isc.py.Callout).SimpleString("x=repr('ПРИВЕТ')","x")
31-
write ##class(isc.py.Callout).SimpleString("x=123","x")
32-
do ##class(isc.py.Callout).Finalize()
33-
write ##class(isc.py.Callout).Unload()
28+
set sc = ##class(isc.py.Callout).Setup()
29+
set sc = ##class(isc.py.Callout).SimpleString("x='HELLO'", "x", , .x)
30+
write x
31+
set sc = ##class(isc.py.Callout).Finalize()
32+
set sc = ##class(isc.py.Callout).Unload()
3433
```
3534

35+
Generally the main interface to Python is `isc.py.Main`. It offers these methods (all return `%Status`):
36+
37+
- `SimpleString(code, returnVariable, serialization, .result)` - for cases where both code and variable are strings.
38+
- `ExcuteCode(code, variable)` - execute `code` (it may be a stream or string), optionally ser result into `variable`.
39+
- `GetVariable(variable, serialization, .stream, useString)` - get `serialization` of `variable` in `stream`. If `useString` is 1 and variable serialization can fit into string then string is returned instead of the stream.
40+
- `GetVariableInfo(variable, serialization, .defined, .type, .length)` - get info about variable: is it defined, type,and serialization length.
41+
- `GetStatus()` - returns last occured exception in Python and clears it.
42+
- `GetVariableJson(variable, .stream, useString)` - get JSON serialization of variable.
43+
- `GetVariablePickle(variable, .stream, useString)` - get Pickle serialization of variable.
44+
45+
Possible Serializations:
46+
- `##class(isc.py.Callout).SerializationStr` - Serialization by str() function
47+
- `##class(isc.py.Callout).SerializationRepr` - Serialization by repr() function
48+
3649
# Context persistence
3750

3851
Python context can be persisted into InterSystems IRIS and restored later on. There are currently three public functions:
3952

40-
- Save context: `set sc = ##class(isc.py.data.Context).SaveContext(.context, verbose)` where `verbose` specifies displaying context after saving, and `context` is a resulting Python context. Get context id with `context.%Id()`
53+
- Save context: `set sc = ##class(isc.py.data.Context).SaveContext(.context, maxLength, mask, verbose)` where `maxLength` - maximum length of saved variable. If veriable serialization is longer than that, it would be ignored. Set to 0 to get them all, `mask` - comma separated list of variables to save (special symbols * and ? are recognized), `verbose` specifies displaying context after saving, and `context` is a resulting Python context. Get context id with `context.%Id()`
4154
- Display context: `do ##class(isc.py.data.Context).DisplayContext(id)` where `id` is an id of a stored context. Leave empty to display current context.
4255
- Restore context: `do ##class(isc.py.data.Context).RestoreContext(id, verbose, clear)` where `clear` kills currently loaded context if set to 1.
4356

4457
Context is saved into `isc.py.data` package and can be viewed/edited by SQL and object methods.
4558

4659
# Interoperability adapter
4760

48-
Interoperability adapter offers abulity to interact with Python process from Interoperability productions. Currently three operations are supported:
61+
Interoperability adapter `isc.py.ens.Operation` offers abulity to interact with Python process from Interoperability productions. Currently three operations are supported:
4962

5063
- Execute Python code via `isc.py.msg.ExecutionRequest`. Returns `isc.py.msg.ExecutionResponse` with requested variable values
64+
- Execute Python code via `isc.py.msg.StreamExecutionRequest`. Returns `isc.py.msg.StreamExecutionResponse` with requested variable values. Same as above, but accepts and returns streams instead of strings.
5165
- Save Python conext via `isc.py.msg.SaveRequest`. Returns `Ens.StringResponse` with context id.
5266
- Restore Python context via `isc.py.msg.RestoreRequest`.
5367

@@ -57,15 +71,22 @@ Check request/response classes documentation for details.
5771

5872
Along with callout code and Interoperability adapter there's also a test Interoperability Production and test Business Process. To use them:
5973

60-
1. In OS bash execute `python -m pip install pyodbc pandas matplotlib seaborn`.
74+
1. In OS bash execute `pip install pyodbc pandas matplotlib seaborn`.
6175
2. Execute: `do ##class(isc.py.test.CannibalizationData).Import()` to populate test data.
62-
3. Create ODBC connection to the namespace with data
63-
4. In test Business Process `isc.py.test.Process` edit annotation for `Correlation Matrix: Tabular` call, specifying correct ODBC DSN in line 3
76+
3. Create ODBC or JDBC connection to the namespace with data.
77+
4. In test Business Process `isc.py.test.Process` edit annotation for `ODBC connection` or `JDBC connection` call, specifying correct DSN.
6478
5. Edit annotation for `Correlation Matrix: Graph` call, specifying valid filepath for `f.savefig` function.
6579
6. Save and compile business process.
80+
7. Configure `ConnectionType` setting for a business process.
6681
7. Start `isc.py.test.Production` production.
6782
8. Send empty `Ens.Request` mesage to the `isc.py.test.Process`.
6883

84+
Notes.
85+
86+
- If you want to use JDBC connection, install JayDeBeApi: `pip install JayDeBeApi`. On linux you might need to install `apt-get install python-apt`.
87+
- For ODBC on Linux insall `unixodbc unixodbc-dev python-pyodbc`.
88+
- If you get errors similar to `undefined symbol: _Py_TrueStruct` in `isc.py.ens.Operation`operation set setting `PythonLib` to `libpython3.6m.so` or even to a full path of the shared library.
89+
6990

7091
# Unit tests
7192

@@ -84,7 +105,7 @@ There are several limitaions associated with the use of PythonAdapter.
84105
1. Modules reinitialization. Some modules may only be loaded once diring process lifetime (i.e. numpy). While Finalization clears the context of the process, repeated load of such libraries terminates the process. Discussions: [1](https://stackoverflow.com/questions/14843408/python-c-embedded-segmentation-fault), [2](https://stackoverflow.com/questions/7676314/py-initialize-py-finalize-not-working-twice-with-numpy).
85106
2. Variables. Do not use these variables: `zzztype`, `zzzjson`, `zzzcount`, `zzzitem`, `zzzmodules`, `zzzvars`. They are used by `isc.py.data` package.
86107
3. Functions Do not redefine these functions `zzzmodulesfunc()`, `zzzvarsfunc()`. They are used by `isc.py.data` package.
87-
4. Context persistence. Only variables, which define a valid `repr` method could be restored correctly. User functions are currently not supported. Module import are supported.
108+
4. Context persistence. Only pickled variables could be restored correctly. User functions are currently not supported. Module imports are supported.
88109

89110
# Development
90111

@@ -109,3 +130,4 @@ Development of C code is done in Eclipse.
109130
3. Set `GLOBALS_HOME` environment variable to the root of Caché or Ensemble installation.
110131
4. Set environment variable `PYTHONVER` to the python version you want to build, i.e.: ` export PYTHONVER=3.6`
111132
5. In `<Repository>/c/` execute `make`.
133+

0 commit comments

Comments
 (0)