Adding data from a Planning Analytics connection
To access data from a Planning Analytics connection, you need to write your own code. You can use available open source libraries like TM1Py, a Python package that wraps the Planning Analytics REST API in a library. After you install the open source library, you can use the library functions to connect to the Planning Analytics service, and to access the data.
The following sample code shows you how to read data from a Planning Analytics connection and load the data to dataframes in a notebook by using the TM1Py open source library:
- See TM1Py for details on the available functions.
- See TM1Py - Help for getting started with the library.
To add data from a Planning Analytics connection:
-
In a notebook code cell, begin by installing the TM1Py library:
# install TM1Py library !pip install TM1py -
Click the Code snippets icon (
), click Read data and then select the connection from the
project. -
Click in an empty code cell in your notebook, select the load option Credentials and then load the credentials to the cell. Use the returned credentials in the TM1Py library functions to connect to the Planning Analytics service.
-
Then, use TM1Py library functions to connect to the Planning Analytics service.
-
If the Planning Analytics service uses basic authentication, you need to specify the URL, username, and password:
# Connect to your Planning Analytics service # The base URL is the TM1 API endpoint excluding the /api/v1 suffix from TM1py.Services import TM1Service tm1 = TM1Service(base_url='http://<server.company.com:port>', user='<username>', password='<password>', ssl=False) -
If the Planning Analytics uses CAM authentication, you need to specify the URL, username, password, and namespace:
# Connect to your Planning Analytics service # The base URL is the TM1 API endpoint excluding the /api/v1 suffix from TM1py.Services import TM1Service tm1 = TM1Service(base_url='http://<server.company.com:port>', user='<username>', password='<password>', namespace='<namespace>', ssl=False)
Hint: Set the
sslparameter to True if the connection to the Planning Analytics service is a secure HTTP connection. -
-
There are different ways to use the TM1Py library with your Planning Analytics data. The following sample code shows you how to read all the cubes to retrieve the name of the cube with the data you want to analyze, and to use the views of the retrieved cube to browse and modify the data.
# Read all cubes and print cube names tm1.cubes.get_all_names() -
Read the views of a specific cube and print the view names:
# Read all views for one cube and print the view names tm1.cubes.views.get_all_names(cube_name="<cube-name>") -
Load the data from a public view to a pandas DataFrame and print the first entries. If you want to load data from a private view, you need to set the
privateparameter toTrue.# Read a dataframe from a public view and print the entries: df_1 = tm1.cubes.cells.execute_view_dataframe(cube_name="<cube-name>", view_name="<view-name>", private=False) df_1.head()