Registry / http-networking / socksio

socksio

JSON →
library1.0.0pypypi✓ verified 29d ago

socksio is a sans-I/O implementation of the SOCKS4, SOCKS4A, and SOCKS5 proxy protocols. It provides the state machines necessary for handling SOCKS proxy negotiation without performing any network I/O itself, making it ideal for integration into asynchronous network frameworks. Currently at version 1.0.0, it follows a stable release cadence with releases primarily for bug fixes or minor enhancements.

pip install socksio
INSTALL
IMPORT
SIG · SOCKSIO
S
socksio
http-networkingpythonv1.0.0
Install
1.5s avg
Import
32ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.034s · 17.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.030s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SOCKS5Connection
✓ from socksio import SOCKS5Connection
✗ from socksio import Socks5Connection

This quickstart demonstrates the core functionality of `socksio` by simulating a SOCKS5 proxy handshake. It shows how to initialize a connection, send client data, receive simulated server responses, and observe the state transitions. Remember that `socksio` handles only the protocol state machine, not actual network I/O.

from socksio import Socks5Connection, Socks5AuthMethods, SOCKS5_NO_AUTH, ConnectionState # This example demonstrates the SOCKS5 state machine, it does not perform actual network I/O. # In a real application, 'client_greeting_data' would be written to a socket, # and 'server_greeting_response' would be read from that socket. # 1. Initialize a SOCKS5 connection to a target host and port. target_host = "example.com" target_port = 80 conn = Socks5Connection(target_host, target_port) print(f"Initial state: {conn.state}") # Expected: ConnectionState.INIT # 2. Client sends greeting with supported authentication methods. # For SOCKS5, common is NO_AUTH. client_greeting_data = conn.send(Socks5AuthMethods([SOCKS5_NO_AUTH])) print(f"\nClient sends greeting ({len(client_greeting_data)} bytes): {client_greeting_data.hex()}") print(f"State after sending greeting: {conn.state}") # Expected: ConnectionState.WAITING_FOR_AUTH_METHOD_SELECTION # 3. Simulate server response to greeting. # A SOCKS5 server typically responds with version (0x05) and selected method (0x00 for NO_AUTH). server_greeting_response = b'\x05\x00' conn.receive(server_greeting_response) print(f"\nServer responds to greeting ({len(server_greeting_response)} bytes): {server_greeting_response.hex()}") print(f"State after receiving greeting response: {conn.state}") # Expected: ConnectionState.AUTH_SUCCESS # 4. Client sends connection request. # The `send()` method generates the connect request based on target_host/port. client_connect_data = conn.send() print(f"\nClient sends connect request ({len(client_connect_data)} bytes): {client_connect_data.hex()}") print(f"State after sending connect request: {conn.state}") # Expected: ConnectionState.WAITING_FOR_CONNECT_REPLY # 5. Simulate server response to connection request. # A successful SOCKS5 connect reply for IPv4 would be: # 0x05 (version) 0x00 (success) 0x00 (reserved) 0x01 (IPv4 address type) # followed by bound address (4 bytes, e.g., 127.0.0.1) and bound port (2 bytes, e.g., 80) server_connect_response = b'\x05\x00\x00\x01\x7f\x00\x00\x01\x00\x50' # 127.0.0.1:80 conn.receive(server_connect_response) print(f"\nServer responds to connect request ({len(server_connect_response)} bytes): {server_connect_response.hex()}") print(f"Final state: {conn.state}") # Expected: ConnectionState.OPEN if conn.is_connected: print("\nSOCKS5 handshake successfully completed (simulated).") print(f"Bound address: {conn.bound_address}, Bound port: {conn.bound_port}") else: print("\nSOCKS5 handshake failed (simulated).")
Debug
Known issues
gotchasocksio explicitly does not perform any network I/O. Users must integrate `socksio`'s `send()` and `receive()` methods with their own socket or network transport layer (e.g., `asyncio`, `trio`, `socket`). This is a common source of confusion if expecting a full client.
fix
Implement custom I/O logic using standard library `socket` or an asynchronous framework like `asyncio` to read from and write to the network based on `socksio`'s output and input.
affects: >=1.0.0
gotchaThe library's scope is limited to the SOCKS proxy negotiation handshake. Once the `ConnectionState.OPEN` state is reached, `socksio` is no longer involved, and subsequent application data must be handled directly by the user's code via the established connection.
fix
After the SOCKS handshake, transition your I/O loop to send and receive application-specific data directly over the underlying network connection, bypassing `socksio`.
affects: >=1.0.0
gotchaProtocol violations or unexpected server responses will raise exceptions (e.g., `BadSocksConnectionState`, `MalformedSocks5Reply`). Robust applications must catch and handle these errors to manage connection failures gracefully.
fix
Wrap calls to `conn.receive()` and `conn.send()` in `try...except` blocks to catch specific `socksio` exceptions and handle them appropriately, such as logging the error and closing the connection.
affects: >=1.0.0
Upgrade
Version history
1.0.0latest on PyPI · released Apr 17, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
socksio — pip install socksio · libregistry