Skip to main content
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).

Metadata

Release files for txtorcon 26.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for txtorcon 26.6.0
File Size Uploaded
txtorcon-26.6.0.tar.gz 312.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for txtorcon 26.6.0
File Interpreter ABI Platform
txtorcon-26.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 574.0 kB

Release files / txtorcon-26.6.0.tar.gz

Download URL txtorcon-26.6.0.tar.gz
Size 312.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0408f063a9fcb8df529daca57bb7373ea0f5b4ebaffcd5103754b7c561773f68
BLAKE2b-256 checksum
How to use checksums
0c599b868727e8a41b6b5be4c0dad15b8188b75cb9ca3162aa7cdd20b7cfa808
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.6

Release files / txtorcon-26.6.0-py3-none-any.whl

Download URL txtorcon-26.6.0-py3-none-any.whl
Size 261.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c5a6e9bf639e48a8fb8a19ceedca0c8b40a8b15c7c049483671fec625dc93a0
BLAKE2b-256 checksum
How to use checksums
4127c8b133268a62f7afa637f0cba1a02741a91cb91ad24596bc3f947c1754a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.6

Release history Release notifications | RSS feed

This release

26.6.0 This release

2 release files

24.8.0

2 release files

23.5.0

2 release files

23.0.0

2 release files

22.0.0

2 release files

21.1.0

2 release files

19.1.0

2 release files

19.0.0

2 release files

18.1.0

2 release files

18.0.1

2 release files

18.0.0

2 release files

0.20.0

2 release files

0.19.3

2 release files

0.19.2

2 release files

0.19.1

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.11.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page