Difference between revisions of "Python Module"
Barrymavin (Talk | contribs) |
Barrymavin (Talk | contribs) (→Using the Lianja Cloud Data Services module in Python Applications) |
||
(16 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/ | cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/ | ||
pip install -r requirements.txt | pip install -r requirements.txt | ||
+ | </code> | ||
+ | |||
+ | On MacOS: | ||
+ | |||
+ | <code lang='bash'> | ||
+ | cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/ | ||
+ | python3 pip install -r requirements.txt --user | ||
</code> | </code> | ||
Line 30: | Line 37: | ||
<code lang='bash'> | <code lang='bash'> | ||
− | cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\ | + | cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\python\lianjaclouddataservices\ |
− | + | python test.py</code> | |
+ | |||
+ | On Linux: | ||
+ | |||
+ | <code lang='bash'> | ||
+ | cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ | ||
+ | python test.py</code> | ||
− | + | On MacOS: | |
<code lang='bash'> | <code lang='bash'> | ||
− | cd / | + | cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ |
− | + | python3 test.py</code> | |
==Using the Lianja Cloud Data Services module in Python Applications== | ==Using the Lianja Cloud Data Services module in Python Applications== | ||
Line 43: | Line 56: | ||
Load the module into your Python application | Load the module into your Python application | ||
− | <code lang=' | + | <code lang='python'>import lianjaclouddataservices as Lianja</code> |
− | Exported functions. All Python methods are | + | Exported functions. All Python methods are synchronous (see example usage below). |
See [[OData_URIs|OData URIs]] for details of OData URIs and [[OData_Operators|OData Operators]] for all the OData operators. | See [[OData_URIs|OData URIs]] for details of OData URIs and [[OData_Operators|OData Operators]] for all the OData operators. | ||
+ | |||
+ | You can use also use the Lianja Key-Value Store (Lianja/KVS) with Python. See [[Key-Value_Store|Lianja/KVS]] for details. | ||
==Module Methods== | ==Module Methods== | ||
Line 94: | Line 109: | ||
|- | |- | ||
|valign="top"|Lianja.OData_UpdateJSON(url, jsontext) | |valign="top"|Lianja.OData_UpdateJSON(url, jsontext) | ||
− | |valign="top"| | + | |valign="top"|See [[ODATA_UPDATE()]] |
|- | |- | ||
|valign="top"|Lianja.OData_Delete(url, data) | |valign="top"|Lianja.OData_Delete(url, data) | ||
Line 104: | Line 119: | ||
<code lang='python'> | <code lang='python'> | ||
+ | # | ||
+ | # Lianja Python module test | ||
+ | # | ||
+ | # On windows: | ||
+ | # | ||
+ | # cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\ | ||
+ | # python test.py | ||
+ | # | ||
+ | # On Linux: | ||
+ | # | ||
+ | # cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ | ||
+ | # python test.py | ||
+ | # | ||
+ | # On MacOS: | ||
+ | # | ||
+ | # cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ | ||
+ | # python test.py | ||
+ | # | ||
+ | |||
import lianjaclouddataservices as Lianja | import lianjaclouddataservices as Lianja | ||
− | + | print("Lianja.login() - login and keep the connection to the Lianja Cloud Server open (keep-alive)"); | |
− | print(" | + | ok = Lianja.login("http://localhost:8001","admin", "admin") |
− | + | print("result=" + ("successful" if ok else "failed")); | |
− | + | ||
− | + | ||
+ | print("Lianja.evaluate() - Evaluate a server side expression which may include remove procedure/function calls"); | ||
result = Lianja.evaluate("etos(date()) + ' ' + time()") | result = Lianja.evaluate("etos(date()) + ' ' + time()") | ||
− | print(" | + | print("result=" + result); |
− | + | print("Lianja.OData_Read() - Read rows and return JSON as a Python 'dict'") | |
− | print(" | + | result = Lianja.OData_Read("/southwind/employees?$top=2") |
− | print( | + | print("#Rows selected="+str(result["d"]["__reccount"])) |
+ | print(result) | ||
− | + | print("Access rows like this (index from 0): result['d']['results'][1]") | |
− | print(" | + | print(result["d"]["results"][1]) |
− | + | ||
+ | print("Access columns in a row like this: result['d']['results'][1]['lastname']") | ||
+ | print("lastname="+result["d"]["results"][1]['lastname']) | ||
+ | |||
+ | print("Lianja.OData_ReadHTML() - Read all text from a varchar column") | ||
+ | result = Lianja.OData_ReadHTML("/southwind/employees?$select=notes&$filter=lastname eq 'Buchanan'") | ||
+ | print(result) | ||
+ | |||
+ | print("Lianja.OData_ReadImage() - Read an image from a blob column and return an html <img> tag embedding the image") | ||
response = Lianja.OData_ReadImage("/southwind/employees?$select=photo&$filter=lastname eq 'Buchanan'") | response = Lianja.OData_ReadImage("/southwind/employees?$select=photo&$filter=lastname eq 'Buchanan'") | ||
− | print(" | + | print("size="+str(len(response))) |
− | print(" | + | |
+ | print("Lianja.logout() - close the connection to the Lianja Cloud Server") | ||
+ | Lianja.logout() | ||
</code> | </code> | ||
Latest revision as of 21:47, 30 May 2024
Python is now the most popular programming language in the world.
Lianja Cloud Server provides a powerful data integration solution with connectors for Python, Node.js and .NET.
Using these connectors you can connect to local and/or remote Lianja Cloud Servers and perform CRUD operations on data.
Contents
Lianja Cloud Data Services Python module
Lianja Cloud Server includes a Python module lianjaclouddataservices enabling Python applications to connect to a local or remote Lianja Cloud Server and perform a variety of operations.
Installing the Lianja Cloud Data Services Python module
On Windows:
cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\python\ pip install -r requirements.txt
On Linux:
cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/ pip install -r requirements.txt
On MacOS:
cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/ python3 pip install -r requirements.txt --user
Testing the installation:
On Windows:
cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\python\lianjaclouddataservices\
python test.py
On Linux:
cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ python test.py
On MacOS:
cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ python3 test.py
Using the Lianja Cloud Data Services module in Python Applications
Load the module into your Python application
import lianjaclouddataservices as Lianja
Exported functions. All Python methods are synchronous (see example usage below).
See OData URIs for details of OData URIs and OData Operators for all the OData operators.
You can use also use the Lianja Key-Value Store (Lianja/KVS) with Python. See Lianja/KVS for details.
Module Methods
Function | Description |
---|---|
Lianja.login(host, user, password) | Login and connect to to a local or remote Cloud Server. To connect locally specify the host as http: //localhost:8001 |
Lianja.logout() | Logout from the local or remote Cloud Server. |
Lianja.evaluate(expr) | Evaluates LianjaScript expression and returns the result asynchronously. |
Lianja.evaluatePython(expr) | Evaluates Python expression and returns the result asynchronously. |
Lianja.evaluateJavaScript(expr) | Evaluates JavaScript expression and returns the result asynchronously. |
Lianja.fetch(url) | Fetches data from the server using an .rsp, .pysp or .jssp server side page. Use fetch() to retrieve custom data from the server. |
Lianja.OData_Create(url, data) | See ODATA_CREATE() |
Lianja.OData_Read(url) | See ODATA_READ() |
Lianja.OData_ReadHTML(url) | See See ODATA_READ() |
Lianja.OData_ReadJSON(url) | See See ODATA_READ() |
Lianja.OData_ReadImage(url) | See See ODATA_READ() |
Lianja.OData_Update(url, data) | See ODATA_UPDATE() |
Lianja.OData_UpdateHTML(url, text) | See ODATA_UPDATE() |
Lianja.OData_UpdateJSON(url, jsontext) | See ODATA_UPDATE() |
Lianja.OData_Delete(url, data) | See ODATA_DELETE() |
Example usage:
# # Lianja Python module test # # On windows: # # cd C:\lianja\cloudserver\tenants\public\wwwroot\library\LianjaWebFramework\LianjaCloudDataServices\node\lianjaclouddataservices\ # python test.py # # On Linux: # # cd /opt/lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ # python test.py # # On MacOS: # # cd /Users/shared/Lianja/cloudserver/tenants/public/wwwroot/library/LianjaWebFramework/LianjaCloudDataServices/python/lianjaclouddataservices/ # python test.py # import lianjaclouddataservices as Lianja print("Lianja.login() - login and keep the connection to the Lianja Cloud Server open (keep-alive)"); ok = Lianja.login("http://localhost:8001","admin", "admin") print("result=" + ("successful" if ok else "failed")); print("Lianja.evaluate() - Evaluate a server side expression which may include remove procedure/function calls"); result = Lianja.evaluate("etos(date()) + ' ' + time()") print("result=" + result); print("Lianja.OData_Read() - Read rows and return JSON as a Python 'dict'") result = Lianja.OData_Read("/southwind/employees?$top=2") print("#Rows selected="+str(result["d"]["__reccount"])) print(result) print("Access rows like this (index from 0): result['d']['results'][1]") print(result["d"]["results"][1]) print("Access columns in a row like this: result['d']['results'][1]['lastname']") print("lastname="+result["d"]["results"][1]['lastname']) print("Lianja.OData_ReadHTML() - Read all text from a varchar column") result = Lianja.OData_ReadHTML("/southwind/employees?$select=notes&$filter=lastname eq 'Buchanan'") print(result) print("Lianja.OData_ReadImage() - Read an image from a blob column and return an html <img> tag embedding the image") response = Lianja.OData_ReadImage("/southwind/employees?$select=photo&$filter=lastname eq 'Buchanan'") print("size="+str(len(response))) print("Lianja.logout() - close the connection to the Lianja Cloud Server") Lianja.logout()