A drop-in replacement for requests that routes through Tor with IP rotation
Project description
TorRotate
A drop-in replacement for the Python requests library that routes traffic through Tor with automatic IP rotation.
Features
- Seamless drop-in replacement for the requests library
- Automatic IP rotation based on request count
- Manual IP rotation available when needed
- Configure Tor directly from Python
- Cross-platform support (Linux, macOS, Windows with limitations)
Installation
pip install torrotate
Requirements
- Python 3.7+
- Tor service installed and running
- Tor control port enabled and accessible
Quick Start
import torrotate
# Configure with default settings
torrotate.configure()
# Make requests through Tor
response = torrotate.requests.get("https://api.ipify.org?format=json")
print(f"Current IP: {response.json()['ip']}")
# Force IP rotation
torrotate.force_new_ip()
# Make another request with new IP
response = torrotate.requests.get("https://api.ipify.org?format=json")
print(f"New IP: {response.json()['ip']}")
Advanced Configuration
Make sure you specify tor_control_password in your script before using torrotate.requests
import torrotate
torrotate.configure(tor_control_password="LFbEWR4Vecek9xif")
print(torrotate.requests.get("https://httpbin.org/get?word=test123").text)
torrotate.configure(
tor_control_port=9051, # Tor control port number
tor_control_password="your_password", # Password for Tor control port
proxy_host="127.0.0.1", # Tor SOCKS proxy host
proxy_port=9050, # Tor SOCKS proxy port
rotate_every=10, # Rotate IP every 10 requests
rotation_delay=3, # Wait 3 seconds after rotation
max_rotation_attempts=5, # Try up to 5 times to get a new IP
debug=True # Enable verbose output
)
Setting Up Tor
On Debian/Ubuntu:
sudo apt install tor
sudo systemctl start tor
sudo systemctl enable tor
Edit the Tor configuration file:
sudo nano /etc/tor/torrc
Add these lines:
ControlPort 9051
HashedControlPassword 16:01234567890ABCDEF...
To generate a hashed password:
tor --hash-password "your_password"
Restart Tor:
sudo systemctl restart tor
API Reference
Main Functions
configure()- Set up the TorRotate libraryrequests- Drop-in replacement for the requests libraryforce_new_ip()- Force rotation to a new IP addressget_current_ip()- Get the current external IP addressreset_rotation_counter()- Reset the request counterrotate_ip()- Rotate to a new Tor circuitconfigure_tor()- Interactive Tor configuration helper
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torrotate-0.1.0.tar.gz.
File metadata
- Download URL: torrotate-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b753622fb488f1395302136caf5345d5a038326d0a8422c4ee03f99cb34236b8
|
|
| MD5 |
1ac31ce1e3def1248999305d5e09e52b
|
|
| BLAKE2b-256 |
13dee34621b3524c9c7a49cc104a73c8b6f71b7d9e38028c7dfdd9cae17da689
|
File details
Details for the file torrotate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torrotate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3c60adc8e795f41ba6f27b597eccdead0fc417e48ed046b984f444ee720f949
|
|
| MD5 |
aa2d8eac8a9c913a030e5227ed7cc194
|
|
| BLAKE2b-256 |
e63fca6533c22ed75d2cbfc9d14f4efc1e86c715289709c043c746d36d3d856b
|