a2wsgi


Namea2wsgi JSON
Version 1.10.3 PyPI version JSON
download
home_pagehttps://github.com/abersheeran/a2wsgi
SummaryConvert WSGI app to ASGI app or ASGI app to WSGI app.
upload_time2024-03-13 02:13:53
maintainer
docs_urlNone
author
requires_python>=3.8.0
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # a2wsgi

Convert WSGI app to ASGI app or ASGI app to WSGI app.

Pure Python. Only depend on the standard library.

Compared with other converters, the advantage is that a2wsgi will not accumulate the requested content or response content in the memory, so you don't have to worry about the memory limit caused by a2wsgi. This problem exists in converters implemented by uvicorn/startlette or hypercorn.

## Install

```
pip install a2wsgi
```

## How to use

### `WSGIMiddleware`

Convert WSGI app to ASGI app:

```python
from a2wsgi import WSGIMiddleware

ASGI_APP = WSGIMiddleware(WSGI_APP)
```

WSGIMiddleware executes WSGI applications with a thread pool of up to 10 threads by default. If you want to increase or decrease this number, just like `WSGIMiddleware(..., workers=15)`.

WSGIMiddleware utilizes a queue to direct traffic from the WSGI App to the client. To adjust the queue size, simply specify the send_queue_size parameter (default to `10`) during initialization, like so: WSGIMiddleware(..., send_queue_size=15). This enable developers to balance memory usage and application responsiveness.

### `ASGIMiddleware`

Convert ASGI app to WSGI app:

```python
from a2wsgi import ASGIMiddleware

WSGI_APP = ASGIMiddleware(ASGI_APP)
```

`ASGIMiddleware` will wait for the ASGI application's Background Task to complete before returning the last null byte. But sometimes you may not want to wait indefinitely for the execution of the Background Task of the ASGI application, then you only need to give the parameter `ASGIMiddleware(..., wait_time=5.0)`, after the time exceeds, the ASGI task corresponding to the request will be tried to cancel, and the last null byte will be returned.

You can also specify your own event loop through the `loop` parameter instead of the default event loop. Like `ASGIMiddleware(..., loop=faster_loop)`

### Access the original `Scope`/`Environ`

Sometimes you may need to access the original WSGI Environ in the ASGI application, just use `scope["wsgi_environ"]`; it is also easy to access the ASGI Scope in the WSGI Application, use `environ["asgi.scope"]`.

## Benchmark

Run `pytest ./benchmark.py -s` to compare the performance of `a2wsgi` and `uvicorn.middleware.wsgi.WSGIMiddleware` / `asgiref.wsgi.WsgiToAsgi`.

## Why a2wsgi

### Convert WSGI app to ASGI app

You can convert an existing WSGI project to an ASGI project to make it easier to migrate from WSGI applications to ASGI applications.

### Convert ASGI app to WSGI app

There is a lot of support for WSGI. Converting ASGI to WSGI, you will be able to use many existing services to deploy ASGI applications.

## Compatibility list

This list quickly demonstrates the compatibility of some common frameworks for users who are unfamiliar with the WSGI and ASGI protocols.

- WSGI: [Django(wsgi)](https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/)/[Kuí(wsgi)](https://kui.aber.sh/wsgi/)/[Pyramid](https://trypyramid.com/)/[Bottle](https://bottlepy.org/)/[Flask](https://flask.palletsprojects.com/)
- ASGI: [Django(asgi)](https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/)/[Kuí(asgi)](https://kui.aber.sh/asgi/)/[Starlette](https://www.starlette.io/)/[FastAPI](https://fastapi.tiangolo.com/)/[Sanic](https://sanic.readthedocs.io/en/stable/)/[Quart](https://pgjones.gitlab.io/quart/)
- **Unsupport**: [aiohttp](https://docs.aiohttp.org/en/stable/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/abersheeran/a2wsgi",
    "name": "a2wsgi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "abersheeran <me@abersheeran.com>",
    "download_url": "https://files.pythonhosted.org/packages/07/7b/1553a92d281c18201eb338061ac0485da845c151c5c28c51f464a9de13c1/a2wsgi-1.10.3.tar.gz",
    "platform": null,
    "description": "# a2wsgi\n\nConvert WSGI app to ASGI app or ASGI app to WSGI app.\n\nPure Python. Only depend on the standard library.\n\nCompared with other converters, the advantage is that a2wsgi will not accumulate the requested content or response content in the memory, so you don't have to worry about the memory limit caused by a2wsgi. This problem exists in converters implemented by uvicorn/startlette or hypercorn.\n\n## Install\n\n```\npip install a2wsgi\n```\n\n## How to use\n\n### `WSGIMiddleware`\n\nConvert WSGI app to ASGI app:\n\n```python\nfrom a2wsgi import WSGIMiddleware\n\nASGI_APP = WSGIMiddleware(WSGI_APP)\n```\n\nWSGIMiddleware executes WSGI applications with a thread pool of up to 10 threads by default. If you want to increase or decrease this number, just like `WSGIMiddleware(..., workers=15)`.\n\nWSGIMiddleware utilizes a queue to direct traffic from the WSGI App to the client. To adjust the queue size, simply specify the send_queue_size parameter (default to `10`) during initialization, like so: WSGIMiddleware(..., send_queue_size=15). This enable developers to balance memory usage and application responsiveness.\n\n### `ASGIMiddleware`\n\nConvert ASGI app to WSGI app:\n\n```python\nfrom a2wsgi import ASGIMiddleware\n\nWSGI_APP = ASGIMiddleware(ASGI_APP)\n```\n\n`ASGIMiddleware` will wait for the ASGI application's Background Task to complete before returning the last null byte. But sometimes you may not want to wait indefinitely for the execution of the Background Task of the ASGI application, then you only need to give the parameter `ASGIMiddleware(..., wait_time=5.0)`, after the time exceeds, the ASGI task corresponding to the request will be tried to cancel, and the last null byte will be returned.\n\nYou can also specify your own event loop through the `loop` parameter instead of the default event loop. Like `ASGIMiddleware(..., loop=faster_loop)`\n\n### Access the original `Scope`/`Environ`\n\nSometimes you may need to access the original WSGI Environ in the ASGI application, just use `scope[\"wsgi_environ\"]`; it is also easy to access the ASGI Scope in the WSGI Application, use `environ[\"asgi.scope\"]`.\n\n## Benchmark\n\nRun `pytest ./benchmark.py -s` to compare the performance of `a2wsgi` and `uvicorn.middleware.wsgi.WSGIMiddleware` / `asgiref.wsgi.WsgiToAsgi`.\n\n## Why a2wsgi\n\n### Convert WSGI app to ASGI app\n\nYou can convert an existing WSGI project to an ASGI project to make it easier to migrate from WSGI applications to ASGI applications.\n\n### Convert ASGI app to WSGI app\n\nThere is a lot of support for WSGI. Converting ASGI to WSGI, you will be able to use many existing services to deploy ASGI applications.\n\n## Compatibility list\n\nThis list quickly demonstrates the compatibility of some common frameworks for users who are unfamiliar with the WSGI and ASGI protocols.\n\n- WSGI: [Django(wsgi)](https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/)/[Ku\u00ed(wsgi)](https://kui.aber.sh/wsgi/)/[Pyramid](https://trypyramid.com/)/[Bottle](https://bottlepy.org/)/[Flask](https://flask.palletsprojects.com/)\n- ASGI: [Django(asgi)](https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/)/[Ku\u00ed(asgi)](https://kui.aber.sh/asgi/)/[Starlette](https://www.starlette.io/)/[FastAPI](https://fastapi.tiangolo.com/)/[Sanic](https://sanic.readthedocs.io/en/stable/)/[Quart](https://pgjones.gitlab.io/quart/)\n- **Unsupport**: [aiohttp](https://docs.aiohttp.org/en/stable/)\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Convert WSGI app to ASGI app or ASGI app to WSGI app.",
    "version": "1.10.3",
    "project_urls": {
        "Homepage": "https://github.com/abersheeran/a2wsgi",
        "Repository": "https://github.com/abersheeran/a2wsgi"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a006e3809a6328c7bed63163a7603c93784786da75accb4e178966f7112182f3",
                "md5": "eff313f3e5133e0c8d2cca1e69bad565",
                "sha256": "6ccb58b14a46a25f5ff9ada30247bd99bf78a799417a10230a9760a44aac216f"
            },
            "downloads": -1,
            "filename": "a2wsgi-1.10.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eff313f3e5133e0c8d2cca1e69bad565",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0",
            "size": 16738,
            "upload_time": "2024-03-13T02:13:51",
            "upload_time_iso_8601": "2024-03-13T02:13:51.654538Z",
            "url": "https://files.pythonhosted.org/packages/a0/06/e3809a6328c7bed63163a7603c93784786da75accb4e178966f7112182f3/a2wsgi-1.10.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "077b1553a92d281c18201eb338061ac0485da845c151c5c28c51f464a9de13c1",
                "md5": "3169a84d2d9fc4337d5ff71fc4782e71",
                "sha256": "7af32e7d18d498e2e1b835079302577d3ec1d789185582e8158ecb83618d9444"
            },
            "downloads": -1,
            "filename": "a2wsgi-1.10.3.tar.gz",
            "has_sig": false,
            "md5_digest": "3169a84d2d9fc4337d5ff71fc4782e71",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.0",
            "size": 18111,
            "upload_time": "2024-03-13T02:13:53",
            "upload_time_iso_8601": "2024-03-13T02:13:53.392538Z",
            "url": "https://files.pythonhosted.org/packages/07/7b/1553a92d281c18201eb338061ac0485da845c151c5c28c51f464a9de13c1/a2wsgi-1.10.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-13 02:13:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "abersheeran",
    "github_project": "a2wsgi",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "a2wsgi"
}
        
Elapsed time: 0.21253s