pyprctl

raw JSON →
0.1.3 verified Mon Apr 27 auth: no python

A pure-Python interface to Linux's prctl() syscall and related functionality (e.g., capabilities, process names, securebits) using ctypes. Version 0.1.3, released 2023-06-18. Low release cadence.

pip install pyprctl
error AttributeError: module 'pyprctl' has no attribute 'prctl'
cause Did import pyprctl instead of from pyprctl import prctl
fix
Use: from pyprctl import prctl
error AttributeError: module 'pyprctl' has no attribute 'Cap'
cause Cap class is in pyprctl.caps, not directly in pyprctl
fix
Use: from pyprctl.caps import Cap
gotcha On Python <3.8, os.fsencode() may behave differently for process names; always pass str to prctl_set_name()
fix Ensure argument is a str, not bytes.
breaking v0.1.2 removed follow_symlinks parameter from FileCaps methods; code using it will break.
fix Remove follow_symlinks argument from FileCaps.get() / FileCaps.set() calls.

Demonstrates basic usage: querying capability sets and checking support.

from pyprctl import prctl
from pyprctl.caps import Cap

# Get current capability sets
permitted = prctl.cap_get_pc()
effective = prctl.cap_get_ec()
print(permitted, effective)

# Check if a capability is supported
if Cap.CAP_NET_RAW.is_supported():
    print("CAP_NET_RAW is supported")