Skip to main content

debugtoolbar for aiohttp

Project description

|Build status| |Coverage status|

aiohttp_debugtoolbar provides a debug toolbar for your aiohttp web application. Library is port of pyramid_debugtoolbar and still in early development stages. Basic functionality has been ported:

  • basic panels

  • intercept redirects

  • intercept and pretty print exception

  • interactive python console

  • show source code

https://raw.githubusercontent.com/aio-libs/aiohttp_debugtoolbar/master/demo/aiohttp_debugtoolba_sceenshot.png

Ported Panels

HeaderDebugPanel, PerformanceDebugPanel, TracebackPanel, SettingsDebugPanel, MiddlewaresDebugPanel, VersionDebugPanel, RoutesDebugPanel, RequestVarsDebugPanel

Help Needed

Are you an experienced coder looking for a project to contribute to python/asyncio libraries? This is the project for you!

Install and Configuration

$ pip install aiohttp_debugtoolbar

In order to plug in aiohttp_debugtoolbar you have to attach middleware to your aiohttp.web.Application, and call aiohttp_debugtoolbar.setup

import aiohttp_debugtoolbar
app = web.Application(loop=loop,
                       middlewares=[aiohttp_debugtoolbar.middleware])
aiohttp_debugtoolbar.setup(app)

Full Example

import asyncio
import jinja2
import aiohttp_debugtoolbar
import aiohttp_jinja2

from aiohttp import web


@aiohttp_jinja2.template('index.html')
def basic_handler(request):
    return {'title': 'example aiohttp_debugtoolbar!',
            'text': 'Hello aiohttp_debugtoolbar!',
            'app': request.app}


@asyncio.coroutine
def exception_handler(request):
    raise NotImplementedError


@asyncio.coroutine
def init(loop):
    # add aiohttp_debugtoolbar middleware to you application
    app = web.Application(loop=loop,
                          middlewares=[aiohttp_debugtoolbar.middleware])
    # install aiohttp_debugtoolbar
    aiohttp_debugtoolbar.setup(app)

    template = """
    <html>
        <head>
            <title>{{ title }}</title>
        </head>
        <body>
            <h1>{{ text }}</h1>
            <p>
              <a href="{{ app.router['exc_example'].url() }}">
              Exception example</a>
            </p>
        </body>
    </html>
    """
    # install jinja2 templates
    loader = jinja2.DictLoader({'index.html': template})
    aiohttp_jinja2.setup(app, loader=loader)

    # init routes for index page, and page with error
    app.router.add_route('GET', '/', basic_handler, name='index')
    app.router.add_route('GET', '/exc', exception_handler,
                         name='exc_example')

    handler = app.make_handler()
    srv = yield from loop.create_server(handler, '127.0.0.1', 9000)
    print("Server started at http://127.0.0.1:9000")
    return srv, handler


loop = asyncio.get_event_loop()
srv, handler = loop.run_until_complete(init(loop))
try:
    loop.run_forever()
except KeyboardInterrupt:
    loop.run_until_complete(handler.finish_connections())

Thanks

I’ve borrowed a lot of code from following projects. I highly recommend to check them out:

Play With Demo

https://github.com/aio-libs/aiohttp_debugtoolbar/tree/master/demo

Requirements

Project details


Download files

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

Source Distribution

aiohttp_debugtoolbar-0.0.3.tar.gz (411.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_debugtoolbar-0.0.3-py3-none-any.whl (429.0 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_debugtoolbar-0.0.3.tar.gz.

File metadata

File hashes

Hashes for aiohttp_debugtoolbar-0.0.3.tar.gz
Algorithm Hash digest
SHA256 e536820a146698e761d198b8b03280c850ddb467caa3950b1444c237efb075d6
MD5 2942239fad01073e0c35367a4eb6421d
BLAKE2b-256 f165819212dbebb3d1ccf89cea628b9e0f047889a1019746aa3310bee0c28e83

See more details on using hashes here.

File details

Details for the file aiohttp_debugtoolbar-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_debugtoolbar-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cc7687ab53a147f16757e986d4795a17f3b96e10836d1ee1638f6395ec16afc4
MD5 e52156592e803e23e6754d3333bff33d
BLAKE2b-256 c5183596b8a0899ceebf35db0f75767aac1bb228ffb4f64d6949cfa9d51489ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page