Stem is a Python controller library that provides a high-level API for interacting with the Tor daemon. It allows applications to query Tor's status, manage circuits and streams, and retrieve information about Tor relays. The current stable version is 1.8.2, with releases occurring as needed for bug fixes and minor enhancements.
pip install stemVerified import paths — ran on the pinned version, not inferred.
This example connects to a running Tor daemon's control port (typically 9051) and authenticates using either an environment variable for a password or via Tor's default cookie-based authentication. It then prints the Tor version and the number of active circuits.
Ensure Tor is installed and running. Check your `torrc` file for `ControlPort` and `SocksPort` settings. You can optionally use `stem.process.launch_tor_with_config` to start a Tor process.
Provide the correct `HashedControlPassword` to `controller.authenticate(password='your_password')` or ensure stem can access the Tor cookie file. If using default `CookieAuthentication`, `controller.authenticate()` without arguments should work if the cookie file is in its default location.
Always use `with launch_tor_with_config(...) as tor_process:` or ensure `tor_process.kill()` is called in a `finally` block. Pass `tor_path='path/to/tor'` if not in PATH. Ensure `init_msg_handler` is used for proper startup feedback.
Verify that Tor is running and that its `ControlPort` is configured and accessible (e.g., `ControlPort 9051`). Check firewall rules. If launching Tor with `stem.process`, ensure `tor_path` is correct and Tor starts successfully.
Provide the correct `HashedControlPassword` to `controller.authenticate(password='your_password')`. Double-check your `torrc` file for the password setting.
Ensure `CookieAuthentication 1` is set in `torrc` and the `CookieAuthFile` is in a default or accessible location. If manually specifying, pass `controller.authenticate(private_key='/path/to/control_auth_cookie')`.
No dependency data recorded yet.