Skip to main content

SOCKS5 proxy session with kill switch — if the proxy drops, your real IP is never exposed.

Project description

socks5-killswitch

Your IP never leaks. Period.

PyPI Python License CI Coverage Typed Code style: ruff


SOCKS5 proxy session for Python built on requests.Session.
If the proxy drops — all requests are instantly killed. No fallback. No leaks.

The Problem

Standard requests + SOCKS5 proxy setup has a fatal flaw: if the proxy goes down, requests silently fall back to your real IP. You're exposed and don't even know it.

The Solution

              Request ──► Proxy OK? ──► Yes ──► Send through proxy
                              │
                              No
                              │
                         KILL SWITCH ON
                              │
                    ┌─────────┴─────────┐
                    │  All requests      │
                    │  blocked forever   │
                    │  ProxyError raised │
                    └───────────────────┘

Install

pip install socks5-killswitch

Quick Start

from socks5_killswitch import create_session, ProxyError

# Create a protected session — real IP is detected and verified automatically
session = create_session(
    host="proxy.example.com",
    port=1080,
    username="your-socks5-user",
    password="your-socks5-pass",
)

# All requests go through the proxy — just like normal requests.Session
resp = session.get("https://example.com")

# Periodic leak check — verifies visible IP != real IP
session.check_ip()

# If proxy ever fails:
# ❌ ProxyError raised
# ❌ ALL further requests blocked
# ❌ No fallback to direct connection
# ✅ Your real IP stays hidden

How It Works

Event What happens
create_session() Detects real IP via ipify.org, connects through proxy, verifies proxy IP is different
Successful request Passes through proxy as normal
Any request failure Kill switch activates — _killed = True, ProxyError raised
Subsequent requests Instantly raise ProxyError — zero network calls
check_ip() Verifies visible IP != real IP (works even after kill switch!)

API

create_session(host, port, username, password, **kwargs)

Factory that returns a verified SafeSession.

Parameter Type Default Description
host str SOCKS5 proxy host
port int SOCKS5 proxy port
username str SOCKS5 username
password str SOCKS5 password
timeout int 15 Default request timeout (seconds)
ip_check_url str https://api.ipify.org IP detection service URL

SafeSession

Extends requests.Session with kill switch protection.

session.get(url)              # proxied request, kills on failure
session.post(url, data=b"…")  # binary data works (AMF2, protobuf, etc.)
session.check_ip()            # returns proxy IP or raises ProxyError
repr(session)                 # <SafeSession proxy=socks5://user:***@host:1080 killed=False>

ProxyError

Raised when proxy fails or IP leak is detected. Original exception is chained via __cause__.

Design Decisions

  • socks5:// not socks5h:// — DNS is resolved locally (required for PIA and similar providers)
  • Pure library — no .env, no config files, no side effects. All parameters passed explicitly
  • check_ip() bypasses kill switch — intentional; leak detection must work even in degraded state
  • Password masked in repr()socks5://user:***@host:1080, safe for logging

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

socks5_killswitch-0.0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

socks5_killswitch-0.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file socks5_killswitch-0.0.2.tar.gz.

File metadata

  • Download URL: socks5_killswitch-0.0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for socks5_killswitch-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8755bdd23dfeb4dd3caed4d6ef14d89f3fa353b2828e1dfae438ac9d114e4622
MD5 79103e588eec4b8ca3a070023d9560c2
BLAKE2b-256 64801f80c41475d0305211989228ef7e99e9538fba335f14e73020bff3690011

See more details on using hashes here.

Provenance

The following attestation bundles were made for socks5_killswitch-0.0.2.tar.gz:

Publisher: publish.yml on ponich/socks5-killswitch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file socks5_killswitch-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for socks5_killswitch-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a286f1e989cef3ca2b544a0f7418cde8094d3dfef6e0fa1021653dd940f356cb
MD5 d20ea78a299c6ba4bb54905587f02cf4
BLAKE2b-256 d3d5e475bb69b735c8445f7ccbce299150fe6c99f452c8c1d8281f1266196197

See more details on using hashes here.

Provenance

The following attestation bundles were made for socks5_killswitch-0.0.2-py3-none-any.whl:

Publisher: publish.yml on ponich/socks5-killswitch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page