Registry / http-networking / python-socketio

python-socketio

JSON →
library5.16.1pypypi✓ verified 35d ago

python-socketio is a comprehensive Python implementation of the Socket.IO real-time communication protocol, offering both server and client functionalities. It enables low-latency, bidirectional, and event-based communication between clients (often web browsers) and a Python server. The library is actively maintained with frequent releases, providing compatibility with various asynchronous frameworks and web servers.

http-networkingweb-frameworkcommunication
Install & Compatibility
Where this runs
tested against v5.16.2 · 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.103.990 runs
installs and imports cleanly · install 0.0s · import 0.606s · 23.9MB
glibc
py 3.103.990 runs
installs and imports cleanly · install 2.4s · import 0.565s · 24MB
26MB installed
● package 26MB
Code
Verified usage

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

import socketio sio = socketio.Server()
import socketio sio = socketio.AsyncServer()
import socketio sio = socketio.Client()
import socketio sio = socketio.AsyncClient()
import socketio app = socketio.WSGIApp(sio)
import socketio app = socketio.ASGIApp(sio)

This quickstart demonstrates a basic Socket.IO server using `eventlet` and a simple HTML client. The server defines handlers for `connect`, `my_message`, and `disconnect` events. The client connects, sends a message, and receives a response. An `index.html` file is created on the fly for easy testing. Remember to `pip install eventlet` for this example to run.

import socketio import eventlet sio = socketio.Server(cors_allowed_origins="*") app = socketio.WSGIApp(sio, static_files={ '/': {'content_type': 'text/html', 'filename': 'index.html'} }) @sio.event def connect(sid, environ): print('connect ', sid) @sio.event def my_message(sid, data): print('message ', data) sio.emit('my response', {'data': data}, room=sid) @sio.event def disconnect(sid): print('disconnect ', sid) if __name__ == '__main__': # index.html for testing with open('index.html', 'w') as f: f.write(''' <!DOCTYPE html> <html> <head> <title>Socket.IO Test</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script> </head> <body> <h1>Socket.IO Test</h1> <script type="text/javascript"> var socket = io(); socket.on('connect', function() { console.log('Connected!'); socket.emit('my_message', 'Hello from browser!'); }); socket.on('my response', function(data) { console.log('Received:', data); }); socket.on('disconnect', function() { console.log('Disconnected!'); }); </script> </body> </html> ''') print("Starting server on http://localhost:5000") eventlet.wsgi.server(eventlet.listen(('', 5000)), app)
Debug
Known footguns
breakingProtocol compatibility is critical: python-socketio v5.x is compatible with JavaScript Socket.IO 3.x and 4.x. Mixing incompatible versions will lead to connection errors or unexpected behavior.
gotchaMissing or incorrect `cors_allowed_origins` can cause connection refusal errors for browser-based clients due to Cross-Origin Resource Sharing (CORS) policies.
gotchaUsing `Gunicorn` with multiple worker processes for `python-socketio` requires sticky sessions (load balancer must route a client to the same worker) and forcing WebSocket-only transport. Long-polling is incompatible with Gunicorn's default load balancing across workers.
deprecatedThe `eventlet` asynchronous framework, while supported, is no longer actively maintained. Using `gevent` or `asyncio` is generally recommended for new projects for better long-term support and performance.
breakingIn Socket.IO v5 protocol (python-socketio 5.x), the default namespace ('/') is not automatically connected. Each namespace connection, including the default, now has its own unique session ID (`sid`), distinct from the Engine.IO `sid`.
gotchaIf your application is configured to use `eventlet` (e.g., `import eventlet`), ensure it is explicitly installed. `python-socketio` supports multiple asynchronous backends, and specific backends like `eventlet` are not installed by default as core dependencies.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
20 hits · last 30 days
gptbot
4
claudebot
4
ahrefsbot
3
dotbot
1
bytedance
1
Resources