The udev context.
This is the central object to access udev. An instance of this class must be created before anything else can be done. It holds the udev configuration and provides the interface to list devices (see list_devices()).
Instances of this class can directly be given as udev * to functions wrapped through ctypes.
Create a new context.
The sysfs mount point defaulting to /sys' as unicode string.
The mount point can be overwritten using the environment variable SYSFS_PATH. Use this for testing purposes.
The device directory path defaulting to /dev as unicode string.
This can be overridden in the udev configuration.
The run runtime directory path defaulting to /run as unicode string.
Required udev version: 167
New in version 0.10.
The logging priority of the interal logging facitility of udev as integer with a standard syslog priority. Assign to this property to change the logging priority.
UDev uses the standard syslog priorities. Constants for these priorities are defined in the syslog module in the standard library:
>>> import syslog
>>> context = pyudev.Context()
>>> context.log_priority = syslog.LOG_DEBUG
New in version 0.9.
List all available devices.
The arguments of this method are the same as for Enumerator.match(). In fact, the arguments are simply passed straight to method match().
This function creates and returns an Enumerator object, that can be used to filter the list of devices, and eventually retrieve Device objects representing matching devices.
Changed in version 0.8: Accept keyword arguments now for easy matching
Enumerate all available devices.
To retrieve devices, simply iterate over an instance of this class. This operation yields Device objects representing the available devices.
Before iteration the device list can be filtered by subsystem or by property values using match_subsystem() and match_property(). Multiple subsystem (property) filters are combined using a logical OR, filters of different types are combined using a logical AND. The following filter for instance:
devices.match_subsystem('block').match_property(
'ID_TYPE', 'disk').match_property('DEVTYPE', 'disk')
means the following:
subsystem == 'block' and (ID_TYPE == 'disk' or DEVTYPE == 'disk')
Once added, a filter cannot be removed anymore. Create a new object instead.
Instances of this class can directly be given as given udev_enumerate * to functions wrapped through ctypes.
Include devices according to the rules defined by the keyword arguments. These keyword arguments are interpreted as follows:
All keyword arguments are optional, calling this method without no arguments at all is simply a noop.
Return the instance again.
New in version 0.8.
Changed in version 0.13: Added parent keyword
Include all devices, which are part of the given subsystem.
subsystem is either a unicode string or a byte string, containing the name of the subsystem. If nomatch is True (default is False), the match is inverted: A device is only included if it is not part of the given subsystem.
Return the instance again.
Include all devices with the given name.
sys_name is a byte or unicode string containing the device name.
Return the instance again.
New in version 0.8.
Include all devices, whose property has the given value.
property is either a unicode string or a byte string, containing the name of the property to match. value is a property value, being one of the following types:
Return the instance again.
Include all devices, whose attribute has the given value.
attribute is either a unicode string or a byte string, containing the name of a sys attribute to match. value is an attribute value, being one of the following types:
If nomatch is True (default is False), the match is inverted: A device is include if the attribute does not match the given value.
Note
If nomatch is True, devices which do not have the given attribute at all are also included. In other words, with nomatch=True the given attribute is not guaranteed to exist on all returned devices.
Return the instance again.
Include all devices, which have the given tag attached.
tag is a byte or unicode string containing the tag name.
Return the instance again.
Required udev version: 154
New in version 0.6.
Include all devices on the subtree of the given parent device.
The parent device itself is also included.
parent is a Device.
Return the instance again.
Required udev version: 172
New in version 0.13.
Include only devices, which are initialized.
Initialized devices have properly set device node permissions and context, and are (in case of network devices) fully renamed.
Currently this will not affect devices which do not have device nodes and are not network interfaces.
Return the instance again.
See also
Required udev version: 165
New in version 0.8.