This is the same question as in Change keyboard locks in Python or How to change caps lock status without key press.
But there is a difference!!
I don't want to change the lights on /dev/console or /dev/tty but on a human interface device that is connected via USB and recognised as /dev/hidraw0.
To make it even harder, this is being used on a Raspberry Pi.
The method suggested in the other questions doesn't work.
Using library at Jakub Wilk's library at http://jwilk.net/software/python-keyboardleds, it is pretty simple:
The trick is to determine which input device your keyboard is. To figure that out, you look at /proc/bus/input/devices. (Thanks to Jakub for this solution)
I tested this on two a keyboards:
Result: It works for the former but not the latter.
Perhaps someone knows whether that's a driver issue or a problem of the hardware itself (not responding to requests from the driver).