Skip to main content

Flashbag (flash messages) support for aiohttp.web

Project description

The library provides flashbag for aiohttp.web.


The library allows us to share some data between requests inside session.

Basic usage example:

import aiohttp_flashbag
from aiohttp import web
from aiohttp_session import setup as setup_session
from aiohttp_session import SimpleCookieStorage

async def handler_get(request):
    validation_error = aiohttp_flashbag.flashbag_get(request, 'error')

    error_html = ''

    if validation_error is not None:
        error_html = '<span>{validation_error}</span>'.format(

    body = '''
            <head><title>aiohttp_flashbag demo</title></head>
                <form method="POST" action="/">
                    <input type="text" name="name" />
                    <input type="submit" value="Say hello">
    body = body.format(error_html=error_html)

    return web.Response(body=body.encode('utf-8'), content_type='text/html')

async def handler_post(request):
    post = await

    if len(post['name']) == 0:
        aiohttp_flashbag.flashbag_set(request, 'error', 'Name is required')

        return web.HTTPSeeOther('/')

    body = 'Hello, {name}'.format(name=post['name'])

    return web.Response(body=body.encode('utf-8'), content_type='text/html')

def make_app():
    session_storage = SimpleCookieStorage()

    app = web.Application()

    setup_session(app, session_storage)




    return app


First of all, you have to register aiohttp_flashbag.flashbag_middleware in aiohttp.web.Application.

You can get some data from the previous request with aiohttp_flashbag.flashbag_get method. Parameters:

  • request. Instance of aiohttp.web_request.Request.
  • key. Name of “variable” that you want to get
  • default. The default value that should be returned, if the key doesn’t exist in session flashbag.

To set one “variable” in flashbag you should use aiohttp_flashbag.flashbag_set. Parameters:

  • request. Instance of aiohttp.web_request.Request.
  • key. Name of “variable” that you want to specify.
  • value. Data that you want to specify.

If you need to replace all “variables” in flashbag you should use aiohttp_flashbag.flashbag_replace_all. Parameters:

  • request. Instance of aiohttp.web_request.Request.
  • value. Dict with values that you want to add into flashbag.

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 aiohttp-flashbag, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size aiohttp_flashbag-0.0.3-py3-none-any.whl (3.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiohttp-flashbag-0.0.3.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page