Skip to main content

Host a temporary HTTP server to receive a web-hook callback.

Project description

Receive

receive is a python library for hosting temporary web servers and receiving values from their route handlers via futures.

Install

Stable Release

pip install receive

Latest Features

pip install git+https://github.com/BlakeASmith/receive

Usage

Handle a GET request

First, define a route handler as follows:

import receive

@receive.get_request(route="/callback", port=5000)
async def get_query_param_from_request(req):
    return req.query["code"]

The req parameter is an aiohttp.web.Request object. In this example we return the code query parameter from the request.

Now we can start a temporary web server, and get our return value from the first request that comes in.

import asyncio

async def main():
    future = await get_query_param_from_request()
    code = await future
    print(code)
    
    
if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(main)

The get_query_param_from_request function will start a web server in the background and return a asyncio.Future object providing access to the return value from the handler. get_query_param_from_request will return immediately, and invoking await on the returned future will block until a GET 0.0.0.0:5000/callback request hits the server. At that time the future will be completed with the value returned from the request handler and the server will be shutdown.

Tests

Run the unit tests using pytest

poetry install
poetry run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

receive-0.1.1.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

receive-0.1.1-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file receive-0.1.1.tar.gz.

File metadata

  • Download URL: receive-0.1.1.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure

File hashes

Hashes for receive-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d0c5e715c07cd8c317ce09bd0dc32f405e62067a041e80c9133d790aafc9b2aa
MD5 69704258be59e5cf28d6b844b21b5515
BLAKE2b-256 03f132cf78fa83c3709a32c8a4d5157681c695334f06df9a5d769a0e96ccd6f6

See more details on using hashes here.

File details

Details for the file receive-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: receive-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.4.0-1047-azure

File hashes

Hashes for receive-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b03d1e83fef03d4f8bd5ee5724c54107848c8d6f1eb8c7d27da39bb10c2a89d
MD5 13f4ff5821905909b8ef659660ba7dee
BLAKE2b-256 7461e5ceda82b950ed9f276530fd6fb64b74291c12654c3b3f2ef2daf56a1032

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page