Use TM1py with PAaaS instance

Post Reply
markhackett
Posts: 3
Joined: Mon Aug 12, 2013 2:00 pm
OLAP Product: IBM Planning Analytics Express
Version: PA 2.0.9.19 and PAW 2.0.91
Excel Version: 2010

Use TM1py with PAaaS instance

Post by markhackett »

Hi - I have been a TM1 / PA developer for a number of years. However, only in the last few months have I started working with a PAaaS cloud instance. I was keen to try out TM1py, so this week I have started learning some python basics. Apologies if this issue has been dealt with elsewhere, but I have searched for an answer without finding what I am looking for. And apologies for the python code - like I say, I'm new to that game, so I am probably breaking all the rules.

The cloud instance is accessed using this URL format: My first test was to see if I could connect to the server - I used the code below to firstly get an access token from the iam.cloud.ibm.com site by using the API key that I had previously generated, and then using the access token to connect to the cloud server. This seemed to be successful because I was able to display a list of the cubes in the SData model. Here is a screenshot of the code:
Code 1.png
Code 1.png (114.88 KiB) Viewed 1439 times
... and here is the output:
Output 1.png
Output 1.png (91.37 KiB) Viewed 1439 times
Given that I was able to connect as above, and use the TM1 REST API to return data, I thought that I would be able to connect using TM1py. However, so far I have been unable to achieve this.

I tried tried the code below which passes in the session_id parameter:
Code 2.png
Code 2.png (113.84 KiB) Viewed 1439 times
However, I got a 401 error in my output (sorry no more screenshots - I've reached my limit of 3!).

I also tried using an access token in the url in case this might get around it, but this gave a 401 error as well.

Just wondering if anyone else has hit this problem, or if anyone can spot that I am missing something obvious?

Thanks and Regards,

Mark
MariusWirtz
Posts: 31
Joined: Sat Apr 08, 2017 8:40 pm
OLAP Product: TM1
Version: 10.2.2.6
Excel Version: 2016

Re: Use TM1py with PAaaS instance

Post by MariusWirtz »

Hi Mark

we just completed the work for TM1 v12 (PAaaS) the other week, with special thanks to Ryan, the main developer behind this feature.
https://github.com/cubewise-code/tm1py/pull/1000

We plan to draft a release in a week or two. To get the functionality now, you can already upgrade to the current master branch on GitHub like this:

Code: Select all

pip uninstall tm1py
pip install https://github.com/cubewise-code/tm1py/archive/refs/heads/master.zip
Here is an example of how to connect with PAaaS from TM1py.

Code: Select all

from TM1py import TM1Service

with TM1Service(
        address="us-east-2.aws.planninganalytics.ibm.com",
        api_key="AB4VfG7T8wPM-912uFKeYG5PGh0XbS80MVBAt7SEG6xn",
        iam_url="https://iam.cloud.ibm.com/identity/token",
        tenant="YA9A2T8BS2ZU",
        database="CWRecordsMDX") as tm1:

    print(tm1.dimensions.get_all_names())
Please let us know if it works, and if you find issues or have ideas for improvements re v12, please raise it directly in GitHub:
https://github.com/cubewise-code/tm1py/issues
markhackett
Posts: 3
Joined: Mon Aug 12, 2013 2:00 pm
OLAP Product: IBM Planning Analytics Express
Version: PA 2.0.9.19 and PAW 2.0.91
Excel Version: 2010

Re: Use TM1py with PAaaS instance

Post by markhackett »

Hi Marius,

Thanks for getting back so promptly - apologies, I was caught up in trying to fix something for a customer yesterday and didn't spot your reply until this morning. Anyway, I followed your instructions and that worked perfectly, so thanks very much for that. And thanks very much to Ryan of course.

I look forward to doing some testing with TM1py on PAaaS now.

Best Regards,

Mark
MariusWirtz
Posts: 31
Joined: Sat Apr 08, 2017 8:40 pm
OLAP Product: TM1
Version: 10.2.2.6
Excel Version: 2016

Re: Use TM1py with PAaaS instance

Post by MariusWirtz »

Now that IBM is moving v12 instances to MCSP, the TM1py authentication looks slightly different.

Here is an example of how to connect to TM1 v12 on MCSP.
If you substitute the 3 placeholders <TenantId>, <DatabaseName>, <TheActualApiKey>, it should just work.

Code: Select all

from TM1py import TM1Service

params = {
    "base_url": "https://us-east-1.planninganalytics.saas.ibm.com/api/<TenantId>/v0/tm1/<DatabaseName>/",
    "user": "apikey",
    "password": "<TheActualApiKey>",
    "async_requests_mode": True,
    "ssl": True,
    "verify": True
}

with TM1Service(**params) as tm1:
    print(tm1.server.get_product_version())
Post Reply