Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erdiaker/torrequest
Simple Python interface for HTTP(s) requests over Tor
https://github.com/erdiaker/torrequest
python requests tor
Last synced: about 2 months ago
JSON representation
Simple Python interface for HTTP(s) requests over Tor
- Host: GitHub
- URL: https://github.com/erdiaker/torrequest
- Owner: erdiaker
- Created: 2016-08-17T13:54:01.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-05T01:14:40.000Z (about 1 year ago)
- Last Synced: 2024-08-08T02:43:05.399Z (about 2 months ago)
- Topics: python, requests, tor
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 233
- Watchers: 14
- Forks: 43
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
TorRequest
==========A simple Python interface for HTTP(s) requests over
[Tor](https://www.torproject.org).
```python
from torrequest import TorRequestwith TorRequest() as tr:
response = tr.get('http://ipecho.net/plain')
print(response.text) # not your IP address
```It's basically a wrapper around [Stem](https://stem.torproject.org) and
[Requests](http://docs.python-requests.org/en/master/) libraries.## Dependencies
You need Tor. It's available via Homebrew.
```sh
brew install tor
```After installation, you may want to configure Tor by creating a `.torrc` file in your `$HOME` directory. More information is available on [Tor
documentation](https://www.torproject.org/docs/tor-manual.html.en).## Installation
After installing dependencies, you can install `torrequest` via PyPI:
```sh
pip install torrequest
```## Examples
```python
from torrequest import TorRequest# Choose a proxy port, a control port, and a password.
# Defaults are 9050, 9051, and None respectively.
# If there is already a Tor process listening the specified
# ports, TorRequest will use that one.
# Otherwise, it will create a new Tor process,
# and terminate it at the end.
with TorRequest(proxy_port=9050, ctrl_port=9051, password=None) as tr:# Specify HTTP verb and url.
resp = tr.get('http://google.com')
print(resp.text)# Send data. Use basic authentication.
resp = tr.post('https://api.example.com',
data={'foo': 'bar'}, auth=('user', 'pass'))'
print(resp.json)# Change your Tor circuit,
# and likely your observed IP address.
tr.reset_identity()# TorRequest object also exposes the underlying Stem controller
# and Requests session objects for more flexibility.print(type(tr.ctrl)) # a stem.control.Controller object
tr.ctrl.signal('CLEARDNSCACHE') # see Stem docs for the full APIprint(type(tr.session)) # a requests.Session object
c = cookielib.CookieJar()
tr.session.cookies.update(c) # see Requests docs for the full API
```## License
MIT