Adding data from a Planning Analytics connection

You need to write your own code if you want to access data from a Planning Analytics connection in a notebook. To do this you can use available open source libraries like for example 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.

NOTE: The information about the third-party open source libraries is provided for your convenience. Although the code has been tested, it is not officially supported by IBM.

The following sample code show you how to read data from a Planning Analytics connection and load the data to dataframes in a notebook using the TM1Py open source library:

To add data from a Planning Analytics connection:

  1. In a notebook code cell, begin by installing the TM1Py library:
    # install TM1Py library 
    !pip install TM1py
    
  2. Click in an empty code cell, click the Find and Add Data icon (Shows the find data icon), and click the Connections tab to see your Planning Analytics connection.
  3. Click Insert to code under the connection name and select to insert the credentials. Use the returned credentials in the TM1Py library functions to connect to the Planning Analytics service.
  4. 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 not only the URL, username and password, but also the 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 ssl parameter to True if the connection to the Planning Analytics service is a secure HTTP connection.

  5. 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()
    
  6. 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>")
    
  7. 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 private parameter to True.
    # 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()
    

Parent topic: Loading and accessing data in a notebook