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

travis coveralls codecov ReadTheDocs ReadTheDocs Code Health

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 (also python2 style)

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-20.0.0.tar.gz (306.1 kB view details)

Uploaded Source

Built Distribution

txtorcon-20.0.0-py2.py3-none-any.whl (260.4 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: txtorcon-20.0.0.tar.gz
  • Upload date:
  • Size: 306.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.3

File hashes

Hashes for txtorcon-20.0.0.tar.gz
Algorithm Hash digest
SHA256 122cd081786396f57718adda1c1a5eb01b8e9a4832fcd140918b45c10359377a
MD5 12c1606c70cca6397ab4ab5117095f8b
BLAKE2b-256 a5124d39a81dd2f60d7c54d2be5484054d668fed27741bee02ebebe55123838a

See more details on using hashes here.

File details

Details for the file txtorcon-20.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: txtorcon-20.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 260.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.3

File hashes

Hashes for txtorcon-20.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5c1145566a8733105da851b794e7b15cb56cea48693635b55c4bddfb79fe629d
MD5 7d9c4fbddb9acca286589652f3cd2156
BLAKE2b-256 13e01c53da6e7dc0b9cc052c64057768ba01337efb1e31a00eac25a3bac85d5d

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