Skip to main content

An async web framework for humans

Project description


pip install aioserver

Getting Started

Start a test server with the examples in the Usage section below:

make test

Make requests against the running test server:

curl -v localhost:8080
curl -v localhost:8080/found
curl -v localhost:8080/not-found
curl -v localhost:8080/server-error


Create Application

from aioserver import Application

app = Application()

Basic Routes

async def index(request):
    return {'message': 'Hello, world!'}

async def found(request):
    return 302, {'Location': ''}, {'message': 'Found'}

async def not_found(request):
    return 404, {'message': 'Not Found'}

async def server_error(request):
    return 500

CORS Headers

async def cross_origin_resource_sharing(request):
    return {'message': 'Greetings from a different origin!'}

@app.cors('*', ['X-Custom-Header'])
async def cross_origin_header_sharing(request):
    return 200, {'X-Custom-Header': 'share-this-header-too'}, {'message': 'Hello!'}

Session Cookie

from aioserver.middleware import hours

@app.session(max_age=24 * hours)
async def session_cookie(request):
    print(f'session uuid {request.session}')
    return 200, {'message': 'Session UUID set as cookie for 24 hours.'}

Custom Middleware

Route-specific middleware:

async def always_ok(request, handler):
    response = await handler(request)
    response.set_status(200, 'OK')
    return response

async def not_found_but_still_ok(request):
    return 404, {'message': 'Not found but still OK!'}

Global middleware:

async def strict_transport_security(request, handler):
    response = await handler(request)
    response.headers['Strict-Transport-Security'] = 'max-age=31536000'
    return response


Run Application'', port=8080)



  • Decorator-based request handlers


  • Allow handler to specify HTTP response status
  • Allow handler to specify additional HTTP headers


  • Serialize XML ElementTree as text/xml response


  • Decorator-based CORS


  • Fix project description


  • Route-specific middleware using decorators
  • Global middleware using app.use(...)
  • Refactor CORS headers as middleware
  • Add session cookie as middleware


  • Package as a module instead of as a single file


  • Update existing routes when adding new middleware

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aioserver, version 0.7.3
Filename, size File type Python version Upload date Hashes
Filename, size aioserver-0.7.3-py3-none-any.whl (6.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aioserver-0.7.3.tar.gz (6.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page