# ExtProxy
[![license](https://img.shields.io/github/license/SeaHOH/extproxy)](https://github.com/SeaHOH/extproxy/blob/master/LICENSE)
[![release status](https://img.shields.io/github/v/release/SeaHOH/extproxy?include_prereleases&sort=semver)](https://github.com/SeaHOH/extproxy/releases)
[![code size](https://img.shields.io/github/languages/code-size/SeaHOH/extproxy)](https://github.com/SeaHOH/extproxy)
ExtProxy extend urllib2's ProxyHandler to support extra proxy types: HTTPS, SOCKS. It provides a consistent user experience like HTTP proxy for the users.
This script is using a non-side-effects monkey patch, it did not applied to build-in module socket, just inject some codes into `Request`, `ProxyHandler`, `HTTPConnection`, `SSLContext` method's processing. Don't need to worry about the patching, you can using everything like before, or you can unpatch it at any time.
# Installation
Install from
[![version](https://img.shields.io/pypi/v/ExtProxy)](https://pypi.org/project/ExtProxy/)
[![package format](https://img.shields.io/pypi/format/ExtProxy)](https://pypi.org/project/ExtProxy/#files)
[![monthly downloads](https://img.shields.io/pypi/dm/ExtProxy)](https://pypi.org/project/ExtProxy/#files)
pip install ExtProxy
Or download and Install from source code
python setup.py install
# Compatibility
- Python >= 2.7
- Require PySocks to support SOCKS proxy type
# Usage
```py
# Target can be imported before monkey patching
from urllib.request import urlopen, build_opener, ProxyHandler
# Import extproxy, auto apply monkey patching by `extproxy.patch_items`
import extproxy
# Use origin HTTP proxy
proxy = "http://127.0.0.1:8080"
# Use HTTPS proxy, use `set_https_proxy` to custom proxy's SSL verify mode
import ssl
proxy = "https://127.0.0.1:8443"
cafile = "cafile path"
set_https_proxy(proxy, check_hostname=False, cafile=cafile)
context_settings = {
"protocol": ssl.PROTOCOL_TLSv1_2,
"cert_reqs": ssl.CERT_REQUIRED, #
"check_hostname": True, #
"cafile": "cafile path", #
"capath": "cafiles dir path", #
"cadata": b"ca data" # Uesd to server auth
"certfile": "certfile path", #
"keyfile": "keyfile path", # Uesd to client auth
}
context = ssl._create_unverified_context(**context_settings)
... # More custom settings
set_https_proxy(proxy, context=context)
# Use SOCKS proxy, `socks` can be: socks, socks4, socks4a, socks5, socks5h
# SOCKS4 does not support remote resolving, but SOCKS4a/5 supported
# 'socks' means SOCKS5, 'socks5h' means do not use remote resolving
proxy = "socks://127.0.0.1:1080"
# Set proxy via system/python environment variables
import os
os.environ["HTTP_PROXY"] = proxy
os.environ["HTTPS_PROXY"] = proxy
print(urlopen("https://httpbin.org/ip").read().decode())
# Set proxy via ProxyHandler
opener = build_opener(ProxyHandler({
"http": proxy,
"https": proxy
}))
print(opener.open("https://httpbin.org/ip").read().decode())
# Restore monkey patch, then HTTPS, SOCKS proxy use can not continue working
extproxy.restore_items()
```
# License
ExtProxy is released under the [MIT License](https://github.com/SeaHOH/extproxy/blob/master/LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/SeaHOH/extproxy",
"name": "ExtProxy",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7",
"maintainer_email": "",
"keywords": "urllib ProxyHandler HTTPS SOCKS proxy",
"author": "SeaHOH",
"author_email": "seahoh@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/16/ef/3b89fd42631e55c7ff6c0c13f287164f8e603454ce9b77a12df42c7e79fc/ExtProxy-1.0.3.tar.gz",
"platform": "any",
"description": "# ExtProxy\r\n[![license](https://img.shields.io/github/license/SeaHOH/extproxy)](https://github.com/SeaHOH/extproxy/blob/master/LICENSE)\r\n[![release status](https://img.shields.io/github/v/release/SeaHOH/extproxy?include_prereleases&sort=semver)](https://github.com/SeaHOH/extproxy/releases)\r\n[![code size](https://img.shields.io/github/languages/code-size/SeaHOH/extproxy)](https://github.com/SeaHOH/extproxy)\r\n\r\nExtProxy extend urllib2's ProxyHandler to support extra proxy types: HTTPS, SOCKS. It provides a consistent user experience like HTTP proxy for the users.\r\n\r\nThis script is using a non-side-effects monkey patch, it did not applied to build-in module socket, just inject some codes into `Request`, `ProxyHandler`, `HTTPConnection`, `SSLContext` method's processing. Don't need to worry about the patching, you can using everything like before, or you can unpatch it at any time.\r\n\r\n# Installation\r\nInstall from \r\n[![version](https://img.shields.io/pypi/v/ExtProxy)](https://pypi.org/project/ExtProxy/)\r\n[![package format](https://img.shields.io/pypi/format/ExtProxy)](https://pypi.org/project/ExtProxy/#files)\r\n[![monthly downloads](https://img.shields.io/pypi/dm/ExtProxy)](https://pypi.org/project/ExtProxy/#files)\r\n\r\n pip install ExtProxy\r\n\r\nOr download and Install from source code\r\n\r\n python setup.py install\r\n\r\n# Compatibility \r\n- Python >= 2.7\r\n- Require PySocks to support SOCKS proxy type\r\n\r\n# Usage\r\n```py\r\n# Target can be imported before monkey patching\r\nfrom urllib.request import urlopen, build_opener, ProxyHandler\r\n\r\n\r\n# Import extproxy, auto apply monkey patching by `extproxy.patch_items`\r\nimport extproxy\r\n\r\n\r\n# Use origin HTTP proxy\r\nproxy = \"http://127.0.0.1:8080\"\r\n\r\n\r\n# Use HTTPS proxy, use `set_https_proxy` to custom proxy's SSL verify mode\r\nimport ssl\r\nproxy = \"https://127.0.0.1:8443\"\r\n\r\ncafile = \"cafile path\"\r\nset_https_proxy(proxy, check_hostname=False, cafile=cafile)\r\n\r\ncontext_settings = {\r\n \"protocol\": ssl.PROTOCOL_TLSv1_2,\r\n \"cert_reqs\": ssl.CERT_REQUIRED, #\r\n \"check_hostname\": True, #\r\n \"cafile\": \"cafile path\", #\r\n \"capath\": \"cafiles dir path\", #\r\n \"cadata\": b\"ca data\" # Uesd to server auth\r\n \"certfile\": \"certfile path\", #\r\n \"keyfile\": \"keyfile path\", # Uesd to client auth\r\n}\r\ncontext = ssl._create_unverified_context(**context_settings)\r\n ... # More custom settings\r\nset_https_proxy(proxy, context=context)\r\n\r\n\r\n# Use SOCKS proxy, `socks` can be: socks, socks4, socks4a, socks5, socks5h\r\n# SOCKS4 does not support remote resolving, but SOCKS4a/5 supported\r\n# 'socks' means SOCKS5, 'socks5h' means do not use remote resolving\r\nproxy = \"socks://127.0.0.1:1080\"\r\n\r\n\r\n# Set proxy via system/python environment variables\r\nimport os\r\nos.environ[\"HTTP_PROXY\"] = proxy\r\nos.environ[\"HTTPS_PROXY\"] = proxy\r\nprint(urlopen(\"https://httpbin.org/ip\").read().decode())\r\n\r\n\r\n# Set proxy via ProxyHandler\r\nopener = build_opener(ProxyHandler({\r\n \"http\": proxy,\r\n \"https\": proxy\r\n}))\r\nprint(opener.open(\"https://httpbin.org/ip\").read().decode())\r\n\r\n\r\n# Restore monkey patch, then HTTPS, SOCKS proxy use can not continue working\r\nextproxy.restore_items()\r\n```\r\n\r\n# License\r\nExtProxy is released under the [MIT License](https://github.com/SeaHOH/extproxy/blob/master/LICENSE).\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "ExtProxy extend urllib2's ProxyHandler to support extra proxy types: HTTPS, SOCKS.",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/SeaHOH/extproxy"
},
"split_keywords": [
"urllib",
"proxyhandler",
"https",
"socks",
"proxy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e253d00f81b697d1f496b83b5c801dee4673ba485c34dc894124380cfb43fbf3",
"md5": "a4ab1bccc525bf056e7583be3a9f50e1",
"sha256": "dbe32731cf03392dac1d911386b433c65e280b6bb6c3109d6ca696b1f3414fb7"
},
"downloads": -1,
"filename": "ExtProxy-1.0.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "a4ab1bccc525bf056e7583be3a9f50e1",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=2.7",
"size": 11971,
"upload_time": "2023-08-23T08:04:17",
"upload_time_iso_8601": "2023-08-23T08:04:17.008064Z",
"url": "https://files.pythonhosted.org/packages/e2/53/d00f81b697d1f496b83b5c801dee4673ba485c34dc894124380cfb43fbf3/ExtProxy-1.0.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "16ef3b89fd42631e55c7ff6c0c13f287164f8e603454ce9b77a12df42c7e79fc",
"md5": "524cd278f137318335a75a4927425896",
"sha256": "4501949cb4885801bac5ae635231df0f67bfe17661a5202d6989bc25d2f124a0"
},
"downloads": -1,
"filename": "ExtProxy-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "524cd278f137318335a75a4927425896",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7",
"size": 9824,
"upload_time": "2023-08-23T08:04:18",
"upload_time_iso_8601": "2023-08-23T08:04:18.447785Z",
"url": "https://files.pythonhosted.org/packages/16/ef/3b89fd42631e55c7ff6c0c13f287164f8e603454ce9b77a12df42c7e79fc/ExtProxy-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-23 08:04:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SeaHOH",
"github_project": "extproxy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "extproxy"
}