{"id":9300,"library":"sentry-cli","title":"Sentry CLI","description":"sentry-cli is a powerful command-line utility for interacting with Sentry, enabling tasks like creating releases, uploading source maps, managing projects, and configuring your Sentry instance. The Python package primarily serves as a convenient wrapper to install and execute the Rust-based binary. It is actively maintained with frequent snapshot builds and regular stable releases.","status":"active","version":"3.3.5","language":"en","source_language":"en","source_url":"https://github.com/getsentry/sentry-cli","tags":["sentry","cli","error monitoring","devops","release management","sourcemaps"],"install":[{"cmd":"pip install sentry-cli","lang":"bash","label":"Install via pip (installs binary)"},{"cmd":"curl -sL https://sentry.io/get-cli/ | bash","lang":"bash","label":"Install standalone binary (recommended)"}],"dependencies":[],"imports":[{"note":"sentry-cli is a command-line tool (a binary), not a Python library with an importable API. Its Python package primarily manages the binary installation. For Python application error reporting, use the `sentry-sdk` library. To run `sentry-cli` from Python, use `subprocess`.","wrong":"import sentry_cli","symbol":"sentry_cli","correct":"This package is not intended for direct Python import as a library with an API."}],"quickstart":{"code":"import os\nimport subprocess\n\n# Ensure SENTRY_AUTH_TOKEN is set for non-interactive use (e.g., CI/CD)\n# It can be obtained from your Sentry 'API Keys' settings.\n# For interactive use, run 'sentry-cli login' once in your terminal.\nos.environ['SENTRY_AUTH_TOKEN'] = os.environ.get('SENTRY_AUTH_TOKEN', '')\nos.environ['SENTRY_ORG'] = os.environ.get('SENTRY_ORG', 'your-org-slug') # Replace with your Sentry organization slug\nos.environ['SENTRY_PROJECT'] = os.environ.get('SENTRY_PROJECT', 'your-project-slug') # Replace with your Sentry project slug\n\ndef run_sentry_cli_command(command_args):\n    full_command = ['sentry-cli'] + command_args\n    print(f\"\\nRunning: {' '.join(full_command)}\")\n    try:\n        result = subprocess.run(\n            full_command,\n            capture_output=True,\n            text=True,\n            check=True, # Raises CalledProcessError for non-zero exit codes\n            env=os.environ # Pass current environment including SENTRY_AUTH_TOKEN\n        )\n        print(\"STDOUT:\\n\" + result.stdout)\n        if result.stderr:\n            print(\"STDERR:\\n\" + result.stderr)\n        return result.stdout\n    except subprocess.CalledProcessError as e:\n        print(f\"Error executing command: {e.cmd}\")\n        print(f\"Return Code: {e.returncode}\")\n        print(f\"STDOUT:\\n{e.stdout}\")\n        print(f\"STDERR:\\n{e.stderr}\")\n        raise # Re-raise the error to stop execution\n    except FileNotFoundError:\n        print(\"Error: 'sentry-cli' command not found. Please ensure it's installed and in your system PATH.\")\n        print(\"You can install it via 'pip install sentry-cli' or by following instructions at https://docs.sentry.io/product/cli/installation/\")\n        raise\n\nif __name__ == \"__main__\":\n    try:\n        # 1. Check the Sentry CLI version\n        run_sentry_cli_command(['--version'])\n\n        # 2. Get the current organization's status\n        run_sentry_cli_command(['info'])\n\n        # 3. Create a Sentry release (replace with your actual release name)\n        release_name = f\"my-app@{os.getenv('BUILD_VERSION', '1.0.0-test')}\"\n        run_sentry_cli_command(['releases', 'new', release_name])\n\n        # 4. Set the release to committed (optional, for connecting to SCM)\n        # run_sentry_cli_command(['releases', 'set-commits', release_name, '--auto'])\n\n        # 5. Finalize the release\n        run_sentry_cli_command(['releases', 'finalize', release_name])\n\n        print(\"\\nSentry CLI commands executed successfully!\")\n\n    except Exception as e:\n        print(f\"\\nAn error occurred during quickstart execution: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to programmatically interact with `sentry-cli` from Python using the `subprocess` module. It includes examples for checking the version, creating, and finalizing a Sentry release. Ensure you have `SENTRY_AUTH_TOKEN`, `SENTRY_ORG`, and `SENTRY_PROJECT` environment variables configured or set `sentry-cli login` interactively. Replace placeholder slugs with your actual Sentry organization and project details."},"warnings":[{"fix":"Use `sentry-cli` directly from your shell or invoke it via Python's `subprocess` module for programmatic control. For Python application integration, use `sentry-sdk`.","message":"sentry-cli is not a Python library meant for direct `import` statements. The Python `sentry-cli` package is a wrapper to install the `sentry-cli` binary. Attempting to `import sentry_cli` will likely fail or lead to confusion.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `sentry-cli` version 3.x and ensure you are using a Sentry Auth Token. Set it as `SENTRY_AUTH_TOKEN` environment variable or use `sentry-cli login`.","message":"Sentry CLI versions 2.x and earlier relied on an older authentication method (API keys). Versions 3.x strongly recommend using Auth Tokens for better security and granular permissions.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Ensure `sentry-cli upload-sourcemaps` commands correctly specify the `--url-prefix` to match how your assets are served, and that the `--release` parameter matches the release ID associated with your reported events. Validate sourcemaps in Sentry's developer tools after uploading.","message":"Sourcemap uploading can be tricky if paths or release names don't match exactly between your build process and Sentry. Incorrect configurations lead to un-minified stack traces.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always include `--org <ORG_SLUG>` and `--project <PROJECT_SLUG>` arguments, or configure them globally via environment variables (`SENTRY_ORG`, `SENTRY_PROJECT`) or a `.sentryclirc` file.","message":"Many `sentry-cli` commands require specifying the Sentry organization and project. Forgetting these, or providing incorrect values, often leads to authentication or permissions errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `sentry-cli` is installed (`pip install sentry-cli` or `curl -sL https://sentry.io/get-cli/ | bash`) and that your shell's PATH includes the directory where the executable resides (e.g., `~/.local/bin` for pip installs).","cause":"The `sentry-cli` executable is not in your system's PATH, or the installation failed.","error":"sentry-cli: command not found"},{"fix":"Run `sentry-cli login` interactively and follow the prompts, or set a valid Sentry Auth Token in the `SENTRY_AUTH_TOKEN` environment variable for non-interactive environments (e.g., CI/CD).","cause":"sentry-cli cannot authenticate with Sentry. This usually means no Auth Token is set, or it's invalid/expired.","error":"error: You need to login first. (sentry-cli.login.not-logged-in)"},{"fix":"Add `--org <YOUR_ORG_SLUG>` to your command, or set the `SENTRY_ORG` environment variable, or configure it in a `.sentryclirc` file in your project or home directory.","cause":"The command requires a Sentry organization slug, but it was not provided.","error":"error: Missing required argument `--org`"},{"fix":"Add `--project <YOUR_PROJECT_SLUG>` to your command, or set the `SENTRY_PROJECT` environment variable, or configure it in a `.sentryclirc` file in your project or home directory.","cause":"The command requires a Sentry project slug, but it was not provided.","error":"error: Missing required argument `--project`"}]}