{"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install sentry-cli"],"cli":{"name":"sentry-cli","version":"sentry-cli 3.4.2"}},"imports":["This package is not intended for direct Python import as a library with an API."],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}