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.

Documentation: https://pyview.rocks

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

uv sync

Running

uv run uvicorn examples.app:app --reload

Then go to http://localhost:8000/

uv Install

brew install uv

or

curl -LsSf https://astral.sh/uv/install.sh | sh

(see https://docs.astral.sh/uv/getting-started/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.9.0a3.tar.gz (136.7 kB view details)

Uploaded Source

Built Distribution

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

pyview_web-0.9.0a3-py3-none-any.whl (161.5 kB view details)

Uploaded Python 3

File details

Details for the file pyview_web-0.9.0a3.tar.gz.

File metadata

  • Download URL: pyview_web-0.9.0a3.tar.gz
  • Upload date:
  • Size: 136.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyview_web-0.9.0a3.tar.gz
Algorithm Hash digest
SHA256 855b52d14b26dc5779d8a68eeaeee19585dfb9755c30e3152f7c20dc9c52a7aa
MD5 dfb137a685541348f42d2e2e4531a3ce
BLAKE2b-256 e095cd98cac194c89409894466f615323055d9133d10105706a5dcb77cc4d586

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyview_web-0.9.0a3.tar.gz:

Publisher: release.yml on ogrodnek/pyview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyview_web-0.9.0a3-py3-none-any.whl.

File metadata

  • Download URL: pyview_web-0.9.0a3-py3-none-any.whl
  • Upload date:
  • Size: 161.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyview_web-0.9.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 588efa278ac4ea64e0c2068fd2673efc5f8b90a537411be26a78cc690f420b98
MD5 a9118e090f32af5afeea3c6cb51018af
BLAKE2b-256 60812c13930014e388ec1d1c47300f3a3df79a6419f82aea87a3de5b576ff979

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyview_web-0.9.0a3-py3-none-any.whl:

Publisher: release.yml on ogrodnek/pyview

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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