mitmproxy-rs

0.12.9 · active · verified Fri Apr 10

mitmproxy-rs is a Python library that re-implements the core functionality of the `mitmproxy` project in Rust, providing a high-performance, async-first HTTP/HTTPS proxy. It offers a largely compatible API for programmatic interception and modification of network traffic, targeting Python 3.12 and newer. As of version 0.12.9, it's under active development with frequent minor releases.

Warnings

Install

Imports

Quickstart

This example starts a simple HTTP proxy that listens on `127.0.0.1:8080` and prints the method and URL of every intercepted HTTP request. It showcases the `Server` and `HttpFlow` objects.

import mitmproxy_rs
import asyncio

async def main():
    # A simple HTTP proxy that logs all requests
    async with mitmproxy_rs.Server(listen_host="127.0.0.1", listen_port=8080) as server:
        async for flow in server.run():
            print(f"[{flow.request.method}] {flow.request.pretty_url}")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →