Skip to main content

Twisted-based Tor controller client, with state-tracking and configuration abstractions. https://txtorcon.readthedocs.org https://github.com/meejah/txtorcon

Project description

github-actions coveralls codecov ReadTheDocs ReadTheDocs

txtorcon

Ten Thousand Feet

txtorcon is an implementation of the control-spec for Tor using the Twisted networking library for Python.

This is useful for writing utilities to control or make use of Tor in event-based Python programs. If your Twisted program supports endpoints (like twistd does) your server or client can make use of Tor immediately, with no code changes. Start your own Tor or connect to one and get live stream, circuit, relay updates; read and change config; monitor events; build circuits; create onion services; etcetera (ReadTheDocs).

Some Possibly Motivational Example Code

download

from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks, ensureDeferred
from twisted.internet.endpoints import UNIXClientEndpoint

import treq
import txtorcon


async def main(reactor):
    tor = await txtorcon.connect(
        reactor,
        UNIXClientEndpoint(reactor, "/var/run/tor/control")
    )

    print("Connected to Tor version {}".format(tor.version))

    url = u'https://www.torproject.org:443'
    print(u"Downloading {}".format(repr(url)))
    resp = await treq.get(url, agent=tor.web_agent())

    print(u"   {} bytes".format(resp.length))
    data = await resp.text()
    print(u"Got {} bytes:\n{}\n[...]{}".format(
        len(data),
        data[:120],
        data[-120:],
    ))

    print(u"Creating a circuit")
    state = await tor.create_state()
    circ = await state.build_circuit()
    await circ.when_built()
    print(u"  path: {}".format(" -> ".join([r.ip for r in circ.path])))

    print(u"Downloading meejah's public key via above circuit...")
    config = await tor.get_config()
    resp = await treq.get(
        u'https://meejah.ca/meejah.asc',
        agent=circ.web_agent(reactor, config.socks_endpoint(reactor)),
    )
    data = await resp.text()
    print(data)


@react
def _main(reactor):
    return ensureDeferred(main(reactor))

Try It Now On Debian/Ubuntu

For example, serve some files via an onion service (aka hidden service):

$ sudo apt-get install --install-suggests python3-txtorcon
$ twistd -n web --port "onion:80" --path ~/public_html

Read More

All the documentation starts in docs/index.rst. Also hosted at txtorcon.rtfd.org.

You’ll want to start with the introductions (hosted at RTD).

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

txtorcon-23.11.0.tar.gz (313.5 kB view details)

Uploaded Source

Built Distribution

txtorcon-23.11.0-py3-none-any.whl (262.8 kB view details)

Uploaded Python 3

File details

Details for the file txtorcon-23.11.0.tar.gz.

File metadata

  • Download URL: txtorcon-23.11.0.tar.gz
  • Upload date:
  • Size: 313.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for txtorcon-23.11.0.tar.gz
Algorithm Hash digest
SHA256 71f85ae93d76d726510059c9ed74e608bc5a5c9f7d103853b49e414280406a2f
MD5 59c8bff94b195147ae6adbfd313f8dd4
BLAKE2b-256 39ebdd87610a296ac02aba6a67668e5811e43078ea32d261e0c8eb2d43d6e67c

See more details on using hashes here.

File details

Details for the file txtorcon-23.11.0-py3-none-any.whl.

File metadata

  • Download URL: txtorcon-23.11.0-py3-none-any.whl
  • Upload date:
  • Size: 262.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for txtorcon-23.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59ec801a38d6ea3cedc544cfcdb8e6f180b55d51bf9a01224b09f4bf48262f6b
MD5 b15be86a3790fda757cea3202fda4b72
BLAKE2b-256 bcef812bfd4172b7a50d920f11c592185fe85b35a0b41f462f008db525bb87db

See more details on using hashes here.

Supported by

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