Contributing¶
│ │ │Bug reports, bug fixes, and new features are always welcome. Please raise issues on GitHub, and submit pull requests for any new code.
│ │ │Testing¶
│ │ │ -It’s recommended to test aiohttp_wsgi
in a virtual environment using venv
.
It’s recommended to test aiohttp_wsgi
in a virtual environment using venv
.
Run the test suite using unittest
:
python -m unittest discover tests
│ │ │
Contributors¶
│ │ ├── ./usr/share/doc/python3-aiohttp-wsgi/html/index.html │ │ │ @@ -33,15 +33,15 @@ │ │ │aiohttp-wsgi¶
│ │ │WSGI adapter for aiohttp.
│ │ │Features¶
│ │ │ │ │ │Resources¶
│ │ │-
│ │ │
- Documentation is on Read the Docs. │ │ ├── ./usr/share/doc/python3-aiohttp-wsgi/html/installation.html │ │ │ @@ -35,15 +35,15 @@ │ │ │
asyncio.loop
│ │ │ - The
asyncio.EventLoop
running the server.
│ │ │ asyncio.executor
│ │ │ -- The
Executor
running the WSGI request.
│ │ │ + - The
Executor
running the WSGI request.
│ │ │ aiohttp.request
│ │ │ - The raw
aiohttp.web.Request
that initiated the WSGI request. Use this to access additional │ │ │ request metadata.
│ │ │ An adapter for WSGI applications, allowing them to run on aiohttp.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- application – A WSGI application callable. │ │ │ -
- url_scheme (str) – A hint about the URL scheme used to access the application. Corresponds to
environ['wsgi.url_scheme']
. Default is auto-detected to'http'
or'https'
.
│ │ │ - - stderr (io.BytesIO) – A file-like value for WSGI error logging. Corresponds to
environ['wsgi.errors']
. Defaults tosys.stderr
.
│ │ │ - - inbuf_overflow (int) – A tempfile will be created if the request body is larger than this value, which is measured in bytes. Defaults to
524288
.
│ │ │ - - max_request_body_size (int) – Maximum number of bytes in request body. Defaults to
1073741824
. Larger requests will receive a HTTP 413 (Request Entity Too Large) response.
│ │ │ - - executor (concurrent.futures.Executor) – An Executor instance used to run WSGI requests. Defaults to the
asyncio
base executor.
│ │ │ - - loop – The asyncio loop. Defaults to
asyncio.get_event_loop()
.
│ │ │ + - url_scheme (str) – A hint about the URL scheme used to access the application. Corresponds to
environ['wsgi.url_scheme']
. Default is auto-detected to'http'
or'https'
.
│ │ │ + - stderr (io.BytesIO) – A file-like value for WSGI error logging. Corresponds to
environ['wsgi.errors']
. Defaults tosys.stderr
.
│ │ │ + - inbuf_overflow (int) – A tempfile will be created if the request body is larger than this value, which is measured in bytes. Defaults to
524288
.
│ │ │ + - max_request_body_size (int) – Maximum number of bytes in request body. Defaults to
1073741824
. Larger requests will receive a HTTP 413 (Request Entity Too Large) response.
│ │ │ + - executor (concurrent.futures.Executor) – An Executor instance used to run WSGI requests. Defaults to the
asyncio
base executor.
│ │ │ + - loop – The asyncio loop. Defaults to
asyncio.get_event_loop()
.
│ │ │
│ │ │
│ │ │ @@ -119,28 +119,28 @@
│ │ │ Runs the WSGI application on aiohttp, serving it until keyboard interrupt.
│ │ ││ │ │
│ │ ││ │ │ │ │ │ │ │ │ │ │ │ │ │ │Parameters: │ │ │-
│ │ │
- application – A WSGI application callable. │ │ │ -
- url_scheme (str) – A hint about the URL scheme used to access the application. Corresponds to
environ['wsgi.url_scheme']
. Default is auto-detected to'http'
or'https'
.
│ │ │ - - stderr (io.BytesIO) – A file-like value for WSGI error logging. Corresponds to
environ['wsgi.errors']
. Defaults tosys.stderr
.
│ │ │ - - inbuf_overflow (int) – A tempfile will be created if the request body is larger than this value, which is measured in bytes. Defaults to
524288
.
│ │ │ - - max_request_body_size (int) – Maximum number of bytes in request body. Defaults to
1073741824
. Larger requests will receive a HTTP 413 (Request Entity Too Large) response.
│ │ │ - - threads (int) – Number of threads used to process application logic. Defaults to
4
.
│ │ │ - - host (str) – Host interfaces to bind. Defaults to
'0.0.0.0'
and'::'
.
│ │ │ - - port (int) – Port to bind. Defaults to
8080
.
│ │ │ - - unix_socket (str) – Path to a unix socket to bind, cannot be used with
host
.
│ │ │ - - unix_socket_perms (int) – Filesystem permissions to apply to the unix socket. Defaults to
384
.
│ │ │ - - backlog (int) – Socket connection backlog. Defaults to 1024. │ │ │ -
- static (list) – Static root mappings in the form (path, directory). Defaults to () │ │ │ -
- static_cors (list) – Set to ‘*’ to enable CORS on static files for all origins, or a string to enable CORS for a specific origin. Defaults to None │ │ │ -
- script_name (str) – URL prefix for the WSGI application, should start with a slash, but not end with a slash. Defaults to
''
.
│ │ │ - - shutdown_timeout (int) – Timeout when closing client connections on server shutdown. Defaults to
60.0
.
│ │ │ + - url_scheme (str) – A hint about the URL scheme used to access the application. Corresponds to
environ['wsgi.url_scheme']
. Default is auto-detected to'http'
or'https'
.
│ │ │ + - stderr (io.BytesIO) – A file-like value for WSGI error logging. Corresponds to
environ['wsgi.errors']
. Defaults tosys.stderr
.
│ │ │ + - inbuf_overflow (int) – A tempfile will be created if the request body is larger than this value, which is measured in bytes. Defaults to
524288
.
│ │ │ + - max_request_body_size (int) – Maximum number of bytes in request body. Defaults to
1073741824
. Larger requests will receive a HTTP 413 (Request Entity Too Large) response.
│ │ │ + - threads (int) – Number of threads used to process application logic. Defaults to
4
.
│ │ │ + - host (str) – Host interfaces to bind. Defaults to
'0.0.0.0'
and'::'
.
│ │ │ + - port (int) – Port to bind. Defaults to
8080
.
│ │ │ + - unix_socket (str) – Path to a unix socket to bind, cannot be used with
host
.
│ │ │ + - unix_socket_perms (int) – Filesystem permissions to apply to the unix socket. Defaults to
384
.
│ │ │ + - backlog (int) – Socket connection backlog. Defaults to 1024. │ │ │ +
- static (list) – Static root mappings in the form (path, directory). Defaults to () │ │ │ +
- static_cors (list) – Set to ‘*’ to enable CORS on static files for all origins, or a string to enable CORS for a specific origin. Defaults to None │ │ │ +
- script_name (str) – URL prefix for the WSGI application, should start with a slash, but not end with a slash. Defaults to
''
.
│ │ │ + - shutdown_timeout (int) – Timeout when closing client connections on server shutdown. Defaults to
60.0
.
│ │ │
Installation¶
│ │ │Requirements¶
│ │ │aiohttp_wsgi
supports Python 3.5 and above.
Installing¶
│ │ │ -It’s recommended to install aiohttp_wsgi
in a virtual environment using venv
.
It’s recommended to install aiohttp_wsgi
in a virtual environment using venv
.
Install aiohttp_wsgi
using pip.
pip install aiohttp_wsgi
│ │ │
Upgrading¶
│ │ ├── ./usr/share/doc/python3-aiohttp-wsgi/html/main.html │ │ │ @@ -31,15 +31,15 @@ │ │ │Command line interface (CLI)¶
│ │ │If you don’t need to add websockets or
│ │ │ async request handlers to your app, but still want to run your WSGI app on the
│ │ │ -asyncio
event loop, aiohttp_wsgi
provides a simple command line interface.
asyncio
event loop, aiohttp_wsgi
provides a simple command line interface.
│ │ │ Example usage¶
│ │ │Serve a WSGI application called application
, located in the your_project.wsgi
module:
aiohttp-wsgi-serve your_project.wsgi:application
│ │ │
Serve a WSGI application and include a static file directory.
│ │ ├── ./usr/share/doc/python3-aiohttp-wsgi/html/wsgi.html │ │ │ @@ -35,15 +35,15 @@ │ │ │Running a WSGI app¶
│ │ │aiohttp_wsgi
allows you to run WSGI applications (e.g. Django, Flask) on aiohttp.
│ │ │ This allows you to add async features like websockets and long-polling to an existing Python web app.
Hint
│ │ │If you don’t need to add websockets or
│ │ │ async request handlers to your app, but still want to run your WSGI app on the
│ │ │ -asyncio
event loop, aiohttp_wsgi
provides a simpler command line interface.
asyncio
event loop, aiohttp_wsgi
provides a simpler command line interface.
│ │ │ Run a web server¶
│ │ │In order to implement a WSGI server, first import your WSGI application and wrap it in a WSGIHandler
.
from aiohttp import web
│ │ │ from aiohttp_wsgi import WSGIHandler
│ │ │ from your_project.wsgi import application
│ │ │ @@ -64,29 +64,29 @@
│ │ │ See the aiohttp.web documentation for information on adding
│ │ │ websockets and async request handlers to your app.
│ │ │
Serving simple WSGI apps¶
│ │ │If you don’t need to add websockets or
│ │ │ async request handlers to your app, but still want to run your WSGI app on the
│ │ │ -asyncio
event loop, aiohttp_wsgi
provides a simple serve()
helper.
asyncio
event loop, aiohttp_wsgi
provides a simple serve()
helper.
│ │ │ from aiohttp_wsgi import serve
│ │ │
│ │ │ serve(application)
│ │ │
Extra environ keys¶
│ │ │aiohttp_wsgi
adds the following additional keys to the WSGI environ:
-
│ │ │