Skip to main content

Audit Logging

The Audit Logging module provides a unified API for logging audit events that comply with the SAP Audit Log Service OpenAPI specification. It uses Python dataclasses for type-safe event construction and supports six event types: Security, Data Access, Data Modification, Data Deletion, Configuration Change, and Configuration Deletion.

Basic Setup

Use create_client(tenant="my-tenant-subdomain") to get a client with automatic environment detection:

from sap_cloud_sdk.core.auditlog import create_client, SecurityEvent

client = create_client(tenant="my-tenant-subdomain")

# Create and log a security event
security_event = SecurityEvent(
data="User login attempt", success=True, user="john.doe", tenant=Tenant.PROVIDER
)

client.log(security_event)

Custom Configuration

from sap_cloud_sdk.core.auditlog import create_client, AuditLogConfig

config = AuditLogConfig(
service_url="https://api.auditlog.cf.example.com/audit-log/oauth2/v2",
oauth_url="https://example.authentication.com/oauth/token",
client_id="your-client-id",
client_secret="your-client-secret",
)

client = create_client(config=config)

For all event types, batch logging, and configuration details, see the Audit Logging user guide in the cloud-sdk-python repository.