This video shows you how to receive webhooks with Python using the requests module.
Webhooks with Python - Part 2!
In this article, we will go over how to make a simple webserver in Flask to receive a webhook.
If you haven't already, check out our last article on how to send webhooks using the request module in python
Setting up a Flask Server to Receive webhooks
Flask is a lightweight web framework for Python. It can be installed with the following command:
pip install flask
Flask server code
Once Flask is installed, create a file with the following code. I called mine server.py
from flask import Flask, request, abort
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
print(request.json)
return 'success', 200
else:
abort(400)
if __name__ == '__main__':
app.run()
And that's all you need to set up a simple webserver to receive webhooks! you can customize the logic within the webhook() function to pretty much do anything with the data received.