4

Many people have shown how to use Tor in Python like this:

proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy_support) 
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
print opener.open(url).read()

However, I'm hunting for a python bindings to Tor, that to be integrated into my App.

I mean, users will not need to download and install and configure Tor again.

That would be very useful, help please.

Thanks.

1
  • What kind of bindings? What is it you want to control? Commented Mar 24, 2011 at 4:56

3 Answers 3

2

There are a few python libraries, the most common ones being stem and txtorcon. As for directing traffic over tor, you might find stem's client usage tutorial to be helpful.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the tor control port to setup tor, the reason there aren't any bindings to tor is because tor effectively already has an API. You would still need to use tor as a SOCKS proxy, which most python libraries don't support very well.

Comments

0

If depending on Twisted is fine, you can try the txtorcon library which speaks to Tor via the control port. It supports the endpoints API for hidden services, has documentation, examples and 95%+ unit-test coverage. There are abstractions for continuously-updated state (i.e. the current state of Tor, with streams, circuits, etcetera) and configuration (setting and reading).

It does depend upon a locally installed tor -- that is, "tor" must be in the path, OR must already be running and listening for control connections. If you're on a debian-based system "apt-get install tor" is sufficient for both of these to be satisfied.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.