Skip to main content

aiohttp_flashbag

The library provides flashbag for aiohttp.web.

https://img.shields.io/travis/aio-libs/aiohttp-flashbag.svg https://codecov.io/github/aio-libs/aiohttp-flashbag/coverage.svg

Usage

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(
            validation_error=validation_error,
        )

    body = '''
        <html>
            <head><title>aiohttp_flashbag demo</title></head>
            <body>
                <form method="POST" action="/">
                    <input type="text" name="name" />
                    {error_html}
                    <input type="submit" value="Say hello">
                </form>
            </body>
        </html>
    '''
    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 request.post()

    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)

    app.middlewares.append(aiohttp_flashbag.flashbag_middleware)

    app.router.add_route(
        'GET',
        '/',
        handler_get,
    )

    app.router.add_route(
        'POST',
        '/',
        handler_post,
    )

    return app


web.run_app(make_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.

Metadata

Release files for aiohttp-flashbag 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp-flashbag 0.0.3
File Size Uploaded Provenance Actions
aiohttp-flashbag-0.0.3.tar.gz 3.4 kB Without provenance Details for aiohttp-flashbag-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-flashbag 0.0.3
File Interpreter ABI Platform Actions
aiohttp_flashbag-0.0.3-py3-none-any.whl Python 3 none any Details for aiohttp_flashbag-0.0.3-py3-none-any.whl

Total release size: 6.5 kB

Release files / aiohttp-flashbag-0.0.3.tar.gz

Download URL aiohttp-flashbag-0.0.3.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5b3e2fe5bd1576ca7311baa9b3da2e6d4692b583878d5e397697b7297e296a2d
BLAKE2b-256 checksum
How to use checksums
c0301fa93af0a7424f647551e712bd805820e9da26332df7a4a4a2cacffc75d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp_flashbag-0.0.3-py3-none-any.whl

Download URL aiohttp_flashbag-0.0.3-py3-none-any.whl
Size 3.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a0ac74e859544b9457deb07722c700f29f908234f8b139adf31c0194c7624d6
BLAKE2b-256 checksum
How to use checksums
64458765ca000df5e9c76f1d81510c92be3126e0a28e0bdec73ed9b6a342d983
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for aiohttp-flashbag 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page