{"id":6924,"library":"trcli","title":"ThoughtSpot Python CLI (trcli)","description":"The ThoughtSpot Python CLI (trcli) is a utility that enables users to perform administrative tasks, such as managing users, groups, objects, and configurations, on a ThoughtSpot cluster programmatically. It is actively developed by ThoughtSpot, with version 1.14.0 being the latest stable release. Releases typically align with ThoughtSpot platform updates or are issued as needed for bug fixes and new features.","status":"active","version":"1.14.0","language":"en","source_language":"en","source_url":"https://github.com/thoughtspot/trcli","tags":["cli","thoughtspot","admin","automation"],"install":[{"cmd":"pip install trcli","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"HTTP client for API interaction","package":"requests"},{"reason":"YAML parsing for configuration","package":"PyYAML"},{"reason":"Framework for building command-line interfaces","package":"click"},{"reason":"Interactive command-line applications","package":"prompt_toolkit"},{"reason":"Pretty-printing tabular data","package":"tabulate"},{"reason":"Cross-platform colored terminal text","package":"colorama"},{"reason":"JSONPath expressions","package":"jsonpath-ng"},{"reason":"Retrying mechanism for failed operations","package":"tenacity"},{"reason":"Backport for 'importlib.resources' (for Python < 3.9)","package":"importlib_resources","optional":true}],"imports":[{"note":"trcli is primarily a command-line interface. Its core functionality is exposed via the 'trcli' executable, not directly via Python library imports for general programmatic use. The recommended and safest way to interact with trcli from Python is by invoking it as a subprocess using `subprocess.run`.","wrong":"from trcli.cli import main # Not a public API for general use","symbol":"trcli CLI functionality","correct":"import subprocess\nimport os\n\nts_url = os.environ.get('TS_URL', 'https://your_thoughtspot_instance.com')\nts_username = os.environ.get('TS_USERNAME', 'admin')\nts_password = os.environ.get('TS_PASSWORD', 'password')\n\n# Example: Get trcli version\ntry:\n    result = subprocess.run(\n        ['trcli', 'version'],\n        capture_output=True, text=True, check=True\n    )\n    print(result.stdout)\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error running trcli: {e.stderr}\")\n\n# Example: Login (requires environment variables or --url/--username/--password)\ntry:\n    # Using environment variables is common, ensure they are set\n    # os.environ['TS_URL'] = ts_url\n    # os.environ['TS_USERNAME'] = ts_username\n    # os.environ['TS_PASSWORD'] = ts_password\n    # Note: For security, avoid hardcoding credentials. Use env vars or config.\n    \n    result = subprocess.run(\n        ['trcli', 'login', '--url', ts_url, '--username', ts_username, '--password', ts_password],\n        capture_output=True, text=True, check=True\n    )\n    print(\"Login successful:\", result.stdout)\nexcept subprocess.CalledProcessError as e:\n    print(f\"Login failed: {e.stderr}\")"}],"quickstart":{"code":"import subprocess\nimport os\n\n# Set ThoughtSpot URL and credentials using environment variables for security\n# Or pass them directly as arguments (less secure for passwords)\n# Example environment variables (replace with your actual values):\n# export TS_URL='https://your-thoughtspot-instance.com'\n# export TS_USERNAME='your_username'\n# export TS_PASSWORD='your_password'\n\n# You can use os.environ.get for testing or local setup\nts_url = os.environ.get('TS_URL', 'https://localhost') # Use a placeholder or actual URL\nts_username = os.environ.get('TS_USERNAME', 'user') # Use a placeholder or actual username\nts_password = os.environ.get('TS_PASSWORD', 'pass') # Use a placeholder or actual password\n\nprint(f\"Attempting to use trcli with URL: {ts_url}\")\n\ntry:\n    # First, try to login to obtain a session token\n    # For programmatic use, consider using a service principal or persistent token\n    login_cmd = [\n        'trcli', 'login',\n        '--url', ts_url,\n        '--username', ts_username,\n        '--password', ts_password\n    ]\n    print(f\"Running login command: {' '.join(login_cmd[:4])} ...\") # Censor password\n    login_result = subprocess.run(login_cmd, capture_output=True, text=True, check=True)\n    print(\"Login successful:\")\n    print(login_result.stdout)\n\n    # Now, run a command, e.g., list users, outputting as JSON\n    list_users_cmd = ['trcli', 'user', 'list', '-o', 'json']\n    print(f\"Running command: {' '.join(list_users_cmd)}\")\n    users_result = subprocess.run(list_users_cmd, capture_output=True, text=True, check=True)\n    print(\"Users list (JSON):\")\n    print(users_result.stdout)\n\nexcept FileNotFoundError:\n    print(\"Error: 'trcli' command not found. Ensure trcli is installed and in your PATH.\")\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error executing trcli command:\\nSTDOUT: {e.stdout}\\nSTDERR: {e.stderr}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to interact with the `trcli` command-line tool from a Python script using the `subprocess` module. It includes a login attempt and a sample command to list users, highlighting the importance of handling credentials securely (e.g., via environment variables) and capturing output."},"warnings":[{"fix":"Ensure your Python environment is running Python 3.9 or newer before installing or upgrading `trcli`. Previous versions of `trcli` (e.g., < 1.13.0) supported older Python versions.","message":"Minimum Python version requirement increased to 3.9.","severity":"breaking","affected_versions":"< 1.13.0"},{"fix":"Users migrating from older versions (pre-1.10.0) may need to re-authenticate or update their stored authentication tokens/methods. Consult `trcli login --help` or the official documentation for the latest authentication mechanisms.","message":"Authentication logic updated, potentially requiring re-login or new token generation.","severity":"breaking","affected_versions":"Introduced in 1.10.0 and subsequent updates"},{"fix":"For secure and consistent automation, it is recommended to set `TS_URL`, `TS_USERNAME`, `TS_PASSWORD`, or `TS_TOKEN` as environment variables. Alternatively, use CLI arguments (`--url`, `--username`, `--password`) or a `trcli_config.yaml` file (e.g., in `~/.thoughtspot/` or `.` directory). Ensure proper security practices for managing credentials.","message":"Credentials and ThoughtSpot URL are often required and can be passed via environment variables, CLI arguments, or configuration files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use the `-o json` or `--output json` flag when you need structured output that can be easily parsed by Python scripts. For example: `trcli user list -o json`.","message":"Default output format is human-readable, but programmatic interaction often requires JSON output.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}