On the B+ (and presumably Pi2) the "PWR" LED was connected to a GPIO pin as was the APX803 voltage monitor chip. This let the LED be controlled, and (presumably) let the Pi detect under-voltage.
The Pi3 "PWR" LED is directly connected to the APX803 but the APX803 is still connected to PWR_LOW_N
. Unfortunately this is not documented and the schematic is incomplete, but is reputed to be on a port extender. Obviously the kernel can detect this, but again there appears to be no documentation. The only option seems to be exploring kernel sources.
How can I control the red LED again shows some info about the output status.
EDIT
I did a bit of digging, and was directed to https://github.com/6by9/rpi3-gpiovirtbuf/ I have tested on my Pi3, and it works. rpi3-gpiovirtbuf g 135
produces output
Get state of 135 as 1
get_config dir input, active low (inverted), not terminated
which is active low and indicates Voltage is OK.
Admittedly this is not Python, but is very simple c and it would be possible to replicate.
Incidentally testing proved to be a challenge. For all the reports on this site of inadequate power supplies, I could not find one which was reliably low, and had to make a variable regulator.
The APX803 is open drain, so it should be possible to pull it low (and turn the LED off) with a program.