Async-first ยท Type-safe ยท Tokio runtime

Tor control protocol
for Rust.

A complete Rust implementation of the Tor control protocol. Connect to Tor, authenticate with any method, query network information, and subscribe to real-time events.

Up and running in minutes

Clear, well-documented examples to get you started with the most common use cases.

1

Connect & Authenticate

Establish connection to Tor control port

Rust
use stem::{ConnectOptions, connect};

#[tokio::main]
async fn main() -> stem::Result<()> {
    let controller = connect(ConnectOptions::default()).await?;
    println!("Connected to Tor!");
    Ok(())
}
2

Query Information

Get version, status, and network metrics

Rust
let version = controller.get_version().await?;
println!("Tor version: {version}");

let bytes_read = controller.get_info("traffic/read").await?;
let bytes_written = controller.get_info("traffic/written").await?;

let circuits = controller.get_circuits().await?;
3

Subscribe to Events

Real-time bandwidth and circuit monitoring

Rust
use stem::events::EventType;

let (_, mut events) = controller
    .subscribe(&[EventType::Bw, EventType::Circ])
    .await?;

while let Some(event) = events.recv().await {
    println!("{} {:?}", event.event_type, event.data);
}
๐Ÿ“ฆ

Download Source

Get the latest source code archive