Receiving Webhooks with Python

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

from flask import Flask, request, abort

app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook():
    if request.method == 'POST':
        return 'success', 200

if __name__ == '__main__':

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.