sysaudit

Documentation Status Build status

Backport module of sys.audit and sys.addaudithook from Python 3.8.

Note: This module does not backport any of the built-in audit events.

Installation

pip install sysaudit

Quick Usage

sysaudit can be used as a drop-in replacement for sys.audit and sys.addaudithook.

import sysaudit

def hook(event, args):
    print("Event:", event, args)

sysaudit.addaudithook(hook)

sysaudit.audit("event_name", 1, 2, dict(key="value"))
# Event: event_name (1, 2, {'key': 'value'})

API

sysaudit.audit(event: str, *args: typing.Any)None

Passes the event to any audit hooks that are attached via addaudithook().

Parameters
  • event (str) –

  • *args (typing.Any) –

Return type

None

sysaudit.audit("event_name", "any", "extra", dict(args="here"))
sysaudit.addaudithook(hook: typing.Callable[[str, typing.Tuple[typing.Any, ], None]])None

Adds a new audit hook callback.

Parameters

hook – Function to call with every event from audit()

Return type

None

def hook(event: str, args: typing.Tuple[typing.Any, ...]) -> None:
    print("Event:", event, "Args:", args)


sysaudit.addaudithook(hook)

sysaudit.audit("event_name", 1, 2, 3)
# Event: event_name Args: (1, 2, 3)

Indices and tables