Skip to content

mrsnifo/pyguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyGuard

Python Versions

An async Python HTTP proxy client for intercepting, responding, and forwarding requests.

Key Features

  • Async/await support throughout
  • Intercept and respond to HTTP requests
  • Forward requests to other servers with optional response modification
  • Lightweight and easy to extend

Installing

Clone the repository and install dependencies:

git clone https://github.com/mrsnifo/pyguard.git
cd pyguard
python3 -m pip install -U .

Respond Example

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()

Forward Example

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.

About

Async HTTP proxy for intercepting and forwarding requests.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages