You could run the python outside of HA and then communicate the information to HA via MQTT. HA has an addon MQTT broker. In this post I have a python script that watches GPIO pins and then sends an MQTT message that is configured into a sensor. If you have a look you can search for watchpins_mqtt.bash to find the relevant parts of the post. I run a supervised install and then just run this script from rc.local on my system.