Is there a way to access the values ioreg utility accesses via Python?

What i'm looking is to add monitoring of the battery status of my Magic Mouse. I know I can get it by using

ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -E '"Product"|BatteryPercent' 

So -- what's the magic to get the value of BatteryPercent into Python, without launching ioreg via subprocess?


The ioreg utility uses IOKit to get the values for for example the battery status of the Magic Mouse.

You can access IOKit from Python using ctypes - a foreign function library for Python. It allows you to call C/Objective C functions etc. from Python.

You can see an example of how to that with IOKit here:


In addition you'll find that someone already creeated a wrapper for IOKit to be accessible from Python here:


  • Thanks. Will check them out. I found first link, but failed come up with the working code yet. – sashk Jul 15 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .