Skip to main content

licence version pyversions coverage docs

aiostem is an asyncio python library that provides a controller to connect and interact with the Tor control port. It therefore acts as an alternative to the community-maintained stem controller.

What about Stem?

Stem was not meant to be used with asynchronous python and despite an attempt to support this framework, it has never really worked well and was never merged. Additionally it does not use a true asynchronous connection but instead uses worker threads in order not to break existing code.

The initial goal of aiostem was to offer better support for events, as there can be many of them coming at a high rate and I noticed that stem quickly ran into deadlocks and high CPU usage. Moreover, I feel like stem provides too many high level APIs and it is hard to know exactly what is performed under the hood. It has also become too complex and bloated with legacy code, both for a large range of Python versions and support for old versions of Tor.

Tor v0.4.x has been released for many years now, therefore aiostem focuses the support for Tor v0.4.5 and later, as well as Python 3.10 and later.

Additionally, stem does not provide a low-level API around the control protocol, which means that there is time wasted registering and unregistering events all around. aiostem focuses on a clean implementation of the low level protocol, providing far better performances when dealing with a higher number of events.

However, aiostem is not a drop-in replacement for stem since we do not handle the following features:

  • Parsing of server and relay descriptors as in stem.descriptor (we have HS descriptors).

  • Higher (and easier) level APIs mixing commands and events in a single call.

  • Run a Tor daemon from library calls as in stem.process.

  • Download server descriptors as in stem.descriptor.remote.

  • Command line interpreter as in stem.interpreter.

  • Support for older versions of Tor and Python.

Installation

This package requires Python ≥ 3.10 and pulls a few other packages as dependencies such as pydantic for serialization, deserialization and validation of received data, and cryptography to deal with the various keys used by Tor.

To install the latest version use the following command:

python -m pip install aiostem

Usage

This simple example shows how to use the controller in asynchronous python. No extra thread is involved here, everything runs in the event loop.

It shows how to open a controller, authenticate, subscribe to an event, run a command and wait for the DNS resolution event to complete.

#!/usr/bin/env python

import asyncio
from functools import partial
from aiostem import Controller
from aiostem.event import EventAddrMap

def on_addrmap_event(done, event):
    if isinstance(event, EventAddrMap):
        print(f'{event.original} is at {event.replacement}')
        done.set()

async def main():
    # Simple asyncio event to exit when the event has been received.
    done = asyncio.Event()

    # Create a new controller with the default port (9051).
    async with Controller.from_port() as ctrl:
        # Authenticate automatically with a secure method (on localhost only).
        reply = await ctrl.authenticate()
        reply.raise_for_status()

        # Register a callback for ``ADDRMAP`` events.
        await ctrl.add_event_handler('ADDRMAP', partial(on_addrmap_event, done))

        # Request DNS resolution for ``github.com``.
        # The output here is received as an ``ADDRMAP`` event.
        reply = await ctrl.resolve(['github.com'])
        reply.raise_for_status()

        # Wait until the address is resolved.
        await done.wait()

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

This code, when executed displays the following output:

$ python examples/usage.py
github.com is at 140.82.121.4

For further details, please refer to the documentation.

Contributing

Contributions, bug reports and feedback are very welcome, feel free to open an issue, send a pull request. or start a discussion.

Participants must uphold the Code of Conduct.

aiostem is released under the MIT license.

Metadata

Release files for aiostem 0.4.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiostem 0.4.7
File Size Uploaded Provenance
aiostem-0.4.7.tar.gz 164.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiostem 0.4.7
File Interpreter ABI Platform
aiostem-0.4.7-py3-none-any.whl Python 3 none any Details

Total release size: 255.7 kB

Release files / aiostem-0.4.7.tar.gz

Download URL aiostem-0.4.7.tar.gz
Size 164.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6549fb86ec3a3b02f7dc8007f1690f1a29b8db9f3c407379fcaa8fce3581e1a4
BLAKE2b-256 checksum
How to use checksums
cbbfcff75452db45f0630ad09cc5edc877efb0460944cfb0ec9a9c50a8a4f948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2026.

Transparency log

Release files / aiostem-0.4.7-py3-none-any.whl

Download URL aiostem-0.4.7-py3-none-any.whl
Size 91.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69e849e5c97065331d6ab69c17dae9e1b10c89d8aee83108613aef294a20b157
BLAKE2b-256 checksum
How to use checksums
21ff76f8c7520f96411772008cffca4bb7950be9fe2fdebb5889a2b82a569a6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2026.

Transparency log

Security for aiostem 0.4.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aiostem-0.4.7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page