Content_Cut_Icon Twitter_Brands_Icon

TM1 REST API & Python Automation Guide (TM1py) | Octane

Mode_Comment_Icon_white0
Alarm_Icon_1_white10 min
Book_Open_Solid_Icon
Executive Summary Key Takeaway in 30 Seconds

Quick Summary: Replace fragile Windows batch files and ExecuteCommand scripts with clean Python automation. Connecting TM1py to the official TM1 REST API delivers encrypted HTTPS logins, real-time error logging, and direct in-memory cube queries without intermediate CSV dumps.

If your TM1 environment still relies on Windows batch files and ExecuteCommand scripts to trigger data loads, you are sitting on technical debt that will eventually break. When files lock or network drives disconnect, batch scripts fail silently without returning error details to your finance team.

There is a much cleaner way to automate IBM Planning Analytics. By connecting Python to the official TM1 REST API using the open-source TM1py library, you can build reliable automation that handles logins securely, logs exact error lines, and transfers data without intermediate CSV dumps.

Chapter 1: The Problem with Legacy Batch Scripts

For decades, TM1 developers used ExecuteCommand in TurboIntegrator to run .bat or PowerShell scripts on the host Windows server. While this worked on old local machines, it introduces three major operational headaches:

  • Zero Error Feedback: TurboIntegrator treats ExecuteCommand as an asynchronous fire-and-forget call. If the batch script crashes halfway through, TM1 logs a generic success code simply because the command prompt launched.
  • Security Risks: Storing hardcoded admin passwords in plain text batch files on shared network folders violates basic enterprise IT security and audit standards.
  • Cloud & Container Incompatibility: Modern Planning Analytics Engine 12 runs inside Linux containers where Windows command shells (cmd.exe) and local drive mappings do not exist.

Chapter 2: Why the TM1 REST API Changes Everything

IBM introduced the TM1 REST API to give developers full programmatic control over the TM1 server. Everything you can do inside Architect or Planning Analytics Workspace can now be orchestrated via standard HTTPS requests:

  • Execute TurboIntegrator processes and receive exact return status codes and error logs in real time.
  • Read and write cube cell values directly in memory without exporting temporary flat CSV files.
  • Create, update, and manage dimension hierarchies on the fly.
  • Subscribe to server transaction logs and monitor active user threads programmatically.

Chapter 3: Getting Started with TM1py

Writing raw HTTP requests against OData endpoints can be tedious. That is why the TM1 community created TM1py, a clean Python wrapper maintained by Cubewise that handles authentication, JSON serialization, and connection pooling automatically.

You can install TM1py in your Python environment with a single terminal command:

$ pip install TM1py

Chapter 4: A Production-Grade Automation Script

Here is a complete, production-ready Python script that logs into TM1 securely over HTTPS, executes a TurboIntegrator process with parameters, evaluates the return status, and queries cell data:

tm1_automation.py Python 3
from TM1py.Services import TM1Service
from TM1py.Exceptions import TM1pyException

# Connect securely to TM1 over HTTPS
tm1_config = {
    'address': 'tm1server.company.com',
    'port': 8001,
    'ssl': True,
    'user': 'svc_finance_automation',
    'password': 'SecureVaultPassword123!',
    'namespace': 'LDAP'
}

try:
    with TM1Service(**tm1_config) as tm1:
        print("Connected to TM1 Server version:", tm1.server.get_product_version())
        
        # 1. Execute a TurboIntegrator Process with Parameters
        process_name = "Finance.Actuals.ImportFromERP"
        params = {"pYear": "2026", "pMonth": "09"}
        
        success, status, error_log_file = tm1.processes.execute_with_return(process_name, **params)
        
        if success:
            print(f"Process {process_name} completed successfully!")
        else:
            print(f"Process failed with status: {status}")
            if error_log_file:
                print(f"Error log file generated: {error_log_file}")
                
        # 2. Extract Cube Summary Data in Real Time
        cube_name = "General Ledger"
        value = tm1.cubes.cells.get_value(
            cube_name=cube_name,
            elements="2026,Sep,Actual,Net Profit,Total Company,Local Currency"
        )
        print(f"September 2026 Net Profit: ${value:,.2f}")

except TM1pyException as e:
    print("TM1 Operation Error:", str(e))
except Exception as ex:
    print("Unexpected Connection Error:", str(ex))

Chapter 5: Scheduling and Enterprise Governance

Once your Python script is tested, you can orchestrate it using modern tools rather than brittle local schedulers:

1. Apache Airflow / Prefect (Pipeline Orchestration)

Chain your TM1 data load after your Snowflake or ERP transformation completes, ensuring TM1 never loads partial or unverified datasets.

2. Azure Automation / AWS Lambda (Serverless Compute)

Run your scripts serverless on a recurring schedule without keeping a dedicated Windows virtual machine powered on 24/7.

3. Cloud Secret Managers (Zero Plain-Text Passwords)

Pull API credentials directly from Azure Key Vault or AWS Secrets Manager so zero passwords or service account tokens live on disk.

Chapter 6: The Developer Checklist Before Going Live

Before moving your Python automation into production, review this five-point readiness checklist:

  • Least-Privilege Security: Verify that CAM or LDAP service accounts have least-privilege security assigned in TM1 (read/write only to target cubes).
  • SSL Certificates: Ensure SSL certificates on your TM1 REST API port are trusted and not expired self-signed certificates.
  • Exponential Backoff: Add retry logic with exponential backoff for network timeouts during high-load month-end lockouts.
  • Instant Webhook Alerts: Send failure alerts directly to your team Slack or Microsoft Teams channel via webhooks when a job fails.
  • Decommission Legacy Scripts: Permanently disable legacy Windows batch files and remove outdated Windows Task Scheduler triggers.

Modernise Your TM1 Automation with Octane

Tired of fragile batch scripts, locked network folders, and middle-of-the-night data load failures? The team at Octane Software Solutions helps enterprise finance teams build resilient, automated TM1 architectures.

Talk to Our TM1 Engineers →
Amiel Lebios
Written by

Amiel Lebios

Subject-matter specialist at Octane Solutions, helping Australian enterprise finance teams optimize planning, analytics, and automation.

Leave a comment

Got a question? Shoot!

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Get more articles like this delivered to your inbox