torwire 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest, windows-latest, macos-latest]
15
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Set up Python ${{ matrix.python-version }}
21
+ uses: actions/setup-python@v5
22
+ with:
23
+ python-version: ${{ matrix.python-version }}
24
+
25
+ - name: Install dependencies
26
+ run: |
27
+ python -m pip install --upgrade pip
28
+ pip install -e ".[requests]" pytest
29
+
30
+ - name: Run unit tests
31
+ run: pytest -v tests/unit
@@ -0,0 +1,49 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - name: Set up Python
15
+ uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.12"
18
+
19
+ - name: Build sdist and wheel
20
+ run: |
21
+ python -m pip install --upgrade pip
22
+ pip install build twine
23
+ python -m build
24
+ twine check dist/*
25
+
26
+ - name: Upload build artifacts
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: dist
30
+ path: dist/
31
+
32
+ publish:
33
+ needs: build
34
+ runs-on: ubuntu-latest
35
+ environment:
36
+ name: pypi
37
+ url: https://pypi.org/p/torwire
38
+ permissions:
39
+ id-token: write
40
+
41
+ steps:
42
+ - name: Download build artifacts
43
+ uses: actions/download-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist/
47
+
48
+ - name: Publish to PyPI via Trusted Publishing
49
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ htmlcov/
torwire-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 torwire contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
torwire-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,208 @@
1
+ Metadata-Version: 2.5
2
+ Name: torwire
3
+ Version: 0.1.0
4
+ Summary: Route your Python app's traffic through Tor. No proxychains, no Privoxy, no manual setup.
5
+ Project-URL: Homepage, https://github.com/TechXploreGenSec/torwire
6
+ Project-URL: Documentation, https://github.com/TechXploreGenSec/torwire#readme
7
+ Project-URL: Repository, https://github.com/TechXploreGenSec/torwire
8
+ Project-URL: Issues, https://github.com/TechXploreGenSec/torwire/issues
9
+ Author: torwire contributors
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: anonymity,ip-rotation,privacy,proxy,socks5,tor
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Internet :: Proxy Servers
24
+ Classifier: Topic :: Security
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: platformdirs>=3.0
27
+ Requires-Dist: stem>=1.8
28
+ Provides-Extra: aiohttp
29
+ Requires-Dist: aiohttp-socks>=0.9; extra == 'aiohttp'
30
+ Requires-Dist: aiohttp>=3.9; extra == 'aiohttp'
31
+ Provides-Extra: all
32
+ Requires-Dist: aiohttp-socks>=0.9; extra == 'all'
33
+ Requires-Dist: aiohttp>=3.9; extra == 'all'
34
+ Requires-Dist: httpx[socks]>=0.27; extra == 'all'
35
+ Requires-Dist: requests[socks]>=2.31; extra == 'all'
36
+ Requires-Dist: torwire-bin; extra == 'all'
37
+ Provides-Extra: bundled
38
+ Requires-Dist: torwire-bin; extra == 'bundled'
39
+ Provides-Extra: httpx
40
+ Requires-Dist: httpx[socks]>=0.27; extra == 'httpx'
41
+ Provides-Extra: requests
42
+ Requires-Dist: requests[socks]>=2.31; extra == 'requests'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # torwire
46
+
47
+ **Route your Python app's traffic through Tor — no proxychains, no Privoxy, no manual setup.**
48
+
49
+ `pip install torwire`, then three lines of code.
50
+
51
+ ---
52
+
53
+ ## Features
54
+
55
+ - **Zero manual setup** — Automatically finds, bundles (`torwire[bundled]`), or downloads and verifies the Tor binary.
56
+ - **Cross-platform** — Works identically on Windows, macOS, and Linux.
57
+ - **Dual proxy endpoints** — Exposes both `socks5h://` (remote DNS, leak-safe) and an in-process pure-Python `http://` forward proxy bridge.
58
+ - **Programmatic IP switching** — Call `tor.new_identity()` or use automatic `RotationPolicy` rules (`EveryNSeconds`, `EveryNRequests`, `OnStatus`, `OnException`).
59
+ - **Stream isolation** — Pass `isolated=True` to give parallel sessions distinct Tor circuits without hitting `NEWNYM` rate limits.
60
+ - **First-class HTTP client helpers** — Ready-made factories for `requests`, `httpx` (sync & async), `aiohttp`, and `proxy_env()` for `urllib` / subprocesses.
61
+ - **Self-healing & low-end friendly** — Built-in watchdog auto-restarts Tor if it crashes; `profile="low_end"` reduces memory and idle CPU.
62
+ - **CLI included** — `torwire start`, `torwire ip`, `torwire newnym`, `torwire download`, `torwire doctor`.
63
+
64
+ ---
65
+
66
+ ## Quick Start
67
+
68
+ ```bash
69
+ pip install "torwire[requests]"
70
+ ```
71
+
72
+ ```python
73
+ import torwire
74
+
75
+ with torwire.TorManager() as tor:
76
+ s = tor.requests_session()
77
+ print(s.get("https://api.ipify.org").text)
78
+
79
+ tor.new_identity()
80
+ print(s.get("https://api.ipify.org").text) # new exit IP
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Examples
86
+
87
+ ### Explicit Proxies (Requests / curl / HTTP Bridge)
88
+
89
+ ```python
90
+ import subprocess
91
+ import requests
92
+ import torwire
93
+
94
+ tor = torwire.TorManager(http_port=0).start()
95
+
96
+ # SOCKS5h for requests
97
+ requests.get("https://api.ipify.org", proxies=tor.proxies)
98
+
99
+ # HTTP/HTTPS bridge for tools that don't speak SOCKS5
100
+ subprocess.run(["curl", "-x", tor.http_url, "https://api.ipify.org"])
101
+
102
+ tor.stop()
103
+ ```
104
+
105
+ ### Country-Specific Exit Nodes
106
+
107
+ ```python
108
+ cfg = torwire.TorConfig(exit_countries=["{de}"], strict_exit=True)
109
+ with torwire.TorManager(cfg) as tor:
110
+ print(tor.current_ip())
111
+ ```
112
+
113
+ ### Auto-Rotation on Block or Interval
114
+
115
+ ```python
116
+ from torwire.rotation import Composite, EveryNSeconds, OnStatus
117
+
118
+ with torwire.TorManager() as tor:
119
+ tor.auto_rotate(Composite(EveryNSeconds(300), OnStatus({403, 429})))
120
+ s = tor.requests_session()
121
+ ...
122
+ ```
123
+
124
+ ### Parallel Workers with Isolated Circuits
125
+
126
+ ```python
127
+ from concurrent.futures import ThreadPoolExecutor
128
+
129
+ with torwire.TorManager() as tor:
130
+ def fetch(url):
131
+ with tor.requests_session(isolated=True) as s:
132
+ return s.get(url).text
133
+
134
+ with ThreadPoolExecutor(max_workers=8) as pool:
135
+ results = list(pool.map(fetch, urls))
136
+ ```
137
+
138
+ ### Async with `httpx`
139
+
140
+ ```python
141
+ async with torwire.TorManager() as tor:
142
+ async with tor.httpx_async_client(isolated=True) as client:
143
+ resp = await client.get("https://api.ipify.org")
144
+ print(resp.text)
145
+ ```
146
+
147
+ ### Attach to an Existing Tor / Tor Browser
148
+
149
+ ```python
150
+ tor = torwire.TorManager.attach(socks_port=9150, control_port=9151, password="")
151
+ print(tor.current_ip())
152
+ ```
153
+
154
+ ### Low-End / Always-On Devices
155
+
156
+ ```python
157
+ cfg = torwire.TorConfig(profile="low_end", persist_data=True, http_port=0)
158
+ with torwire.TorManager(cfg) as tor:
159
+ ...
160
+ ```
161
+
162
+ ---
163
+
164
+ ## CLI Usage
165
+
166
+ ```bash
167
+ torwire start --socks 9050 --http 8118 --country "{de}"
168
+ torwire ip
169
+ torwire newnym
170
+ torwire download
171
+ torwire doctor
172
+ ```
173
+
174
+ ---
175
+
176
+ ## Configuration (`TorConfig`)
177
+
178
+ | Field | Default | Description |
179
+ |---|---|---|
180
+ | `tor_path` | `None` | Explicit path to `tor` binary |
181
+ | `auto_download` | `True` | Download Tor Expert Bundle if missing |
182
+ | `socks_port` | `0` | SOCKS5 port (`0` = auto free port) |
183
+ | `control_port` | `0` | Control port (`0` = auto free port) |
184
+ | `http_port` | `None` | HTTP bridge port (`None` = disabled, `0` = auto) |
185
+ | `data_dir` | `None` | Custom data directory (`None` = ephemeral temp dir) |
186
+ | `persist_data` | `False` | Keep consensus cache for faster warm restarts |
187
+ | `exit_countries` | `None` | Preferred exit country codes |
188
+ | `strict_exit` | `False` | Enforce `StrictNodes 1` |
189
+ | `bridges` | `None` | Pluggable transport bridge lines |
190
+ | `profile` | `"default"` | `"default"` or `"low_end"` |
191
+ | `watchdog` | `True` | Auto-restart Tor if it exits unexpectedly |
192
+
193
+ ---
194
+
195
+ ## Security, Privacy & Legal Notes
196
+
197
+ - **Remote DNS (`socks5h://`)** is enforced everywhere to prevent DNS leaks.
198
+ - **No telemetry** — URLs and headers are never logged by the HTTP bridge.
199
+ - **Disclaimer**: `torwire` provides no anonymity guarantees beyond what Tor itself provides.
200
+ - **Responsible use**: Tor exit bandwidth is donated by volunteers. Respect site terms of service, local laws, and rate-limit your requests.
201
+
202
+ ---
203
+
204
+ ## Requirements & License
205
+
206
+ - Python 3.9+
207
+ - Core dependencies: `stem`, `platformdirs`
208
+ - License: [MIT](LICENSE)
@@ -0,0 +1,164 @@
1
+ # torwire
2
+
3
+ **Route your Python app's traffic through Tor — no proxychains, no Privoxy, no manual setup.**
4
+
5
+ `pip install torwire`, then three lines of code.
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - **Zero manual setup** — Automatically finds, bundles (`torwire[bundled]`), or downloads and verifies the Tor binary.
12
+ - **Cross-platform** — Works identically on Windows, macOS, and Linux.
13
+ - **Dual proxy endpoints** — Exposes both `socks5h://` (remote DNS, leak-safe) and an in-process pure-Python `http://` forward proxy bridge.
14
+ - **Programmatic IP switching** — Call `tor.new_identity()` or use automatic `RotationPolicy` rules (`EveryNSeconds`, `EveryNRequests`, `OnStatus`, `OnException`).
15
+ - **Stream isolation** — Pass `isolated=True` to give parallel sessions distinct Tor circuits without hitting `NEWNYM` rate limits.
16
+ - **First-class HTTP client helpers** — Ready-made factories for `requests`, `httpx` (sync & async), `aiohttp`, and `proxy_env()` for `urllib` / subprocesses.
17
+ - **Self-healing & low-end friendly** — Built-in watchdog auto-restarts Tor if it crashes; `profile="low_end"` reduces memory and idle CPU.
18
+ - **CLI included** — `torwire start`, `torwire ip`, `torwire newnym`, `torwire download`, `torwire doctor`.
19
+
20
+ ---
21
+
22
+ ## Quick Start
23
+
24
+ ```bash
25
+ pip install "torwire[requests]"
26
+ ```
27
+
28
+ ```python
29
+ import torwire
30
+
31
+ with torwire.TorManager() as tor:
32
+ s = tor.requests_session()
33
+ print(s.get("https://api.ipify.org").text)
34
+
35
+ tor.new_identity()
36
+ print(s.get("https://api.ipify.org").text) # new exit IP
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Examples
42
+
43
+ ### Explicit Proxies (Requests / curl / HTTP Bridge)
44
+
45
+ ```python
46
+ import subprocess
47
+ import requests
48
+ import torwire
49
+
50
+ tor = torwire.TorManager(http_port=0).start()
51
+
52
+ # SOCKS5h for requests
53
+ requests.get("https://api.ipify.org", proxies=tor.proxies)
54
+
55
+ # HTTP/HTTPS bridge for tools that don't speak SOCKS5
56
+ subprocess.run(["curl", "-x", tor.http_url, "https://api.ipify.org"])
57
+
58
+ tor.stop()
59
+ ```
60
+
61
+ ### Country-Specific Exit Nodes
62
+
63
+ ```python
64
+ cfg = torwire.TorConfig(exit_countries=["{de}"], strict_exit=True)
65
+ with torwire.TorManager(cfg) as tor:
66
+ print(tor.current_ip())
67
+ ```
68
+
69
+ ### Auto-Rotation on Block or Interval
70
+
71
+ ```python
72
+ from torwire.rotation import Composite, EveryNSeconds, OnStatus
73
+
74
+ with torwire.TorManager() as tor:
75
+ tor.auto_rotate(Composite(EveryNSeconds(300), OnStatus({403, 429})))
76
+ s = tor.requests_session()
77
+ ...
78
+ ```
79
+
80
+ ### Parallel Workers with Isolated Circuits
81
+
82
+ ```python
83
+ from concurrent.futures import ThreadPoolExecutor
84
+
85
+ with torwire.TorManager() as tor:
86
+ def fetch(url):
87
+ with tor.requests_session(isolated=True) as s:
88
+ return s.get(url).text
89
+
90
+ with ThreadPoolExecutor(max_workers=8) as pool:
91
+ results = list(pool.map(fetch, urls))
92
+ ```
93
+
94
+ ### Async with `httpx`
95
+
96
+ ```python
97
+ async with torwire.TorManager() as tor:
98
+ async with tor.httpx_async_client(isolated=True) as client:
99
+ resp = await client.get("https://api.ipify.org")
100
+ print(resp.text)
101
+ ```
102
+
103
+ ### Attach to an Existing Tor / Tor Browser
104
+
105
+ ```python
106
+ tor = torwire.TorManager.attach(socks_port=9150, control_port=9151, password="")
107
+ print(tor.current_ip())
108
+ ```
109
+
110
+ ### Low-End / Always-On Devices
111
+
112
+ ```python
113
+ cfg = torwire.TorConfig(profile="low_end", persist_data=True, http_port=0)
114
+ with torwire.TorManager(cfg) as tor:
115
+ ...
116
+ ```
117
+
118
+ ---
119
+
120
+ ## CLI Usage
121
+
122
+ ```bash
123
+ torwire start --socks 9050 --http 8118 --country "{de}"
124
+ torwire ip
125
+ torwire newnym
126
+ torwire download
127
+ torwire doctor
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Configuration (`TorConfig`)
133
+
134
+ | Field | Default | Description |
135
+ |---|---|---|
136
+ | `tor_path` | `None` | Explicit path to `tor` binary |
137
+ | `auto_download` | `True` | Download Tor Expert Bundle if missing |
138
+ | `socks_port` | `0` | SOCKS5 port (`0` = auto free port) |
139
+ | `control_port` | `0` | Control port (`0` = auto free port) |
140
+ | `http_port` | `None` | HTTP bridge port (`None` = disabled, `0` = auto) |
141
+ | `data_dir` | `None` | Custom data directory (`None` = ephemeral temp dir) |
142
+ | `persist_data` | `False` | Keep consensus cache for faster warm restarts |
143
+ | `exit_countries` | `None` | Preferred exit country codes |
144
+ | `strict_exit` | `False` | Enforce `StrictNodes 1` |
145
+ | `bridges` | `None` | Pluggable transport bridge lines |
146
+ | `profile` | `"default"` | `"default"` or `"low_end"` |
147
+ | `watchdog` | `True` | Auto-restart Tor if it exits unexpectedly |
148
+
149
+ ---
150
+
151
+ ## Security, Privacy & Legal Notes
152
+
153
+ - **Remote DNS (`socks5h://`)** is enforced everywhere to prevent DNS leaks.
154
+ - **No telemetry** — URLs and headers are never logged by the HTTP bridge.
155
+ - **Disclaimer**: `torwire` provides no anonymity guarantees beyond what Tor itself provides.
156
+ - **Responsible use**: Tor exit bandwidth is donated by volunteers. Respect site terms of service, local laws, and rate-limit your requests.
157
+
158
+ ---
159
+
160
+ ## Requirements & License
161
+
162
+ - Python 3.9+
163
+ - Core dependencies: `stem`, `platformdirs`
164
+ - License: [MIT](LICENSE)