Skip to main content

Asgiproxify

Asgiproxify is an ASGI middleware for dynamic reverse proxy.

Installation

Of course, you can directly install from PyPI.

(venv) $ pip install asgiproxify

Getting Started

You can easily make a running example from these lines:

import uvicorn

from asgiproxify import Asgiproxify

proxify = Asgiproxify()
uvicorn.run(proxify)

Oh, you have an ASGI server already? You can set a fallback:

import uvicorn

from app import app
from asgiproxify import Asgiproxify

proxify = Asgiproxify(app) # or proxify.to(app)
uvicorn.run(proxify)

Adding a new reverse proxy endpoint is as simple as:

import uvicorn

from asgiproxify import Asgiproxify, AsgiproxifyHandler

proxify = Asgiproxify()


@proxify.register('/example/')
class FooProxyHanlder(AsgiproxifyHandler):
	pass

uvicorn.run(proxify)

This will register a handler to handle all requests to /example/*. By default, an AsgiproxifyHandler will proxy any request to example.org.

AsgiproxifyHandler can be smarter than that, like proxy to any URL you wish, like this:

import uvicorn

from asgiproxify import Asgiproxify, AsgiproxifyHandler

proxify = Asgiproxify()


@proxify.register('/LICENSE')
class FooProxyHanlder(AsgiproxifyHandler):
	def make_request_url(self):
		return 'https://www.gnu.org/licenses/gpl-3.0.txt'

uvicorn.run(proxify)

You may dynamically make revrese proxy by reading self.scope. Its content is specified in ASGI Specification.

A little example for that will be:

import uvicorn

from asgiproxify import Asgiproxify, AsgiproxifyHandler

proxify = Asgiproxify()


@proxify.register('/')
class FooProxyHanlder(AsgiproxifyHandler):
	def make_request_url(self):
		return 'https://ftp.gnu.org' + self.scope['path']

uvicorn.run(proxify)

You can do more with it by utilizing the scope and other infomation. The parameters you can tweek from the hander are request_url, request_cookies, request_headers and response_headers. If that's not enough for you, you can override make_request which will allow you to create your own aiohttp request!

You can consult proxify.py for more technical infomation.

License

This project is proudly licensed in GNU General Public License v3 or later.

Please refer to COPYING for more infomation.

Release files for asgiproxify 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asgiproxify 0.0.1
File Size Uploaded
asgiproxify-0.0.1.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asgiproxify 0.0.1
File Interpreter ABI Platform
asgiproxify-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.0 kB

Release files / asgiproxify-0.0.1.tar.gz

Download URL asgiproxify-0.0.1.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
56ebbff09e9dfa4b051f82f598c273fd8bac5a11011cac4e3def86c781027a4d
BLAKE2b-256 checksum
How to use checksums
e0347736b41265a5eb4ecd28ac433bf1e9f72797c7339d43a6ed3d948124b07f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / asgiproxify-0.0.1-py3-none-any.whl

Download URL asgiproxify-0.0.1-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4252b89b0ee99c4a9c30f57d570220e9295bb37aa5e44cfcc9c05b8ea211ad39
BLAKE2b-256 checksum
How to use checksums
c0ad2e533a074f455f89d6f5d7b70cb9ed9c911ef68187feb12ed9c6a8052ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page