How do I get python output in ha

You can use the Command line Sensor for it.

EDIT: Here’s an example running queries on a mysql db.