Skip to main content

Aiohttp-Tor

PyPI version PyPI - Downloads

Inspired by the stem library from the tor-project, this project attempts to make seemless transitions with aiohttp and tor. For both clients and hosting.

Running Clients

from aiohttp_tor import launch, MessageHandler
from aiohttp import ClientSession
import asyncio


# if you want to use the init_msg_handler here's the steps to follow.
handler = MessageHandler()

@handler.on_message
async def send_message(msg:str):
    print(msg)


async def request_for_onionsite():
    async with launch(ctrl_port=9051, socks_port=9050, init_msg_handler=handler) as process:
        # NOTE: use connect() to avoid any annoying setups. 
        # there's nothing more stressful than remebering what ports to use.
        async with ClientSession(connector=process.connect()) as session:
            async with session.get("http://mf34jlghauz5pxjcmdymdqbe5pva4v24logeys446tdrgd5lpsrocmqd.onion/index.html") as resp:
                data = await resp.read()
                print(data)
                # b'\n\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n ... and so on...

    

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

Running Tor Hidden Services

from aiohttp_tor.web import run_app
from aiohttp.web import Application, RouteTableDef, Request, Response

import winloop # There's custom options for uvloop/winloop thanks to loop_factory

routes = RouteTableDef()
app = Application()

@routes.get('/')
async def index(request:Request):
    return Response(body=b"<html><body><h1>Hi Grandma!</h1></body></html>", content_type="text/html")

# Tor hidden service will be located in a .tor-hs directory
# unless you pass a hidden_service_dir parameter, this is to make 
# things friendly for beginners but it's encouraged to change it's path 
# so that bad actors can't find it.

if __name__ == "__main__":
    app.add_routes(routes)
    run_app(app, loop_factory=winloop.new_event_loop, port=6999)

Requirements

  • Python 3.10+ (Due to how aiostem works)
  • aiostem
  • aiohttp-socks (For sending Client Requests)
  • aiohttp

Metadata

Release files for aiohttp-tor 0.2.0

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

Source distribution (sdist)

Source distribution for aiohttp-tor 0.2.0
File Size Uploaded Provenance Actions
aiohttp_tor-0.2.0.tar.gz 15.1 kB Without provenance Details for aiohttp_tor-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-tor 0.2.0
File Interpreter ABI Platform Actions
aiohttp_tor-0.2.0-py3-none-any.whl Python 3 none any Details for aiohttp_tor-0.2.0-py3-none-any.whl

Total release size: 31.2 kB

Release files / aiohttp_tor-0.2.0.tar.gz

Download URL aiohttp_tor-0.2.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9d17e2dbd58acd831581897646eb4fad070163980d66b450e3524d6d841e7ea5
BLAKE2b-256 checksum
How to use checksums
4262cc1fa03da417868cad5e7b5a18f0c04e9513e3b3f2efbb406de23d5b036a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / aiohttp_tor-0.2.0-py3-none-any.whl

Download URL aiohttp_tor-0.2.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
461a79e728ff88c25c666e08c79dd6996484dfd1f223af028fa3e234b83c9a92
BLAKE2b-256 checksum
How to use checksums
719a575e44f544c1d123af32371fd249fe9e400c82bcdccb8565d704a7870611
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for aiohttp-tor 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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