Skip to content

youngrok/aiohttp-wsgi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aiohttp-wsgi

aiohttp-wsgi is a WSGI adapter for aiohttp.

Features

Installation

  1. Install using pip install aiohttp-wsgi.

Usage

WSGIHandler(application, **kwargs)

Handler that wraps a WSGI application for use inside an aiohttp Application.

from aiohttp.web import Application
from aiohttp_wsgi import WSGIHandler
from your_app.wsgi import application

aiohttp_application = Application()
wsgi_handler = WSGIHandler(application)
aiohttp_application.router.add_route("*", "/{path_info:.*}", wsgi_handler.handle_request)

Available arguments:

url_scheme

hint about the URL scheme used to access the application. Corresponds to environ["wsgi.uri_scheme"]. Default value auto-detected to "http" or "https".

stderr

A file-like value for WSGI error logging. Corresponds to environ["wsgi.errors"]. Defaults to sys.stderr.

inbuf_overflow

A tempfile will be created if the request body is larger than inbuf_overflow, which is measured in bytes. Defaults to 512K (524288).

max_request_body_size

Maximum number of bytes in request body. Defaults to 1GB (1073741824). Larger requests will receive a HTTP 413 (Request Entity Too Large) response.

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().

configure_server(application, **kwargs)

High-level factory method that wraps a WSGI application in an asyncio server and aiohttp Application.

from aiohttp_wsgi import configure_server
from your_app.wsgi import application

server, app = configure_server(application)

Available arguments:

host

The IP address to bind the server. Defaults to "0.0.0.0".

port

The network port to bind the server. Defaults to 8080.

unix_socket

The path to a unix socket to bind the server. Overrides host.

unix_socket_perms

A set of filesystem permissions to apply to the unix socket. Defaults to 0o600.

socket

A preexisting socket object to use for the server. Overrides host.

backlog

The maximum number of queued connections for the socket. Defaults to 1024.

routes

A list of (method, path, handler) routes to add to the aiohttp Application. Defaults to [].

static

A list of (path, dirname) static routes to add to the aiohttp Application. Defaults to [].

on_finish

A list of callbacks to be executed when the server shuts down. Each callback will be passed the aiohttp Application.

script_name

The URL prefix to mount the WSGI application. Corresponds to environ["SCRIPT_NAME"]. This should not end with a slash. Defaults to "".

configure_server() also accepts all arguments available to WSGIHandler().

serve(application, **kwargs)

High-level factory method that starts a server running a WSGI application.

from aiohttp_wsgi import serve
from your_app.wsgi import application

serve(application)

serve() accepts all arguments available to configure_server().

Design

WSGI applications are run on an asyncio executor. This allows existing Python frameworks like Django and Flask to run normally without blocking the main event loop or resorting to hacks like monkey-patching the Python standard library. This enables you to write the majority of your application code in a safe, predictable environment.

Asyncronous parts of your application (e.g. websockets) can be run on the same network port, using the aiohttp router to switch between your WSGI app and asyncronous code.

Build status

This project is built on every push using the Travis-CI service.

image

Support and announcements

Downloads and bug tracking can be found at the main project website.

More information

The aiohttp-wsgi project was developed by Dave Hall. You can get the code from the aiohttp-wsgi project site.

Dave Hall is a freelance web developer, based in Cambridge, UK. You can usually find him on the Internet in a number of different places:

About

WSGI adapter for aiohttp.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%