Dependency-free Python bindings for the Linux kernel keyring: add, search, read, describe, link and unlink keys in session and process keyrings, without shelling out to keyctl(1).
Requires Python 3.10+ and Linux. No runtime dependencies: the bindings call add_key(2), request_key(2) and keyctl(2) through ctypes.
pip install keyctl2
import keyctl2
# Add a user key to the session keyring and read it back.
serial = keyctl2.add_key("user", "my-secret", b"hunter2")
key = keyctl2.Key(serial)
assert key.read() == b"hunter2"
# Search the session keyring for it later.
assert keyctl2.search("session", "user", "my-secret") == serial
# Inspect it and clean up.
print(key.describe()) # KeyDescription(type='user', ...)
key.unlink("session")
uv sync --group dev
make check
License: 0BSD. Quad4 Software, https://quad4.io