mitmproxy-rs
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
- breaking While aiming for API compatibility, `mitmproxy-rs` is a separate implementation. Some APIs, especially for advanced features or internal structures, may diverge from the original `mitmproxy` library.
- breaking The generic `Flow` object was split into `HttpFlow` and `TcpFlow` for better type clarity and functionality separation.
- breaking The main proxy class was renamed from `Proxy` to `Server` for clearer semantics.
- breaking The `Mode` enum for proxy operation was renamed to `ProxyMode`.
- gotcha The library explicitly requires Python 3.12 or newer due to its Rust binding implementation details.
Install
-
pip install mitmproxy-rs
Imports
- Server
from mitmproxy_rs import Server
- HttpFlow
from mitmproxy_rs import HttpFlow
- TcpFlow
from mitmproxy_rs import TcpFlow
- ProxyMode
from mitmproxy_rs import ProxyMode
Quickstart
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())