python-networkmanager wraps NetworkManagers D-Bus interface so you can be less verbose when talking to NetworkManager from python. All interfaces have been wrapped in classes, properties are exposed as python properties and function calls are forwarded to the correct interface.
I wrote it to reduce a 100-line python script to 50 lines. Not realizing that the library has more lines than the ones I removed. Oh well 😊
Platforms: Linux systems with NetworkManager 0.90
All the code is contained in one module: NetworkManager. Using it is as simple as you think it is:
>>> import NetworkManager >>> NetworkManager.NetworkManager.Version '0.9.1.90'
NetworkManager exposes a lot of information via D-Bus and also allows full control of network settings. The full D-Bus API can be found on NetworkManager project website. All interfaces listed there have been wrapped in classes as listed below.
This is the base class for all interface wrappers. It adds a few useful features to standard D-Bus interfaces:
Many of NetworkManagers D-Bus methods expect or return numeric constants, for which there are enums in teh C sourece code only. These constants, such as NM_STATE_CONNECTED_GLOBAL, can all be found in the NetworkManager module as well. The const() function can help you translate them to text. For example:
>>> NetworkManager.const('state', 40) 'connecting' >>> NetworkManager.const('device_type', 2) 'wifi'
This class represents the org.freedesktop.NetworkManager interface. Note that NetworkManager.NetworkManager actually is the singleton instance of this class.
This class represents the org.freedesktop.NetworkManager.Settings interface. Note that NetworkManager.Settings actually is the singleton instance of this class.
This class represents the org.freedesktop.NetworkManager.Settings.Connection interface.
This class represents the org.freedesktop.NetworkManager.Connection.Active interface.
This class represents the org.freedesktop.NetworkManager.AccessPoint interface.
These classes represent D-Bus interfaces for various types of hardware. Note that methods such as NetworkManager.GetDevices() will only return Device instances. To get the hardware-specific class, you can call the Device.SpecificDevice() method.
>>> [(dev.Interface, dev.SpecificDevice().__class__.__name__) ... for dev in NetworkManager.NetworkManager.GetDevices()] [('eth0', 'Wired'), ('wlan0', 'Wireless'), ('wwan0', 'Modem')]
These classes represent the various IP configuration interfaces.
This class represents the org.freedesktop.NetworkManager.VPN.Connection interface.