Metadata-Version: 2.1
Name: flask-websockets
Version: 0.1.2
Summary: A WebSockets and channels implementation for Flask
Author-Email: ch-iv <alicesummer38@gmail.com>
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development
Classifier: Typing :: Typed
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Project-URL: Documentation, https://flaskwebsockets.readthedocs.io/en/latest/
Project-URL: Issue tracker, https://github.com/ch-iv/flask-websockets/issues
Project-URL: Repository, https://github.com/ch-iv/flask-websockets
Requires-Python: >=3.10
Requires-Dist: flask>=3.0.3
Requires-Dist: wsproto>=1.2.0
Requires-Dist: msgspec>=0.18.6
Description-Content-Type: text/markdown

# flask-websockets
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ch-iv/flask-websockets/ci.yml?style=flat&logo=github&label=Tests%20%26%20Linting)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ch-iv/flask-websockets/publish.yml?style=flat&logo=github&label=Latest%20Release)
[![Documentation Status](https://readthedocs.org/projects/flaskwebsockets/badge/?version=latest)](https://flaskwebsockets.readthedocs.io/en/latest/?badge=latest)
![PyPI - Downloads](https://img.shields.io/pypi/dm/flask-websockets)
[![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json&labelColor=202235)](https://github.com/astral-sh/ruff)
[![code style - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json&labelColor=202235)](https://github.com/astral-sh/ruff)

flask-websockets is an extension library for Flask, a popular web micro-framework. It adds real-time communication capabilities to your Flask application. flask-websockets implements the WebSocket protocol and allows for low-level control over the connections, as well as a high-level API for subscribing connections to rooms.

flask-websockets supports most popular HTTP WSGI servers such as Werkzeug, Gunicorn, Eventlet and Gevent.

## Example Usage
```python
import time
from threading import Thread
from flask import Flask
from flask_websockets import WebSocket, WebSockets

app = Flask(__name__)
websockets = WebSockets(app)


@websockets.route("/ws")
def websocket_route(ws: WebSocket) -> None:
    with websockets.subscribe(ws, ["server_time"]):
        for data in ws.iter_data():    # keep listening to the websocket so it doesn't disconnect
            pass


def publish_server_time() -> None:
    while True:
        websockets.publish(str(time.time()), ["server_time"])
        time.sleep(1)


Thread(target=publish_server_time).start()
app.run(host="localhost", port=6969)
```
