Document toolboxDocument toolbox

Connecting Kyvos semantic model to Python using MDX connection

Applies to: Kyvos Enterprise  Kyvos Cloud (SaaS on AWS) Kyvos AWS Marketplace

Kyvos Azure Marketplace   Kyvos GCP Marketplace Kyvos Single Node Installation (Kyvos SNI)


This section explains how you can connect Python to Kyvos semantic models using the MDX connection.

Prerequisites

To connect Kyvos using Python, you must have the following.

  1. Python (3 and above) must be hosted either on an analyst’s machine or on Hadoop Cluster (Cloud/On-Premises).

Steps to connect

  1. Open the Command prompt (CMD).

  2. Run the following command to create a test environment.
    python3 -m venv python_testenv

  3. Run the following command to enter the test environment.

    cd python_testenv

  4. On Windows/Mac computer, run the following command to activate the test environment.

    Scripts\activate.bat

  5. On Linux, run the following command to activate the test environment.

    source bin/activate

  6. Go to URL: https://github.com/may-day/olap

  7. Download the olap-master.zip folder as shown in the following figure.

  8. Extract files from the downloaded zip folder, copy the unzipped folder (named – olap-master), and paste it in the test environment folder location (created as mentioned in Step 4)

  9. Switch to CMD and run the following commands:

    cd olap-master cd olap-master cd xmla
  10. Install the following libraries:

    pip install zope pip install olap pip install xmla pip install lxml pip install zeep==3.4.0
  11. Copy the Python Code, paste it on the notepad file, edit the code by providing your Kyvos server URL in Kyvos Server IP, Kyvos User ID, and Password (within the double quotes) on Line#3 and #4 and save the notepad file with extension .py in the C:\Users\python_testenv\olap-master\olap-master\xmla folder.

    import olap.xmla.xmla as xmla p = xmla.XMLAProvider() c = p.connect(location="http://<Kyvos Server IP>:8081/kyvos/xmlaKyvos", auth=("<Enter Kyvos User Name>", "<Enter Kyvos Password>")) sba = """ SELECT NON EMPTY Hierarchize(AddCalculatedMembers({DrilldownLevel({[Vendor].[H_Vendor].[Hierarchy.ALL].[0]})})) DIMENSION PROPERTIES PARENT_UNIQUE_NAME,HIERARCHY_UNIQUE_NAME ON COLUMNS  FROM [NYC] WHERE ([Measures].[fare_amount]) CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS """ tweetRes = c.Execute(sba, Catalog="NYC") i= tweetRes.getSlice() l= tweetRes.getSlice(Axis0=0) m= tweetRes.getSlice(Axis0=0,SlicerAxis=0) print(m)
  12. Switch to CMD and execute the script by running the following command.

  13. After the script runs, it gives an output of the MDX as shown in the following figure.


Read more


Copyright Kyvos, Inc. All rights reserved.