Google Cloud Snapshot Debugger for Python

4.1 · active · verified Mon Apr 13

The Python Cloud Debugger client library (now known as Google Cloud Snapshot Debugger) allows you to inspect the state of a running Python application in Google Cloud without stopping or slowing it down. It works by capturing snapshots of application state. The current version is 4.1, with releases typically aligning with significant feature updates or bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Snapshot Debugger in your Python application. After calling `snapshot_debugger.start()`, your application will connect to the Google Cloud Console, allowing you to set breakpoints and inspect variables without redeploying. Ensure your Google Cloud project is configured for Cloud Debugger and the service account has the necessary permissions (e.g., Cloud Debugger, Firebase Realtime Database Admin).

import snapshot_debugger
import os

# snapshot_debugger.start() attempts to auto-detect project ID and config.
# For local testing, you might need to specify it or set environment variables.
# Example for App Engine, Cloud Functions, GKE etc. it usually works out of the box.
# For manual configuration if needed:
# snapshot_debugger.start(project_id='your-gcp-project-id', module='your-app-name', version='1.0')

# In a typical cloud environment, simply calling start() is sufficient.
# Ensure your service account has 'Cloud Debugger' role.
# For Firebase backend, the service account needs 'Firebase Realtime Database Admin' role.
snapshot_debugger.start()

print('Snapshot Debugger started. You can now set breakpoints in the Google Cloud Console.')

def main():
    x = 10
    y = 20
    z = x + y # Set a breakpoint here in Google Cloud Console
    print(f'Result: {z}')

if __name__ == '__main__':
    main()

view raw JSON →