There’s been a couple different efforts to create a Python API for Discourse, have a look at these:
https://github.com/tindie/pydiscourse
https://meta.discourse.org/t/python-module-wip/49467