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 python3 style)

from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
from twisted.internet.endpoints import UNIXClientEndpoint
import treq
import txtorcon

@react
@inlineCallbacks
def main(reactor):
    tor = yield txtorcon.connect(
        reactor,
        UNIXClientEndpoint(reactor, "/var/run/tor/control")
    )

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

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

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

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

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

Try It Now On Debian/Ubuntu

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

$ sudo apt-get install --install-suggests python-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-19.1.0.tar.gz (312.7 kB view details)

Uploaded Source

Built Distribution

txtorcon-19.1.0-py2.py3-none-any.whl (341.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: txtorcon-19.1.0.tar.gz
  • Upload date:
  • Size: 312.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.4.2 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for txtorcon-19.1.0.tar.gz
Algorithm Hash digest
SHA256 25d8e52c3eac45bb90ff958ca7cdd7674fb3284e3a50826a58ab7b9578b15ea5
MD5 fb323f9874298a8145dbe8d43c387932
BLAKE2b-256 8c26d5b2fba4ffbcb23957ff2cee4d7d0a2d667372b9eb04807058bd561c8e8f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: txtorcon-19.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 341.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.4.2 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for txtorcon-19.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e93aef50f339b537ed969a4d83a704a2870658bb49cdfa95495ba5a740548d32
MD5 cee1a33539664690c28588b45631f0f0
BLAKE2b-256 4e36910a6991534847eda30e99a7c363cd2bbe6710fc05a2d54c9abe22507ffe

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