Skip to main content

LiveView in Python

Project description

PyView

A Python implementation of Phoenix LiveView

PyView enables dynamic, real-time web apps, using server-rendered HTML.

Source Code: https://github.com/ogrodnek/pyview

Installation

pip install pyview-web

Quickstart

There's a cookiecutter template available

cookiecutter gh:ogrodnek/pyview-cookiecutter

Live Examples

https://examples.pyview.rocks/

Other Examples

Simple Counter

See it live!

count.py:

from pyview import LiveView, LiveViewSocket
from typing import TypedDict


class CountContext(TypedDict):
    count: int


class CountLiveView(LiveView[CountContext]):
    async def mount(self, socket: LiveViewSocket[CountContext], _session):
        socket.context = {"count": 0}

    async def handle_event(self, event, payload, socket: LiveViewSocket[CountContext]):
        if event == "decrement":
            socket.context["count"] -= 1

        if event == "increment":
            socket.context["count"] += 1

    async def handle_params(self, url, params, socket: LiveViewSocket[CountContext]):
        if "c" in params:
            socket.context["count"] = int(params["c"][0])

count.html:

<div>
  <h1>Count is {{count}}</h1>
  <button phx-click="decrement">-</button>
  <button phx-click="increment">+</button>
</div>

Acknowledgements

  • Obviously this project wouldn't exist without Phoenix LiveView, which is a wonderful paradigm and implementation. Besides using their ideas, we also directly use the LiveView JavaScript code.

  • Thanks to Donnie Flood for the encouragement, inspiration, help, and even pull requests to get this project started! Check out LiveViewJS for a TypeScript implementation of LiveView (that's much more mature than this one!)

  • Thanks to Darren Mulholland for both his Let's Build a Template Language tutorial, as well as his ibis template engine, which he very generously released into the public domain, and forms the basis of templating in PyView.

Additional Thanks

Status

PyView is in the very early stages of active development. Please check it out and give feedback! Note that the API is likely to change, and there are many features that are not yet implemented.

Running the included Examples

Setup

poetry install

Running

poetry run uvicorn examples.app:app --reload

Then go to http://localhost:8000/

Poetry Install

brew install pipx
pipx install poetry
pipx ensurepath

(see https://python-poetry.org/docs/#installation for more details)

License

PyView is licensed under the MIT License.

Download files

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

Source Distribution

pyview_web-0.0.21.tar.gz (75.9 kB view details)

Uploaded Source

Built Distribution

pyview_web-0.0.21-py3-none-any.whl (85.0 kB view details)

Uploaded Python 3

File details

Details for the file pyview_web-0.0.21.tar.gz.

File metadata

  • Download URL: pyview_web-0.0.21.tar.gz
  • Upload date:
  • Size: 75.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for pyview_web-0.0.21.tar.gz
Algorithm Hash digest
SHA256 15529a9197a0898faf23fd71c67a16f3da3422dd6fdb89f0ecc3c89cd6073685
MD5 64a2157531175572cab2353b4568ac90
BLAKE2b-256 04a9cba52c141350bdd904389e28dbcbc584148cfc50e0acb4fad76c59f64236

See more details on using hashes here.

File details

Details for the file pyview_web-0.0.21-py3-none-any.whl.

File metadata

  • Download URL: pyview_web-0.0.21-py3-none-any.whl
  • Upload date:
  • Size: 85.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for pyview_web-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 12a111fe6fdc9823d9d5f455b4a6a9888aca47a93a9aa21588d870eb5ac0c849
MD5 de6c33a2190651d20a8f0a9ec688f574
BLAKE2b-256 0b7972f97c128f9fb35637c36951edb5d0a91f9a01f81a70783a19f0fe251ab8

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