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.
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
muslpy 3.10–3.990 runs
installs and imports cleanly · install 0.0s · import 0.606s · 23.9MB
glibcpy 3.10–3.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)
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.