PyCADF Library

4.0.1 · active · verified Thu Apr 16

The pycadf library provides an auditing data model based on the Cloud Auditing Data Federation (CADF) specification. It is primarily used within the OpenStack ecosystem to establish strict expectations for auditors regarding audit notifications and event structures. The library is actively maintained by the OpenStack project and is currently at version 4.0.1.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic CADF audit event by defining an initiator (user), a target (VM instance), and then constructing an Event object. The event is then serialized to a JSON string for auditing purposes.

import json
from pycadf.events import Event
from pycadf.resource import Resource
from pycadf.cadftype import CADF_VERSION_1_0_0

# Define initiator resource
initiator = Resource(
    typeURI=CADF_VERSION_1_0_0 + 'security/account/user',
    id='example-user-id',
    name='example_auditor',
    domainId='example-domain'
)

# Define target resource
target = Resource(
    typeURI=CADF_VERSION_1_0_0 + 'compute/instance',
    id='example-instance-id',
    name='my_vm',
    host=Resource(
        typeURI=CADF_VERSION_1_0_0 + 'compute/host',
        id='example-host-id',
        name='compute-host-1'
    )
)

# Create a CADF event
event = Event(
    eventType='activity',
    outcome='success',
    action='create',
    initiator=initiator,
    target=target,
    eventTime='2026-04-16T15:00:00.000Z', # ISO 8601 format
    id='example-event-id'
)

# Serialize the event to a dictionary and print as JSON
print(json.dumps(event.as_dict(), indent=2))

view raw JSON →