An ASGI function for proxying to a backend over HTTP
Project description
asgi-proxy-lib
An ASGI function for proxying to a backend over HTTP
⚠️ Warning: this is an early alpha.
Installation
Install this library using pip
:
pip install asgi-proxy-lib
Usage
This library provides a single ASGI function called asgi_proxy
. You can use it like this:
from asgi_proxy import asgi_proxy
app = asgi_proxy("https://datasette.io")
Now app
is an ASGI application that will proxy all incoming HTTP requests to the equivalent URL on https://datasette.io
.
The function takes an optional second argument, log=
- set this to a Python logger, or any object that has .info(msg)
and .error(msg)
methods, and the proxy will log information about each request it proxies.
It also takes a timeout=
option, which defaults to None
for no timeout. This can be set to a floating point value in seconds to enforce a timeout on requests that are being proxied.
CLI tool
You can try this module out like so:
python -m asgi_proxy https://datasette.io
You may need to pip install uvicorn
first for this to work.
This will start a server on port 8000 that proxies to https://datasette.io
.
Add -p PORT
to specify a different port, --timeout 3
to set a timeout, --verbose
to see debug logging, and --host 127.0.0.1
to listen on a different host (the default is 0.0.0.0
).
Development
To contribute to this library, first checkout the code. Then create a new virtual environment:
cd asgi-proxy-lib
python -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file asgi_proxy_lib-0.2a0.tar.gz
.
File metadata
- Download URL: asgi_proxy_lib-0.2a0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b88f218751f8e25d43022485c3e7a040a0788d33f36a51775542e328c4160e86 |
|
MD5 | deea242c7df4654e2288a9c46c60f7ca |
|
BLAKE2b-256 | a4b2bb8a4cc83e86a983d69df4d4e1836948b944e1b12b2349993dd878c39005 |
File details
Details for the file asgi_proxy_lib-0.2a0-py3-none-any.whl
.
File metadata
- Download URL: asgi_proxy_lib-0.2a0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 658f938dc2d5cb39bbbf09e2c427ec96cfcfbb0e47bc9b3ee19ee3ec90f7e960 |
|
MD5 | ddae52725085583683e89c254efae65e |
|
BLAKE2b-256 | 8e52b51e5492b4256b889ddcfd7ec576c894bea024a80ffc22455ae350237c8e |