Webhook Listener
Very basic webserver module to listen for webhooks and forward requests to predefined functions.
Author: Todd Roberts
https://pypi.org/project/webhook_listener/
https://github.com/toddrob99/Webhooks
Install
Install from PyPI using pip
pip install webhook_listener
Use
- Define a function to process requests
requestparameter will be a cherrypy request object*argsparameter will be a tuple of URL path components**kwargsparameter will be a dictionary of URL parameters- Get the body of a
POSTrequest fromrequest.body.readpassing the length ofrequest.headers['Content-Length']:request.body.read(int(request.headers['Content-Length'])) if int(request.headers.get('Content-Length',0)) > 0 else '' - Note: The body will be a byte array, and not a string. You may need to decode it to a string. For example:
import json body_raw = request.body.read(int(request.headers['Content-Length'])) if int(request.headers.get('Content-Length',0)) > 0 else '{}' body = json.loads(body_raw.decode('utf-8'))
- Include webhook-listener in your project
- Create an instance of the webhook_listener.Listener class
- handlers = Dictionary of functions/callables for each supported HTTP method. (Example: {'POST':process_post_request, 'GET':process_get_request})
- port = Port for the web server to listen on (default: 8090)
- host = Host for the web server to listen on (default: '0.0.0.0')
- threadPool = Number of worker threads for the web server (default: 10)
- logScreen = Setting for cherrypy to log to screen (default: False)
- autoReload = Setting for cherrypy to auto reload when python files are changed (default: False)
- sslModule = Select which SSL library to use (default: 'builtin')
- sslCert = Path to the certificate (SSL is disabled when empty)
- sslPrivKey = Path to the certificate's private key (SSL is disabled when empty)
- sslCertChain = Path to the full certificate chain see https://cherrypydocrework.readthedocs.io/deploy.html#ssl-support for more information on SSL support
- Start the Listener
- Keep your application running so the Listener can run in a separate thread
Example
import time
import webhook_listener
def process_post_request(request, *args, **kwargs):
print(
"Received request:\n"
+ "Method: {}\n".format(request.method)
+ "Headers: {}\n".format(request.headers)
+ "Args (url path): {}\n".format(args)
+ "Keyword Args (url parameters): {}\n".format(kwargs)
+ "Body: {}".format(
request.body.read(int(request.headers["Content-Length"]))
if int(request.headers.get("Content-Length", 0)) > 0
else ""
)
)
# Process the request!
# ...
return
webhooks = webhook_listener.Listener(handlers={"POST": process_post_request})
webhooks.start()
while True:
print("Still alive...")
time.sleep(300)
Metadata
Release files for Webhook-Listener 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Webhook_Listener-1.2.0.tar.gz | 4.5 kB | Without provenance | Details for Webhook_Listener-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Webhook_Listener-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for Webhook_Listener-1.2.0-py3-none-any.whl |
Total release size: 9.3 kB
Release files / Webhook_Listener-1.2.0.tar.gz
| Download URL | Webhook_Listener-1.2.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e7d6afd02970df29cc26f79a8c61f181cad751b3612b0e21804d526d9fec3c3
|
|
BLAKE2b-256 checksum How to use checksums |
f0fcd04cda3834a50c5fc248094b5f65508998b2ef81683f312a8c2fe5bfd685
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / Webhook_Listener-1.2.0-py3-none-any.whl
| Download URL | Webhook_Listener-1.2.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
247384452ba4000dd62e1f6bd5a3bc0c4dbd78375620cc61afd6f436ac739661
|
|
BLAKE2b-256 checksum How to use checksums |
2271780e62259e87f8b582f35553f905de72dd16bbaccb52b7077ea52af313dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for Webhook-Listener 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.