Skip to main content

Tor utilities for using with aiohttp

Project description

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

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.2.0.tar.gz (15.1 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.2.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiohttp_tor-0.2.0.tar.gz
  • Upload date:
  • Size: 15.1 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.2.0.tar.gz
Algorithm Hash digest
SHA256 9d17e2dbd58acd831581897646eb4fad070163980d66b450e3524d6d841e7ea5
MD5 2383c4707f82f7dad1696f0b856ef637
BLAKE2b-256 4262cc1fa03da417868cad5e7b5a18f0c04e9513e3b3f2efbb406de23d5b036a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiohttp_tor-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 461a79e728ff88c25c666e08c79dd6996484dfd1f223af028fa3e234b83c9a92
MD5 29102a6cd013a6eddc2ab9e3627c7140
BLAKE2b-256 719a575e44f544c1d123af32371fd249fe9e400c82bcdccb8565d704a7870611

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