TM1py is the python package for IBM Planning Analytics (TM1).
with TM1Service(address='localhost', port=8001, user='admin', password='apple', ssl=True) as tm1:
subset = Subset(dimension_name='Month', subset_name='Q1', elements=['Jan', 'Feb', 'Mar'])
tm1.subsets.create(subset, private=True)
Features
TM1py offers handy features to interact with TM1 from Python, such as
- Functions to read data from cubes through cube views or MDX queries (e.g.
tm1.cells.execute_mdx) - Functions to write data to cubes (e.g.
tm1.cells.write) - Functions to update dimensions and hierarchies (e.g.
tm1.hierarchies.get) - Functions to update metadata, clear or write to cubes directly from pandas dataframes (e.g.
tm1.elements.get_elements_dataframe) - Async functions to easily parallelize your read or write operations (e.g.
tm1.cells.write_async) - Functions to execute TI process or loose statements of TI (e.g.
tm1.processes.execute_with_return) - CRUD features for all TM1 objects (cubes, dimensions, subsets, etc.)
Requirements
- Python (3.7 or higher)
- TM1/Planning Analytics (v11 or higher)
Optional Python Packages
- pandas
- networkx
Install
without pandas
pip install tm1py
with pandas
pip install "tm1py[pandas]"
Usage
TM1 11 on-premise
from TM1py.Services import TM1Service
with TM1Service(address='localhost', port=8001, user='admin', password='apple', ssl=True) as tm1:
print(tm1.server.get_product_version())
TM1 11 on IBM cloud
with TM1Service(
base_url='https://mycompany.planning-analytics.ibmcloud.com/tm1/api/tm1/',
user="non_interactive_user",
namespace="LDAP",
password="U3lSn5QLwoQZY2",
ssl=True,
verify=True,
async_requests_mode=True) as tm1:
print(tm1.server.get_product_version())
TM1 12 PAaaS
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())
TM1 12 on-premise & Cloud Pak For Data
with TM1Service(
address="tm1-ibm-operands-services.apps.cluster.your-cluster.company.com",
instance="your instance name",
database="your database name",
application_client_id="client id",
application_client_secret="client secret",
user="admin",
ssl=True) as tm1:
print(tm1.server.get_product_version())
TM1 12 on-premise with access token
params = {
"base_url": "https://pa12.dev.net/api/<InstanceId>/v0/tm1/<DatabaseName>",
"user": "8643fd6....8a6b",
"access_token":"<TheActualAccessToken>",
"async_requests_mode": True,
"ssl": True,
"verify": True
}
with TM1Service(**params) as tm1:
print(tm1.server.get_product_version())
Accessing TM1 REST APIs through Planning Analytics Workspace
PAW serves the TM1 REST API at https://<PawHost>/api/v1/tm1/<DatabaseName> and authenticates every request with an
OAuth access token. access_token also accepts a function that returns the token. TM1py calls it before every request, so your code can
refresh the token (e.g. a PAW OAuth access token) mid-session, without a failed request or a new TM1 session.
Obtaining, refreshing and storing the token stay in your code; TM1py never opens a browser or stores tokens.
from TM1py import TM1Service
def get_token() -> str:
# return a valid access token: a cached one while it is valid, a refreshed one when it is about to expire
return my_oauth_client.get_access_token()
with TM1Service(
base_url="https://<PawHost>/api/v1/tm1/<DatabaseName>",
access_token=get_token) as tm1: # the function itself, not get_token()
print(tm1.server.get_product_version())
A string token also works: when the server returns no session cookie, TM1py keeps sending it with every request. A string cannot be refreshed, though, so requests fail once the token expires. Pass a function for anything that runs longer than the token is valid.
The function is called on every request, possibly from several threads, so it should return a cached token quickly and be thread-safe.
TM1Service.save_to_file pickles the service. It fails if the function cannot be pickled, e.g. a lambda, a nested
function or an object that holds a threading.Lock.
Documentation
Issues
If you find issues, sign up in GitHub and open an Issue in this repository
Contribution
TM1py is an open source project. It thrives on contribution from the TM1 community. If you find a bug or feel like you can contribute please fork the repository, update the code and then create a pull request so we can merge in the changes.
Metadata
Release files for TM1py 2.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tm1py-2.5.0.tar.gz | 183.6 kB | Without provenance | Details for tm1py-2.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tm1py-2.5.0-py3-none-any.whl | Python 3 | none | any | Details for tm1py-2.5.0-py3-none-any.whl |
Total release size: 394.7 kB
Release files / tm1py-2.5.0.tar.gz
| Download URL | tm1py-2.5.0.tar.gz |
|---|---|
| Size | 183.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4b35080f059f073c3efdb0ccec40bc63cbb0467f0bb850c6a84664b7d258d425
|
|
BLAKE2b-256 checksum How to use checksums |
4860aacba63b4acedd52132fa96f4aee4d3054212992ba24fa6259ba81b11a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Release files / tm1py-2.5.0-py3-none-any.whl
| Download URL | tm1py-2.5.0-py3-none-any.whl |
|---|---|
| Size | 211.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1a8e7fa65728e8d94e051c909f540026902731f90666ff5cce2d0b2a121751f
|
|
BLAKE2b-256 checksum How to use checksums |
ef6eb179a9a5dbc5321718772e87a60847b379e82df33bee19c5eecbfa87524e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Security for TM1py 2.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.