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 23.11.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 23.11.0
File Size Uploaded Provenance Actions
txtorcon-23.11.0.tar.gz 313.5 kB Without provenance Details for txtorcon-23.11.0.tar.gz

Built distribution (wheel)

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

Total release size: 576.3 kB

Release files / txtorcon-23.11.0.tar.gz

Download URL txtorcon-23.11.0.tar.gz
Size 313.5 kB
Tags Source
SHA-256 checksum
How to use checksums
71f85ae93d76d726510059c9ed74e608bc5a5c9f7d103853b49e414280406a2f
BLAKE2b-256 checksum
How to use checksums
39ebdd87610a296ac02aba6a67668e5811e43078ea32d261e0c8eb2d43d6e67c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

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

Download URL txtorcon-23.11.0-py3-none-any.whl
Size 262.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59ec801a38d6ea3cedc544cfcdb8e6f180b55d51bf9a01224b09f4bf48262f6b
BLAKE2b-256 checksum
How to use checksums
bcef812bfd4172b7a50d920f11c592185fe85b35a0b41f462f008db525bb87db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Security for txtorcon 23.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

23.11.0 This release

2 release files No provenance

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