flask-uwsgi-ws


Nameflask-uwsgi-ws JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryFlask WebSocket extension for uWSGI
upload_time2024-12-01 16:15:45
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords flask uwsgi websocket websockets ws async
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Flask-uWSGI-WS

A high-performance WebSocket extension for Flask applications powered by uWSGI.
Compatible with Python 3.12 and newer versions.

## Example Usage

```python
from flask import Flask
from flask_uwsgi_ws import WebSocket

app = Flask(__name__)
ws = WebSocket(app)

@ws.route('/echo')
def echo(ws):
    while True:
        msg = ws.receive()
        ws.send(msg)

if __name__ == '__main__':
    app.run(debug=True, threads=16)
```

## Installation

To install Flask-uWSGI-WS, you'll need to install uWSGI with SSL support first:

### For Ubuntu/Debian:
```bash
CFLAGS="-I/usr/include/openssl" LDFLAGS="-L/usr/lib/x86_64-linux-gnu" UWSGI_PROFILE_OVERRIDE=ssl=true pip install --no-cache-dir uwsgi --no-binary :all:
```

### For macOS (Apple Silicon):
```bash
CFLAGS="-I/opt/homebrew/opt/openssl@3/include" \
LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib" \
UWSGI_PROFILE_OVERRIDE=ssl=true pip install --no-cache-dir uwsgi --no-binary :all:
```

Then install Flask-uWSGI-WS:
```bash
pip install flask-uwsgi-ws
```

## Deployment

You can use uWSGI's built-in HTTP router to get up and running quickly:

```bash
$ uwsgi --master --http :8080 --http-websockets --wsgi-file app.py
```

...or call app.run, passing uwsgi any arguments you like:

```python
app.run(debug=True, host='localhost', port=8080, master=true, processes=8)
```

### Using with Gevent

uWSGI supports several concurrency models, including Gevent. To use Gevent, import `GeventWebSocket`:

```python
from flask_uwsgi_ws import GeventWebSocket
```

Then run uWSGI with the gevent loop engine:

```bash
$ uwsgi --master --http :8080 --http-websockets --gevent 100 --wsgi-file app.py
```

...or in your code:

```python
app.run(debug=True, gevent=100)
```

## Development

To use Flask's interactive debugger, install werkzeug's DebuggedApplication middleware:

```python
from werkzeug.debug import DebuggedApplication
app.wsgi_app = DebuggedApplication(app.wsgi_app, True)
```

Then run uWSGI with a single worker:

```bash
$ uwsgi --master --http :8080 --http-websockets --wsgi-file --workers 1 --threads 8 app.py
```

If you use `app.run(debug=True)`, Flask-uWSGI-WS will do this automatically.

## WebSocket API

Flask-uWSGI-WS handles the WebSocket handshake and provides a websocket client with the following methods:

- `websocket.recv()` - Receive a message
- `websocket.send(msg)` - Send a message
- `websocket.send_binary(msg)` - Send a binary message
- `websocket.recv_nb()` - Non-blocking receive
- `websocket.send_from_sharedarea(id, pos)` - Send from shared memory area
- `websocket.send_binary_from_sharedarea(id, pos)` - Send binary from shared memory area
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flask-uwsgi-ws",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "flask, uwsgi, websocket, websockets, ws, async",
    "author": null,
    "author_email": "Nidal Alhariri <leve09@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/7e/c3/955d5bf1f6288ac5ad9035442603ca0076f967e3e60b1e4a5633b5bf502b/flask_uwsgi_ws-0.4.0.tar.gz",
    "platform": null,
    "description": "# Flask-uWSGI-WS\n\nA high-performance WebSocket extension for Flask applications powered by uWSGI.\nCompatible with Python 3.12 and newer versions.\n\n## Example Usage\n\n```python\nfrom flask import Flask\nfrom flask_uwsgi_ws import WebSocket\n\napp = Flask(__name__)\nws = WebSocket(app)\n\n@ws.route('/echo')\ndef echo(ws):\n    while True:\n        msg = ws.receive()\n        ws.send(msg)\n\nif __name__ == '__main__':\n    app.run(debug=True, threads=16)\n```\n\n## Installation\n\nTo install Flask-uWSGI-WS, you'll need to install uWSGI with SSL support first:\n\n### For Ubuntu/Debian:\n```bash\nCFLAGS=\"-I/usr/include/openssl\" LDFLAGS=\"-L/usr/lib/x86_64-linux-gnu\" UWSGI_PROFILE_OVERRIDE=ssl=true pip install --no-cache-dir uwsgi --no-binary :all:\n```\n\n### For macOS (Apple Silicon):\n```bash\nCFLAGS=\"-I/opt/homebrew/opt/openssl@3/include\" \\\nLDFLAGS=\"-L/opt/homebrew/opt/openssl@3/lib\" \\\nUWSGI_PROFILE_OVERRIDE=ssl=true pip install --no-cache-dir uwsgi --no-binary :all:\n```\n\nThen install Flask-uWSGI-WS:\n```bash\npip install flask-uwsgi-ws\n```\n\n## Deployment\n\nYou can use uWSGI's built-in HTTP router to get up and running quickly:\n\n```bash\n$ uwsgi --master --http :8080 --http-websockets --wsgi-file app.py\n```\n\n...or call app.run, passing uwsgi any arguments you like:\n\n```python\napp.run(debug=True, host='localhost', port=8080, master=true, processes=8)\n```\n\n### Using with Gevent\n\nuWSGI supports several concurrency models, including Gevent. To use Gevent, import `GeventWebSocket`:\n\n```python\nfrom flask_uwsgi_ws import GeventWebSocket\n```\n\nThen run uWSGI with the gevent loop engine:\n\n```bash\n$ uwsgi --master --http :8080 --http-websockets --gevent 100 --wsgi-file app.py\n```\n\n...or in your code:\n\n```python\napp.run(debug=True, gevent=100)\n```\n\n## Development\n\nTo use Flask's interactive debugger, install werkzeug's DebuggedApplication middleware:\n\n```python\nfrom werkzeug.debug import DebuggedApplication\napp.wsgi_app = DebuggedApplication(app.wsgi_app, True)\n```\n\nThen run uWSGI with a single worker:\n\n```bash\n$ uwsgi --master --http :8080 --http-websockets --wsgi-file --workers 1 --threads 8 app.py\n```\n\nIf you use `app.run(debug=True)`, Flask-uWSGI-WS will do this automatically.\n\n## WebSocket API\n\nFlask-uWSGI-WS handles the WebSocket handshake and provides a websocket client with the following methods:\n\n- `websocket.recv()` - Receive a message\n- `websocket.send(msg)` - Send a message\n- `websocket.send_binary(msg)` - Send a binary message\n- `websocket.recv_nb()` - Non-blocking receive\n- `websocket.send_from_sharedarea(id, pos)` - Send from shared memory area\n- `websocket.send_binary_from_sharedarea(id, pos)` - Send binary from shared memory area",
    "bugtrack_url": null,
    "license": null,
    "summary": "Flask WebSocket extension for uWSGI",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/level09/flask-uwsgi-ws",
        "Repository": "https://github.com/level09/flask-uwsgi-ws.git"
    },
    "split_keywords": [
        "flask",
        " uwsgi",
        " websocket",
        " websockets",
        " ws",
        " async"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "51582615e149d192004632abef18c8944c39c847c56096bfaf16c8a4387365d9",
                "md5": "d2b0543aa5d612ec2ea704945240e00c",
                "sha256": "bf7ecc251e78a7500a85f067c823d0ad78fb3b8d1c80a8125319e0a8423682ad"
            },
            "downloads": -1,
            "filename": "flask_uwsgi_ws-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d2b0543aa5d612ec2ea704945240e00c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10205,
            "upload_time": "2024-12-01T16:15:44",
            "upload_time_iso_8601": "2024-12-01T16:15:44.243478Z",
            "url": "https://files.pythonhosted.org/packages/51/58/2615e149d192004632abef18c8944c39c847c56096bfaf16c8a4387365d9/flask_uwsgi_ws-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7ec3955d5bf1f6288ac5ad9035442603ca0076f967e3e60b1e4a5633b5bf502b",
                "md5": "32f2e6ea623a4486b3fc1f167cba9878",
                "sha256": "fe3a104eceb4caeefa6b93669b476fc6d8f623b4f6f65b93e294f8ef03a93db7"
            },
            "downloads": -1,
            "filename": "flask_uwsgi_ws-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32f2e6ea623a4486b3fc1f167cba9878",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13652,
            "upload_time": "2024-12-01T16:15:45",
            "upload_time_iso_8601": "2024-12-01T16:15:45.980417Z",
            "url": "https://files.pythonhosted.org/packages/7e/c3/955d5bf1f6288ac5ad9035442603ca0076f967e3e60b1e4a5633b5bf502b/flask_uwsgi_ws-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-01 16:15:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "level09",
    "github_project": "flask-uwsgi-ws",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flask-uwsgi-ws"
}
        
Elapsed time: 0.40460s