# asgi-proxy-lib
[![PyPI](https://img.shields.io/pypi/v/asgi-proxy-lib.svg)](https://pypi.org/project/asgi-proxy-lib/)
[![Changelog](https://img.shields.io/github/v/release/simonw/asgi-proxy-lib?include_prereleases&label=changelog)](https://github.com/simonw/asgi-proxy-lib/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/asgi-proxy-lib/blob/main/LICENSE)
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:
```python
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:
```bash
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
Raw data
{
"_id": null,
"home_page": "https://github.com/simonw/asgi-proxy-lib",
"name": "asgi-proxy-lib",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Simon Willison",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/a4/b2/bb8a4cc83e86a983d69df4d4e1836948b944e1b12b2349993dd878c39005/asgi_proxy_lib-0.2a0.tar.gz",
"platform": null,
"description": "# asgi-proxy-lib\n\n[![PyPI](https://img.shields.io/pypi/v/asgi-proxy-lib.svg)](https://pypi.org/project/asgi-proxy-lib/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/asgi-proxy-lib?include_prereleases&label=changelog)](https://github.com/simonw/asgi-proxy-lib/releases)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/asgi-proxy-lib/blob/main/LICENSE)\n\nAn ASGI function for proxying to a backend over HTTP\n\n**\u26a0\ufe0f Warning: this is an early alpha.**\n\n## Installation\n\nInstall this library using `pip`:\n\n pip install asgi-proxy-lib\n\n## Usage\n\nThis library provides a single ASGI function called `asgi_proxy`. You can use it like this:\n\n```python\nfrom asgi_proxy import asgi_proxy\n\napp = asgi_proxy(\"https://datasette.io\")\n```\nNow `app` is an ASGI application that will proxy all incoming HTTP requests to the equivalent URL on `https://datasette.io`.\n\nThe 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.\n\nIt 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.\n\n## CLI tool\n\nYou can try this module out like so:\n\n```bash\npython -m asgi_proxy https://datasette.io\n```\nYou may need to `pip install uvicorn` first for this to work.\n\nThis will start a server on port 8000 that proxies to `https://datasette.io`.\n\nAdd `-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`).\n\n## Development\n\nTo contribute to this library, first checkout the code. Then create a new virtual environment:\n\n cd asgi-proxy-lib\n python -m venv venv\n source venv/bin/activate\n\nNow install the dependencies and test dependencies:\n\n pip install -e '.[test]'\n\nTo run the tests:\n\n pytest\n",
"bugtrack_url": null,
"license": "Apache License, Version 2.0",
"summary": "An ASGI function for proxying to a backend over HTTP",
"version": "0.2a0",
"project_urls": {
"CI": "https://github.com/simonw/asgi-proxy-lib/actions",
"Changelog": "https://github.com/simonw/asgi-proxy-lib/releases",
"Homepage": "https://github.com/simonw/asgi-proxy-lib",
"Issues": "https://github.com/simonw/asgi-proxy-lib/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8e52b51e5492b4256b889ddcfd7ec576c894bea024a80ffc22455ae350237c8e",
"md5": "ddae52725085583683e89c254efae65e",
"sha256": "658f938dc2d5cb39bbbf09e2c427ec96cfcfbb0e47bc9b3ee19ee3ec90f7e960"
},
"downloads": -1,
"filename": "asgi_proxy_lib-0.2a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ddae52725085583683e89c254efae65e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8241,
"upload_time": "2024-11-06T07:40:59",
"upload_time_iso_8601": "2024-11-06T07:40:59.664696Z",
"url": "https://files.pythonhosted.org/packages/8e/52/b51e5492b4256b889ddcfd7ec576c894bea024a80ffc22455ae350237c8e/asgi_proxy_lib-0.2a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a4b2bb8a4cc83e86a983d69df4d4e1836948b944e1b12b2349993dd878c39005",
"md5": "deea242c7df4654e2288a9c46c60f7ca",
"sha256": "b88f218751f8e25d43022485c3e7a040a0788d33f36a51775542e328c4160e86"
},
"downloads": -1,
"filename": "asgi_proxy_lib-0.2a0.tar.gz",
"has_sig": false,
"md5_digest": "deea242c7df4654e2288a9c46c60f7ca",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 8242,
"upload_time": "2024-11-06T07:41:00",
"upload_time_iso_8601": "2024-11-06T07:41:00.935805Z",
"url": "https://files.pythonhosted.org/packages/a4/b2/bb8a4cc83e86a983d69df4d4e1836948b944e1b12b2349993dd878c39005/asgi_proxy_lib-0.2a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-06 07:41:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "simonw",
"github_project": "asgi-proxy-lib",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "asgi-proxy-lib"
}