aiohttp-asgi
============
[![PyPI - License](https://img.shields.io/pypi/l/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![Wheel](https://img.shields.io/pypi/wheel/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![PyPI](https://img.shields.io/pypi/v/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![PyPI](https://img.shields.io/pypi/pyversions/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![Coverage Status](https://coveralls.io/repos/github/mosquito/aiohttp-asgi/badge.svg?branch=master)](https://coveralls.io/github/mosquito/aiohttp-asgi?branch=master) ![tox](https://github.com/mosquito/aiohttp-asgi/workflows/tox/badge.svg?branch=master)
This module provides a way to use any ASGI compatible frameworks and aiohttp together.
Example
-------
```python
from aiohttp import web
from fastapi import FastAPI
from starlette.requests import Request as ASGIRequest
from aiohttp_asgi import ASGIResource
asgi_app = FastAPI()
@asgi_app.get("/asgi")
async def root(request: ASGIRequest):
return {
"message": "Hello World",
"root_path": request.scope.get("root_path")
}
aiohttp_app = web.Application()
# Create ASGIResource which handle
# any request startswith "/asgi"
asgi_resource = ASGIResource(asgi_app, root_path="/asgi")
# Register resource
aiohttp_app.router.register_resource(asgi_resource)
# Mount startup and shutdown events from aiohttp to ASGI app
asgi_resource.lifespan_mount(aiohttp_app)
# Start the application
web.run_app(aiohttp_app)
```
Installation
------------
```bash
pip install aiohttp-asgi
```
ASGI HTTP server
----------------
Command line tool for starting aiohttp web server with ASGI app.
#### Example
Create the `test_app.py`
```python
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
return JSONResponse({'hello': 'world'})
routes = [
Route("/", endpoint=homepage)
]
application = Starlette(debug=True, routes=routes)
```
and run the `test_app.py` with `aiohttp-asgi`
```bash
aiohttp-asgi \
--address "[::1]" \
--port 8080 \
test_app:application
```
alternatively using `python -m`
```bash
python -m aiohttp_asgi \
--address "[::1]" \
--port 8080 \
test_app:application
```
Raw data
{
"_id": null,
"home_page": "https://github.com/mosquito/aiohttp-asgi",
"name": "aiohttp-asgi",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "aiohttp,asgi",
"author": "Dmitry Orlov",
"author_email": "me@mosquito.su",
"download_url": "https://files.pythonhosted.org/packages/8b/0e/a97a05f992765d666b066cf08d968ffc98e719f28ebeaf0601869e5e0044/aiohttp_asgi-0.5.2.tar.gz",
"platform": null,
"description": "aiohttp-asgi\n============\n\n[![PyPI - License](https://img.shields.io/pypi/l/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![Wheel](https://img.shields.io/pypi/wheel/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![PyPI](https://img.shields.io/pypi/v/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![PyPI](https://img.shields.io/pypi/pyversions/aiohttp-asgi)](https://pypi.org/project/aiohttp-asgi) [![Coverage Status](https://coveralls.io/repos/github/mosquito/aiohttp-asgi/badge.svg?branch=master)](https://coveralls.io/github/mosquito/aiohttp-asgi?branch=master) ![tox](https://github.com/mosquito/aiohttp-asgi/workflows/tox/badge.svg?branch=master)\n\nThis module provides a way to use any ASGI compatible frameworks and aiohttp together.\n\nExample\n-------\n\n```python\nfrom aiohttp import web\nfrom fastapi import FastAPI\nfrom starlette.requests import Request as ASGIRequest\n\nfrom aiohttp_asgi import ASGIResource\n\n\nasgi_app = FastAPI()\n\n\n@asgi_app.get(\"/asgi\")\nasync def root(request: ASGIRequest):\n return {\n \"message\": \"Hello World\",\n \"root_path\": request.scope.get(\"root_path\")\n }\n\n\naiohttp_app = web.Application()\n\n# Create ASGIResource which handle\n# any request startswith \"/asgi\"\nasgi_resource = ASGIResource(asgi_app, root_path=\"/asgi\")\n\n# Register resource\naiohttp_app.router.register_resource(asgi_resource)\n\n# Mount startup and shutdown events from aiohttp to ASGI app\nasgi_resource.lifespan_mount(aiohttp_app)\n\n# Start the application\nweb.run_app(aiohttp_app)\n\n```\n\nInstallation\n------------\n\n```bash\npip install aiohttp-asgi\n```\n\nASGI HTTP server\n----------------\n\nCommand line tool for starting aiohttp web server with ASGI app.\n\n#### Example\n\nCreate the `test_app.py`\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\n\n\nasync def homepage(request):\n return JSONResponse({'hello': 'world'})\n\nroutes = [\n Route(\"/\", endpoint=homepage)\n]\n\napplication = Starlette(debug=True, routes=routes)\n```\n\nand run the `test_app.py` with `aiohttp-asgi`\n\n```bash\naiohttp-asgi \\\n --address \"[::1]\" \\\n --port 8080 \\\n test_app:application\n```\n\nalternatively using `python -m`\n\n```bash\npython -m aiohttp_asgi \\\n --address \"[::1]\" \\\n --port 8080 \\\n test_app:application\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Adapter to running ASGI applications on aiohttp",
"version": "0.5.2",
"split_keywords": [
"aiohttp",
"asgi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fc0696aa3e1956bb61f4b24032f665580858ba910f6d7ef9945b35ebbedca543",
"md5": "558d0a822c79bb2fdd36d0f01d9cc418",
"sha256": "9a594f400696fe91c8b44c864261181844c764c8846aacd1384e9de49bce164a"
},
"downloads": -1,
"filename": "aiohttp_asgi-0.5.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "558d0a822c79bb2fdd36d0f01d9cc418",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 15485,
"upload_time": "2023-03-20T12:48:40",
"upload_time_iso_8601": "2023-03-20T12:48:40.969119Z",
"url": "https://files.pythonhosted.org/packages/fc/06/96aa3e1956bb61f4b24032f665580858ba910f6d7ef9945b35ebbedca543/aiohttp_asgi-0.5.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8b0ea97a05f992765d666b066cf08d968ffc98e719f28ebeaf0601869e5e0044",
"md5": "7209716bc2102a6ec6ff7f032bd25fec",
"sha256": "bc601f74e286305cb35026d8701dd8eb74833c309e5f06493c487daa0daddb20"
},
"downloads": -1,
"filename": "aiohttp_asgi-0.5.2.tar.gz",
"has_sig": false,
"md5_digest": "7209716bc2102a6ec6ff7f032bd25fec",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 11356,
"upload_time": "2023-03-20T12:48:42",
"upload_time_iso_8601": "2023-03-20T12:48:42.436404Z",
"url": "https://files.pythonhosted.org/packages/8b/0e/a97a05f992765d666b066cf08d968ffc98e719f28ebeaf0601869e5e0044/aiohttp_asgi-0.5.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-20 12:48:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "mosquito",
"github_project": "aiohttp-asgi",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "aiohttp-asgi"
}