Skip to main content

Async Web Framework

Project description

Dazzler

Build Documentation Status Version License

Dazzler is a Python async web framework. Create dazzling fast pages with a layout of Python components and bindings to update from the backend.

Install

Install with pip: $ pip install dazzler

Features

  • Fast WebSocket based communication, deliver updates in realtime to thousands of connected clients at once.
  • Lightweight bundles for fast initial page load.
  • Support for third party integrations via middlewares.
  • Session & authentication systems.
  • No HTML/CSS/JS knowledge required, write everything with Python.
  • Multi page based.
  • Hot reload.
  • Tons of components.
  • Tie & Transform API to perform updates on the client side.

Basic example

Create a page with a layout and assign bindings to save & load a visitor name with the session system. The button to save the visitor name is disabled if no input value via tie & transform.

from dazzler import Dazzler
from dazzler.system import Page, BindingContext, transforms as t
from dazzler.components import core

app = Dazzler(__name__)
page = Page(
    __name__,
    core.Container([
        core.Html('H2', 'My dazzler page'),
        core.Container('Please enter a name', identity='visitor-name'),
        core.Input(value='', identity='input'),
        core.Button('Save name', identity='save-btn', disabled=True),
    ], identity='layout', id='layout'),
    title='My Page',
    url='/'
)

# UI updates via tie & transforms
page.tie('value@input', 'disabled@save-btn').transform(
    t.Length().t(t.Lesser(1))
)


# Bindings executes on the server via websockets.
@page.bind('clicks@save-btn')
async def on_click(context: BindingContext):
    # Save the visitor name via session system
    name = await context.get_aspect('input', 'value')
    await context.session.set('visitor', name)
    await context.set_aspect(
        'visitor-name', children=f'Saved {name}'
    )


# Aspects defined on the layout trigger on initial render and
# allows to insert initial data.
@page.bind('id@layout')
async def on_layout(context: BindingContext):
    visitor = await context.session.get('visitor')
    if visitor:
        await context.set_aspect(
            'visitor-name', children=f'Welcome back {visitor}!'
        )


app.add_page(page)

if __name__ == '__main__':
    app.start()

Documentation

Full documentation hosted on readthedocs.

Get help for the command line tools: $ dazzler --help

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

dazzler-0.6.0.tar.gz (2.5 MB view details)

Uploaded Source

File details

Details for the file dazzler-0.6.0.tar.gz.

File metadata

  • Download URL: dazzler-0.6.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for dazzler-0.6.0.tar.gz
Algorithm Hash digest
SHA256 325ee5149ec48edd070159fd0e83ace9e13cea9aba77f60d05de21fd2cb90ef0
MD5 ece0f8929781c7aa54ce100a2e6f3a92
BLAKE2b-256 437961f92fc617ebaeda8ed5b09064b81b34e9b75696acabe2d64743e54457cf

See more details on using hashes here.

Supported by

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