pythoncognos-tm1

How to pull data from IBM TM1


I have established a connection between Python and IBM TM1 OLAP tool using the TM1py package for Python. Now when I try to fetch data from an MDX view of TM1 in Python, all I get is the column headers. I read the documentation of TM1py and it looks like the get_native_view function are supposed to just return an instance of the view and not the actual data contained in the view.

from TM1py.Services import TM1Service

with TM1Service(address='hostname', port=12523,user='username', password=****, ssl=False) as tm1:

query = tm1.cubes.views.get_native_view('cube_name', 'View_name', private=True)
print(query)

Does anyone know a way to pull the actual data and not just column headers from TM1 in Python?


Solution

  • The get_native_view function returns the defition of a cube view.

    To pull cube data from IBM TM1 into Python with TM1py you can use the get_view_content function (Option 1) or do an MDX Query (Option 2).

    Option 1:

    from TM1py.Services import TM1Service
    
    with TM1Service(address='localhost', port=12354, user='admin', password='apple', ssl=True) as tm1:
        content = tm1.cubes.cells.get_view_content(cube_name='Plan_BudgetPlan', view_name='Default', private=False)
        print(content)
    

    Option 2:

    from TM1py.Services import TM1Service
    
    with TM1Service(address='localhost', port=12354, user='admin', password='apple', ssl=True) as tm1:
        mdx = "SELECT " \
              "NON EMPTY {TM1SUBSETALL( [}Clients] )} on ROWS, " \
              "NON EMPTY {TM1SUBSETALL( [}Groups] )} ON COLUMNS " \
              "FROM [}ClientGroups]"
        content = tm1.cubes.cells.execute_mdx(mdx)
        print(content)