An async Python HTTP proxy client for intercepting, responding, and forwarding requests.
- Async/await support throughout
- Intercept and respond to HTTP requests
- Forward requests to other servers with optional response modification
- Lightweight and easy to extend
Clone the repository and install dependencies:
git clone https://github.com/mrsnifo/pyguard.git
cd pyguard
python3 -m pip install -U .from pyguard import Client, Request
from aiohttp.web import Response
client = Client()
@client.event
async def on_ready():
print("Server is ready")
@client.event
async def on_request(request: Request):
print(f"Request from {request.remote}")
# Respond immediately
request.respond(Response(text="Access Denied", status=403))
client.run()from pyguard import Client, Request, Response
client = Client()
@client.event
async def on_request(request: Request):
request.forward("http://localhost:8030", request)
@client.event
async def on_forward(response: Response):
# Modify the forwarded response
response.headers["X-Filtered-By"] = "PyGuard"
response.respond(response)
client.run(host="localhost", port=8080)More examples available in the examples folder.