flask-sock

WebSocket route support for Flask, with no greenlet-based server required.

Library
PyPI
v0.7.0
317stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
43/100Fair
Development Activity16
Maintenance20
Community56
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture72
Code Quality76
Innovation58
Learning Curve82

flask-sock adds WebSocket route handling to Flask applications through a simple @sock.route() decorator, similar to Flask’s regular @app.route(). Unlike many Flask WebSocket extensions, it does not require a greenlet-based server such as gevent or eventlet — it works directly with Flask’s development server.

For production, it can still run under Gunicorn, Eventlet, or Gevent, giving developers a choice of deployment without changing application code. It’s built by Miguel Grinberg, author of the Flask Mega-Tutorial, and reuses his lower-level simple-websocket library for the actual protocol handling.

What You Get

  • A Sock extension object with a @sock.route() decorator for defining WebSocket endpoints
  • Compatibility with Flask’s built-in development server (no greenlet server required for local dev)
  • Production support under Gunicorn, Eventlet, or Gevent workers
  • Blueprint support for organizing WebSocket routes alongside regular HTTP routes
  • Built on simple-websocket for the underlying WebSocket protocol implementation

Common Use Cases

  • Adding a live chat or notification channel to an existing Flask application
  • Streaming real-time data (logs, metrics, sensor readings) to a browser client from Flask
  • Building collaborative or live-updating features without introducing a separate WebSocket server
  • Prototyping WebSocket endpoints locally with Flask’s dev server before choosing a production deployment model

Under The Hood

Architecture: the entire extension lives in a single module, src/flask_sock/__init__.py (~100 lines) — a Sock class that registers a WSGI-level hook to intercept WebSocket upgrade requests before they reach Flask’s normal routing, then hands the raw socket to simple-websocket (a separate, lower-level library by the same author) to manage the protocol handshake and framing. Tech Stack: pure Python, depends on Flask and simple-websocket; ships examples for running under eventlet and gevent for production deployments. Code Quality: the project has a dedicated tests/test_flask_sock.py suite plus CI (GitHub Actions) and Codecov integration, and the docs (docs/) are built with Sphinx and hosted on Read the Docs. API Design: the @sock.route() decorator intentionally mirrors Flask’s @app.route() pattern, minimizing the conceptual overhead for developers already familiar with Flask routing, and it composes with Blueprints for larger applications.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search