proxyverge-utils 1.0.0__py3-none-any.whl

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,5 @@
1
+ from .parser import ProxyConfig, parse_proxy, format_proxy, convert_batch
2
+ from .checker import check_ip
3
+
4
+ __all__ = ["ProxyConfig", "parse_proxy", "format_proxy", "convert_batch", "check_ip"]
5
+ __version__ = "1.0.0"
@@ -0,0 +1,27 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from typing import Any, Optional, Union
5
+ from urllib import request as urllib_request
6
+
7
+ from .parser import ProxyConfig, format_proxy
8
+
9
+
10
+ def check_ip(
11
+ proxy: Optional[Union[str, ProxyConfig]] = None,
12
+ endpoint: str = "https://proxyverge.com/api/ip",
13
+ timeout: float = 10.0,
14
+ ) -> dict[str, Any]:
15
+ """Fetch exit IP, ASN, geolocation, and proxy header leak signals from https://proxyverge.com/api/ip."""
16
+ handlers = []
17
+ if proxy:
18
+ proxies_dict = format_proxy(proxy, fmt="requests")
19
+ handlers.append(urllib_request.ProxyHandler(proxies_dict))
20
+ opener = urllib_request.build_opener(*handlers)
21
+ req = urllib_request.Request(endpoint, headers={"Accept": "application/json", "User-Agent": "proxyverge-utils/1.0.0"})
22
+ with opener.open(req, timeout=timeout) as resp:
23
+ data = json.loads(resp.read().decode("utf-8"))
24
+ headers_list = data.get("proxyHeaders") if isinstance(data.get("proxyHeaders"), list) else []
25
+ data["proxyHeaders"] = headers_list
26
+ data["has_proxy_headers"] = len(headers_list) > 0
27
+ return data
@@ -0,0 +1,46 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+
7
+ from .checker import check_ip
8
+ from .parser import format_proxy
9
+
10
+
11
+ def main(argv: list[str] | None = None) -> int:
12
+ parser = argparse.ArgumentParser(
13
+ prog="proxyverge-utils",
14
+ description="Convert proxy formats and check exit IP / header leaks (https://proxyverge.com/tools/proxy-converter).",
15
+ )
16
+ sub = parser.add_subparsers(dest="command")
17
+
18
+ p_conv = sub.add_parser("convert", help="Convert a proxy string to a target format")
19
+ p_conv.add_argument("proxy", help="Proxy string (e.g. host:port:user:pass)")
20
+ p_conv.add_argument(
21
+ "--format",
22
+ default="url",
23
+ choices=["url", "requests", "httpx", "playwright", "curl", "host-port-user-pass", "user-pass-host-port", "json"],
24
+ )
25
+ p_conv.add_argument("--protocol", default="http")
26
+
27
+ p_ip = sub.add_parser("check-ip", help="Check exit IP via https://proxyverge.com/api/ip")
28
+ p_ip.add_argument("--proxy", default=None, help="Optional HTTP/HTTPS proxy string")
29
+ p_ip.add_argument("--endpoint", default="https://proxyverge.com/api/ip")
30
+
31
+ args = parser.parse_args(argv)
32
+ if args.command == "convert":
33
+ out = format_proxy(args.proxy, fmt=args.format, default_protocol=args.protocol)
34
+ print(out if isinstance(out, str) else json.dumps(out, indent=2))
35
+ return 0
36
+ if args.command == "check-ip":
37
+ data = check_ip(proxy=args.proxy, endpoint=args.endpoint)
38
+ print(json.dumps(data, indent=2))
39
+ return 0
40
+
41
+ parser.print_help()
42
+ return 0
43
+
44
+
45
+ if __name__ == "__main__":
46
+ sys.exit(main())
@@ -0,0 +1,154 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, asdict
4
+ import json
5
+ import re
6
+ from typing import Any, Union
7
+ from urllib.parse import quote, unquote
8
+
9
+ SUPPORTED_PROTOCOLS = {"http", "https", "socks4", "socks5", "socks5h"}
10
+ _PROTO_RE = re.compile(r"^([a-z0-9]+)://(.+)$", re.IGNORECASE)
11
+ _HOSTPORT_RE = re.compile(r"^(\[[^\]]+\]|[^:/\s]+):(\d{1,5})$")
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class ProxyConfig:
16
+ protocol: str
17
+ host: str
18
+ port: int
19
+ username: str = ""
20
+ password: str = ""
21
+
22
+
23
+ def _normalize_protocol(protocol: str = "http") -> str:
24
+ clean = (protocol or "http").strip().lower().removesuffix("://")
25
+ if clean not in SUPPORTED_PROTOCOLS:
26
+ raise ValueError(f"Unsupported proxy protocol: {protocol}")
27
+ return clean
28
+
29
+
30
+ def _validate_port(raw_port: Union[str, int]) -> int:
31
+ try:
32
+ port = int(raw_port)
33
+ except (TypeError, ValueError) as exc:
34
+ raise ValueError(f"Invalid proxy port: {raw_port}") from exc
35
+ if port < 1 or port > 65535:
36
+ raise ValueError(f"Invalid proxy port: {raw_port}")
37
+ return port
38
+
39
+
40
+ def parse_proxy(
41
+ raw: Union[str, ProxyConfig], default_protocol: str = "http"
42
+ ) -> ProxyConfig:
43
+ """Parse a proxy string in host:port, host:port:user:pass, user:pass@host:port, or URL format."""
44
+ if isinstance(raw, ProxyConfig):
45
+ return ProxyConfig(
46
+ protocol=_normalize_protocol(raw.protocol or default_protocol),
47
+ host=raw.host.strip(),
48
+ port=_validate_port(raw.port),
49
+ username=raw.username or "",
50
+ password=raw.password or "",
51
+ )
52
+
53
+ text = (raw or "").strip()
54
+ if not text:
55
+ raise ValueError("Proxy string cannot be empty")
56
+
57
+ proto_match = _PROTO_RE.match(text)
58
+ protocol = _normalize_protocol(proto_match.group(1) if proto_match else default_protocol)
59
+ body = (proto_match.group(2) if proto_match else text).rstrip("/")
60
+
61
+ # Format: user:pass@host:port (only when RHS after last '@' is a valid host:port)
62
+ at_idx = body.rfind("@")
63
+ if at_idx != -1:
64
+ auth_part = body[:at_idx]
65
+ host_port_part = body[at_idx + 1 :]
66
+ hp_match = _HOSTPORT_RE.match(host_port_part)
67
+ if hp_match:
68
+ if ":" in auth_part:
69
+ u_raw, p_raw = auth_part.split(":", 1)
70
+ username, password = unquote(u_raw), unquote(p_raw)
71
+ else:
72
+ username, password = unquote(auth_part), ""
73
+ host = hp_match.group(1).strip("[]").strip()
74
+ port = _validate_port(hp_match.group(2))
75
+ if host:
76
+ return ProxyConfig(protocol=protocol, host=host, port=port, username=username, password=password)
77
+
78
+ # Format: host:port or host:port:user:pass (passwords may contain ':')
79
+ parts = body.split(":")
80
+ if len(parts) == 2:
81
+ host = parts[0].strip()
82
+ port = _validate_port(parts[1])
83
+ if not host:
84
+ raise ValueError(f"Missing host in proxy: {text}")
85
+ return ProxyConfig(protocol=protocol, host=host, port=port)
86
+
87
+ if len(parts) >= 4:
88
+ host = parts[0].strip()
89
+ port = _validate_port(parts[1])
90
+ username = parts[2]
91
+ password = ":".join(parts[3:])
92
+ if not host:
93
+ raise ValueError(f"Missing host in proxy: {text}")
94
+ return ProxyConfig(protocol=protocol, host=host, port=port, username=username, password=password)
95
+
96
+ raise ValueError(f"Unrecognized proxy format: {text}")
97
+
98
+
99
+ def format_proxy(
100
+ proxy: Union[str, ProxyConfig],
101
+ fmt: str = "url",
102
+ default_protocol: str = "http",
103
+ ) -> Any:
104
+ """Convert a proxy string or ProxyConfig into url, requests, httpx, playwright, curl, json, etc."""
105
+ p = parse_proxy(proxy, default_protocol=default_protocol)
106
+ host_display = f"[{p.host}]" if ":" in p.host else p.host
107
+ if p.username or p.password:
108
+ auth = f"{quote(p.username, safe='')}:{quote(p.password, safe='')}@"
109
+ else:
110
+ auth = ""
111
+ url = f"{p.protocol}://{auth}{host_display}:{p.port}"
112
+
113
+ kind = (fmt or "url").strip().lower()
114
+ if kind in ("url", "httpx"):
115
+ return url
116
+ if kind == "requests":
117
+ return {"http": url, "https": url}
118
+ if kind == "host-port-user-pass":
119
+ if p.username or p.password:
120
+ return f"{p.host}:{p.port}:{p.username}:{p.password}"
121
+ return f"{p.host}:{p.port}"
122
+ if kind == "user-pass-host-port":
123
+ if p.username or p.password:
124
+ return f"{p.username}:{p.password}@{host_display}:{p.port}"
125
+ return f"{host_display}:{p.port}"
126
+ if kind == "playwright":
127
+ server_proto = "socks5" if p.protocol == "socks5h" else p.protocol
128
+ cfg = {"server": f"{server_proto}://{host_display}:{p.port}"}
129
+ if p.username:
130
+ cfg["username"] = p.username
131
+ if p.password:
132
+ cfg["password"] = p.password
133
+ return cfg
134
+ if kind == "curl":
135
+ if p.protocol in ("socks5", "socks5h"):
136
+ auth_flag = f' -U "{p.username}:{p.password}"' if (p.username or p.password) else ""
137
+ return f'curl -s --socks5-hostname "{host_display}:{p.port}"{auth_flag} https://proxyverge.com/api/ip'
138
+ return f'curl -s -x "{url}" https://proxyverge.com/api/ip'
139
+ if kind == "json":
140
+ return json.dumps(asdict(p))
141
+ raise ValueError(f"Unsupported output format: {fmt}")
142
+
143
+
144
+ def convert_batch(
145
+ text: str, fmt: str = "url", default_protocol: str = "http"
146
+ ) -> list[Any]:
147
+ """Convert a newline-delimited list of proxy strings, ignoring blank lines and '#' comments."""
148
+ results: list[Any] = []
149
+ for raw_line in (text or "").splitlines():
150
+ line = raw_line.strip()
151
+ if not line or line.startswith("#"):
152
+ continue
153
+ results.append(format_proxy(line, fmt=fmt, default_protocol=default_protocol))
154
+ return results
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: proxyverge-utils
3
+ Version: 1.0.0
4
+ Summary: Zero-dependency proxy string parser, format converter (requests, httpx, Playwright, cURL), and exit IP/header leak checker.
5
+ Author-email: ProxyVerge <support@proxyverge.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://proxyverge.com/tools/proxy-converter
8
+ Project-URL: Documentation, https://proxyverge.com/tools/my-ip
9
+ Project-URL: API, https://proxyverge.com/api/ip
10
+ Keywords: proxy,proxy-parser,proxy-converter,web-scraping,playwright,httpx,ip-checker,socks5
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Internet :: WWW/HTTP
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: license-file
25
+
26
+ # proxyverge-utils
27
+
28
+ Zero-dependency Python library & CLI for parsing proxy strings, converting formats (`requests`, `httpx`, `Playwright`, `cURL`, `url`), and checking exit IP / proxy header leaks.
29
+
30
+ - Browser-based bulk converter (100% client-side): https://proxyverge.com/tools/proxy-converter
31
+ - Browser IP, WebRTC & DNS leak checker: https://proxyverge.com/tools/my-ip
32
+ - Lightweight JSON exit IP endpoint: https://proxyverge.com/api/ip
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install proxyverge-utils
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ```python
43
+ from proxyverge_utils import parse_proxy, format_proxy, convert_batch, check_ip
44
+
45
+ # Parse colon-delimited strings (including passwords with special characters)
46
+ cfg = parse_proxy("198.51.100.10:8080:alice:p@ss:w/rd#1")
47
+
48
+ # Percent-encoded URL for httpx
49
+ httpx_url = format_proxy(cfg, "httpx")
50
+ # 'http://alice:p%40ss%3Aw%2Frd%231@198.51.100.10:8080'
51
+
52
+ # Dict ready for requests.get(..., proxies=...)
53
+ req_proxies = format_proxy("198.51.100.10:8080:alice:secret", "requests")
54
+
55
+ # Playwright proxy dict
56
+ pw_proxy = format_proxy("198.51.100.10:8080:alice:secret", "playwright")
57
+ # {'server': 'http://198.51.100.10:8080', 'username': 'alice', 'password': 'secret'}
58
+
59
+ # DNS-leak-safe cURL command for SOCKS5 (--socks5-hostname)
60
+ curl_cmd = format_proxy("198.51.100.10:1080:alice:secret", "curl", default_protocol="socks5")
61
+
62
+ # Batch conversion (skips empty lines and # comments)
63
+ urls = convert_batch("""
64
+ # Pool
65
+ 198.51.100.10:8080:u1:p1
66
+ u2:p2@198.51.100.11:9000
67
+ """, fmt="url")
68
+
69
+ # Check exit IP, ASN, country, and leaked proxy headers
70
+ info = check_ip()
71
+ print(info["ip"], info["country"], info["asn"], info["has_proxy_headers"])
72
+ ```
73
+
74
+ ## CLI Usage
75
+
76
+ ```bash
77
+ proxyverge-utils convert "198.51.100.10:8080:user:p@ss" --format playwright
78
+ proxyverge-utils convert "198.51.100.10:1080:user:pass" --protocol socks5 --format curl
79
+ proxyverge-utils check-ip
80
+ ```
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,10 @@
1
+ proxyverge_utils/__init__.py,sha256=6jV6x-uP9oApRL0hiJJobA7EX-lMInatGfECZD3k3JE,213
2
+ proxyverge_utils/checker.py,sha256=gyXPFHJPEwe85CIh_d5LHfGFXYYlopqh3bUWoAZsQto,1107
3
+ proxyverge_utils/cli.py,sha256=3qq7UNRbhk0xW9qUQ0ytM9mTEtZgOgB0MXLXfMEVcnQ,1618
4
+ proxyverge_utils/parser.py,sha256=cuOcDlM7DvFaLd30Ewba-5XThOmzWdFSR85F01PW6FY,5784
5
+ proxyverge_utils-1.0.0.dist-info/licenses/LICENSE,sha256=GWepQKmRLDAPqDtKKmHstV9lPn6kLOZ54o_WyLTLZOU,1067
6
+ proxyverge_utils-1.0.0.dist-info/METADATA,sha256=6_IhG5L_WABXrAXx9croOUT3ZNf2elowF-Dq5pVcbwo,3103
7
+ proxyverge_utils-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ proxyverge_utils-1.0.0.dist-info/entry_points.txt,sha256=ZBLMQn9X_GGEh3V5i0lBgNRSSc5QvQpLOaE3sXrsObc,63
9
+ proxyverge_utils-1.0.0.dist-info/top_level.txt,sha256=LqFope-5jpxpfsQ9BOJan_J8YvxhjdjJHOJzbfJ_lKA,17
10
+ proxyverge_utils-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ proxyverge-utils = proxyverge_utils.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ProxyVerge
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.
@@ -0,0 +1 @@
1
+ proxyverge_utils