0

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?

GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71
N91
  • 395
  • 1
  • 3
  • 14

1 Answers1

2

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)
Marius Wirtz
  • 86
  • 1
  • 6
  • Hi Marius, where do you find the localhost and port? – excelguy Jun 15 '20 at 17:52
  • 1
    Hi @excelguy, if python is not running on the same machine you have to pass the address of the server instead of "localhost". For the port argument, you must provide the HTTPPortServer. – Marius Wirtz Aug 31 '20 at 14:07