When one wants to write an application that uses some of the features of Tor in a secure manner it would be helpful if there was a library to do so.

I wonder if there is a library that provides features like the ones the Tor Browser Bundle implements, such as:

  • Only connect through Tor (no way of connecting through other means and thereby leaking data)
  • Using Unix Sockets instead of TCP for added security
  • Providing an interface to Tor's feature to create individual circuits on demand (like Tor Browsers does with tabs)

Maybe some more things, especially in regards to Hidden Services (like setting them up) or the Control Port (directly accessing its functionality). I know there is Stem, but it is written in Python and I think a C library would allow more users to actually make use of it, be it via language bindings or directly.

2 Answers 2


A bit of Googling has thrown up libtor, which might be worth a look. (It appears not to have been touched for several years though... )

Another option would be to use Stem, but embed it in your C code using Python's C interface. Either that, or use something like Pyrex or Cython to somehow integrate the two. (I haven't tried this myself, so can't provide any examples, I'm afraid.)

For libraries written in other languages - though not, it appears, C - have a look at this entry on Stem's FAQ.

  • I only saw libtor. The Stem FAQ is really interesting. Should have seen that earlier. Thank you!
    – meee
    Commented Aug 29, 2015 at 21:47

You can try Torpy pure python tor protocol implementation or if you prefer C implementation try mini-tor

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .