Skip to main content

Tor utilities for using with aiohttp

Project description

Aiohttp-Tor

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 TorConnector, 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):
        # TorConnector should mirror what you've launched tor with.
        async with ClientSession(connector=TorConnector(port=9050, ctrl_port=9051)) 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp_tor-0.1.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_tor-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_tor-0.1.0.tar.gz.

File metadata

  • Download URL: aiohttp_tor-0.1.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiohttp_tor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d86047a96e3fb074ab201fb735ece7aa24bb470900817aa7668456f488ebf1b2
MD5 ab1e05d3a69046ec2824141395e03ca1
BLAKE2b-256 a1b909739141fc7e7c90d7e35df16f25a198ce0a7c2b61e02a250313010c181e

See more details on using hashes here.

File details

Details for the file aiohttp_tor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_tor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiohttp_tor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a07c501e20b9b363f0b637f021da6d2979d9276b02e3cb6366e4459e0953ca36
MD5 bc183e95be1bf0893ec8b57b8a0b16b9
BLAKE2b-256 91348b9015eb9413bcab70ec61de7a744cf2e6f2c8343fc29b3c641c3c9067c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page