{"id":5630,"library":"google-cloud-audit-log","title":"Google Cloud Audit Log Protobufs","description":"The `google-cloud-audit-log` library provides the generated Python classes for Google Cloud Audit Log protocol buffer definitions. It enables developers to work with AuditLog messages, which describe activities in Google Cloud, allowing for parsing, constructing, and serializing these structured log entries. The current version is 0.4.0, and releases typically occur to update protobuf definitions as Google Cloud services evolve.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/python-audit-log","tags":["google-cloud","audit","protobuf","logging"],"install":[{"cmd":"pip install google-cloud-audit-log","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This library contains generated Python classes for protocol buffer definitions and relies heavily on the `protobuf` library for message serialization and deserialization.","package":"protobuf","optional":false}],"imports":[{"note":"Most protobuf messages, like AuditLog, are imported directly from their respective `_pb2` files within the `google.cloud.audit` namespace.","symbol":"AuditLog","correct":"from google.cloud.audit import audit_log_pb2"},{"note":"Nested message types are attributes of the containing message type, but their definitions are also available from the main `_pb2` file.","symbol":"RequestMetadata","correct":"from google.cloud.audit import audit_log_pb2"}],"quickstart":{"code":"from google.cloud.audit import audit_log_pb2\nfrom google.protobuf.json_format import MessageToJson, Parse\n\n# Example: Construct an AuditLog message programmatically\naudit_log_entry = audit_log_pb2.AuditLog(\n    service_name=\"compute.googleapis.com\",\n    method_name=\"v1.compute.instances.insert\",\n    resource_name=\"projects/my-project/zones/us-central1-a/instances/my-instance\",\n    authentication_info=audit_log_pb2.AuthenticationInfo(\n        principal_email=\"user@example.com\"\n    ),\n    request_metadata=audit_log_pb2.RequestMetadata(\n        caller_ip=\"192.168.1.1\",\n        caller_supplied_user_agent=\"gcloud-sdk\",\n    )\n)\n\nprint(\"Constructed AuditLog (JSON format):\")\nprint(MessageToJson(audit_log_entry))\n\n# Example: Simulate receiving a serialized AuditLog (e.g., from a message queue)\n# In a real scenario, `serialized_data` would be bytes received from a source.\n# For this example, we'll serialize the object we just created.\nserialized_data = audit_log_entry.SerializeToString()\n\n# Parse the received data back into an AuditLog object\nparsed_log_entry = audit_log_pb2.AuditLog()\nparsed_log_entry.ParseFromString(serialized_data)\n\nprint(\"\\nParsed AuditLog (JSON format):\")\nprint(MessageToJson(parsed_log_entry))\n\n# Accessing fields from the parsed log entry\nprint(f\"\\nService Name: {parsed_log_entry.service_name}\")\nprint(f\"Method Name: {parsed_log_entry.method_name}\")\nif parsed_log_entry.authentication_info.principal_email:\n    print(f\"Principal Email: {parsed_log_entry.authentication_info.principal_email}\")\n","lang":"python","description":"This quickstart demonstrates how to programmatically construct an `AuditLog` message and then serialize it to bytes, simulating how it might be stored or transmitted. It then shows how to deserialize those bytes back into an `AuditLog` object and access its fields. This reflects the library's primary use case of defining and manipulating audit log protobuf messages."},"warnings":[{"fix":"Upgrade or downgrade your `protobuf` installation to match the requirements of `google-cloud-audit-log`. For example, `pip install 'protobuf>=3.19.5,<5.0.0'`.","message":"The `protobuf` dependency requirements have changed across minor versions. Ensure your environment uses a compatible `protobuf` version to avoid runtime errors. For version `0.4.0`, `protobuf>=3.19.5, <5.0.0` is generally required.","severity":"breaking","affected_versions":"All versions, specifically v0.2.1, v0.2.4, v0.2.5, v0.3.0, v0.4.0"},{"fix":"To fetch audit logs, use a client library for the relevant Google Cloud service, such as `google-cloud-logging` to read from Cloud Logging.","message":"This library provides only the protobuf definitions for Google Cloud Audit Logs. It does NOT include a client library for fetching audit logs from Google Cloud APIs (e.g., Stackdriver Logging). Users are responsible for obtaining the serialized audit log data from other sources (e.g., Pub/Sub, Cloud Logging API) and then using this library to parse and interpret it.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always import specific protobuf message modules directly, e.g., `from google.cloud.audit import audit_log_pb2` to access `audit_log_pb2.AuditLog`.","message":"The import paths for protobuf messages are direct to the `_pb2` files (e.g., `from google.cloud.audit import audit_log_pb2`). There are no higher-level client objects or `types` modules provided by this library, as its sole purpose is to expose the generated protobuf classes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your development and deployment environments use Python 3.7 or a later version.","message":"This library requires Python 3.7 or newer. Attempting to use it with older Python versions will result in installation failures or runtime errors.","severity":"gotcha","affected_versions":"< 0.2.3 (implicitly), >=0.2.3 (explicitly enforces)"}],"env_vars":null,"last_verified":"2026-03-28T00:00:00.000Z","next_check":"2026-06-26T00:00:00.000Z"}