Install & Compatibility
Where this runs
tested against v0.6.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.348s · 21.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.0s · import 0.066s · 22MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AuditLog
✓ from google.cloud.audit import audit_log_pb2
Most protobuf messages, like AuditLog, are imported directly from their respective `_pb2` files within the `google.cloud.audit` namespace.
RequestMetadata
✓ from google.cloud.audit import audit_log_pb2
Nested message types are attributes of the containing message type, but their definitions are also available from the main `_pb2` file.
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.
from google.cloud.audit import audit_log_pb2
from google.protobuf.json_format import MessageToJson, Parse
# Example: Construct an AuditLog message programmatically
audit_log_entry = audit_log_pb2.AuditLog(
service_name="compute.googleapis.com",
method_name="v1.compute.instances.insert",
resource_name="projects/my-project/zones/us-central1-a/instances/my-instance",
authentication_info=audit_log_pb2.AuthenticationInfo(
principal_email="user@example.com"
),
request_metadata=audit_log_pb2.RequestMetadata(
caller_ip="192.168.1.1",
caller_supplied_user_agent="gcloud-sdk",
)
)
print("Constructed AuditLog (JSON format):")
print(MessageToJson(audit_log_entry))
# Example: Simulate receiving a serialized AuditLog (e.g., from a message queue)
# In a real scenario, `serialized_data` would be bytes received from a source.
# For this example, we'll serialize the object we just created.
serialized_data = audit_log_entry.SerializeToString()
# Parse the received data back into an AuditLog object
parsed_log_entry = audit_log_pb2.AuditLog()
parsed_log_entry.ParseFromString(serialized_data)
print("\nParsed AuditLog (JSON format):")
print(MessageToJson(parsed_log_entry))
# Accessing fields from the parsed log entry
print(f"\nService Name: {parsed_log_entry.service_name}")
print(f"Method Name: {parsed_log_entry.method_name}")
if parsed_log_entry.authentication_info.principal_email:
print(f"Principal Email: {parsed_log_entry.authentication_info.principal_email}")
Debug
Known issues
breakingThe `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.fixUpgrade 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'`.
affects: All versions, specifically v0.2.1, v0.2.4, v0.2.5, v0.3.0, v0.4.0
gotchaThis 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.fixTo fetch audit logs, use a client library for the relevant Google Cloud service, such as `google-cloud-logging` to read from Cloud Logging.
affects: All versions
gotchaThe 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.fixAlways import specific protobuf message modules directly, e.g., `from google.cloud.audit import audit_log_pb2` to access `audit_log_pb2.AuditLog`.
affects: All versions
gotchaThis library requires Python 3.7 or newer. Attempting to use it with older Python versions will result in installation failures or runtime errors.fixEnsure your development and deployment environments use Python 3.7 or a later version.
affects: < 0.2.3 (implicitly), >=0.2.3 (explicitly enforces)
Errors
Common errors & fixes
TypeError: Can not find message descriptor by type_url: type.googleapis.com/google.cloud.audit.AuditLog.
This error typically occurs when the protobuf library (often `protobuf` or `google-cloud-core`) cannot find the definition for the `AuditLog` message when attempting to deserialize a log entry, usually due to a version mismatch or an environment where the generated protobuf definitions are not correctly registered or accessible.
fixEnsure that `google-cloud-audit-log` and other related Google Cloud client libraries (like `google-cloud-logging`) are up-to-date and compatible. Sometimes, recreating the Python environment or explicitly registering the protobuf descriptor can resolve this. For Google Cloud Logging, this error was historically a backend misconfiguration issue, but for local usage, it points to a protobuf setup problem.
ModuleNotFoundError: No module named 'google.cloud.audit'
This error indicates that the `google-cloud-audit-log` library or its top-level `google.cloud.audit` module is not installed in the current Python environment or is not accessible via the Python path.
fixInstall the library using pip: `pip install google-cloud-audit-log` or ensure your environment's Python path includes the location where the package is installed.
ImportError: cannot import name 'AuditLog' from 'google.cloud.audit'
This happens when attempting to import the `AuditLog` class directly from the `google.cloud.audit` package, but the actual protobuf-generated class resides in a nested module, typically `audit_log_pb2`.
fixImport the `AuditLog` class from its specific protobuf-generated module: `from google.cloud.audit.audit_log_pb2 import AuditLog`.
Upgrade
Version history
0.6.2latest on PyPI · released Aug 24, 2026
Audit
Dependencies
protobufrequiredThis library contains generated Python classes for protocol buffer definitions and relies heavily on the `protobuf` library for message serialization and deserialization.