<img src="https://pyview.rocks/images/pyview_logo_512.png" width="128px" align="right" />
# PyView
> A Python implementation of Phoenix LiveView
PyView enables dynamic, real-time web apps, using server-rendered HTML.
**Source Code**: <a href="https://github.com/ogrodnek/pyview" target="_blank">https://github.com/ogrodnek/pyview</a>
# Installation
`pip install pyview-web`
## Quickstart
There's a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template available
```
cookiecutter gh:ogrodnek/pyview-cookiecutter
```
# Live Examples
[https://examples.pyview.rocks/](https://examples.pyview.rocks/)
## Other Examples
- [pyview AI chat](https://github.com/pyview/pyview-example-ai-chat)
- [pyview auth example](https://github.com/pyview/pyview-example-auth) (using [authlib](https://docs.authlib.org/en/latest/))
## Simple Counter
[See it live!](https://examples.pyview.rocks/count)
count.py:
```python
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:
```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](https://github.com/phoenixframework/phoenix_live_view), which is a wonderful paradigm and implementation. Besides using their ideas, we also directly use the LiveView JavaScript code.
- Thanks to [Donnie Flood](https://github.com/floodfx) for the encouragement, inspiration, help, and even pull requests to get this project started! Check out [LiveViewJS](https://github.com/floodfx/liveviewjs) for a TypeScript implementation of LiveView (that's much more mature than this one!)
- Thanks to [Darren Mulholland](https://github.com/dmulholl) for both his [Let's Build a Template Language](https://www.dmulholl.com/lets-build/a-template-language.html) tutorial, as well as his [ibis template engine](https://github.com/dmulholl/ibis), which he very generously released into the public domain, and forms the basis of templating in PyView.
## Additional Thanks
- We're using the [pubsub implementation from flet](https://github.com/flet-dev/flet)
- PyView is built on top of [Starlette](https://www.starlette.io/).
# 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](LICENSE).
Raw data
{
"_id": null,
"home_page": "https://pyview.rocks",
"name": "pyview-web",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.13,>=3.10",
"maintainer_email": null,
"keywords": "web, api, LiveView",
"author": "Larry Ogrodnek",
"author_email": "ogrodnek@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/67/3b/d5c529bdf546cd130438768c11dacd6f29c611f00e7eaa13530d1a07d64d/pyview_web-0.1.0.tar.gz",
"platform": null,
"description": "<img src=\"https://pyview.rocks/images/pyview_logo_512.png\" width=\"128px\" align=\"right\" />\n\n# PyView\n\n> A Python implementation of Phoenix LiveView\n\nPyView enables dynamic, real-time web apps, using server-rendered HTML.\n\n**Source Code**: <a href=\"https://github.com/ogrodnek/pyview\" target=\"_blank\">https://github.com/ogrodnek/pyview</a>\n\n# Installation\n\n`pip install pyview-web`\n\n## Quickstart\n\nThere's a [cookiecutter](https://github.com/cookiecutter/cookiecutter) template available\n\n```\ncookiecutter gh:ogrodnek/pyview-cookiecutter\n```\n\n# Live Examples\n\n[https://examples.pyview.rocks/](https://examples.pyview.rocks/)\n\n## Other Examples\n\n- [pyview AI chat](https://github.com/pyview/pyview-example-ai-chat)\n- [pyview auth example](https://github.com/pyview/pyview-example-auth) (using [authlib](https://docs.authlib.org/en/latest/))\n\n## Simple Counter\n\n[See it live!](https://examples.pyview.rocks/count)\n\ncount.py:\n\n```python\nfrom pyview import LiveView, LiveViewSocket\nfrom typing import TypedDict\n\n\nclass CountContext(TypedDict):\n count: int\n\n\nclass CountLiveView(LiveView[CountContext]):\n async def mount(self, socket: LiveViewSocket[CountContext], _session):\n socket.context = {\"count\": 0}\n\n async def handle_event(self, event, payload, socket: LiveViewSocket[CountContext]):\n if event == \"decrement\":\n socket.context[\"count\"] -= 1\n\n if event == \"increment\":\n socket.context[\"count\"] += 1\n\n async def handle_params(self, url, params, socket: LiveViewSocket[CountContext]):\n if \"c\" in params:\n socket.context[\"count\"] = int(params[\"c\"][0])\n```\n\ncount.html:\n\n```html\n<div>\n <h1>Count is {{count}}</h1>\n <button phx-click=\"decrement\">-</button>\n <button phx-click=\"increment\">+</button>\n</div>\n```\n\n# Acknowledgements\n\n- Obviously this project wouldn't exist without [Phoenix LiveView](https://github.com/phoenixframework/phoenix_live_view), which is a wonderful paradigm and implementation. Besides using their ideas, we also directly use the LiveView JavaScript code.\n- Thanks to [Donnie Flood](https://github.com/floodfx) for the encouragement, inspiration, help, and even pull requests to get this project started! Check out [LiveViewJS](https://github.com/floodfx/liveviewjs) for a TypeScript implementation of LiveView (that's much more mature than this one!)\n\n- Thanks to [Darren Mulholland](https://github.com/dmulholl) for both his [Let's Build a Template Language](https://www.dmulholl.com/lets-build/a-template-language.html) tutorial, as well as his [ibis template engine](https://github.com/dmulholl/ibis), which he very generously released into the public domain, and forms the basis of templating in PyView.\n\n## Additional Thanks\n\n- We're using the [pubsub implementation from flet](https://github.com/flet-dev/flet)\n- PyView is built on top of [Starlette](https://www.starlette.io/).\n\n# Status\n\nPyView 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.\n\n# Running the included Examples\n\n## Setup\n\n```\npoetry install\n```\n\n## Running\n\n```\npoetry run uvicorn examples.app:app --reload\n```\n\nThen go to http://localhost:8000/\n\n### Poetry Install\n\n```\nbrew install pipx\npipx install poetry\npipx ensurepath\n```\n\n(see https://python-poetry.org/docs/#installation for more details)\n\n# License\n\nPyView is licensed under the [MIT License](LICENSE).\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "LiveView in Python",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://pyview.rocks",
"Repository": "https://github.com/ogrodnek/pyview"
},
"split_keywords": [
"web",
" api",
" liveview"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "629c89974e1ffad31c2cfd106a69dc3c2a6d0e30ba6e1589ddcfe217e800fe1d",
"md5": "d9c0c8170c70c75c6bcd43594acb2432",
"sha256": "178856aa1caa04e3d3889ecc7ef9760db55e5ecd66c9a84fe49fbd915155d6e6"
},
"downloads": -1,
"filename": "pyview_web-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d9c0c8170c70c75c6bcd43594acb2432",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.13,>=3.10",
"size": 85876,
"upload_time": "2024-09-17T23:24:46",
"upload_time_iso_8601": "2024-09-17T23:24:46.734261Z",
"url": "https://files.pythonhosted.org/packages/62/9c/89974e1ffad31c2cfd106a69dc3c2a6d0e30ba6e1589ddcfe217e800fe1d/pyview_web-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "673bd5c529bdf546cd130438768c11dacd6f29c611f00e7eaa13530d1a07d64d",
"md5": "3396e07e89e3f1194580edb9bbdddc3a",
"sha256": "1aa5c1d9cf6b63fcda568464edd88d4520ec0ea19ab833f4df46464b6372a8bc"
},
"downloads": -1,
"filename": "pyview_web-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "3396e07e89e3f1194580edb9bbdddc3a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.13,>=3.10",
"size": 75871,
"upload_time": "2024-09-17T23:24:48",
"upload_time_iso_8601": "2024-09-17T23:24:48.107558Z",
"url": "https://files.pythonhosted.org/packages/67/3b/d5c529bdf546cd130438768c11dacd6f29c611f00e7eaa13530d1a07d64d/pyview_web-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-17 23:24:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ogrodnek",
"github_project": "pyview",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyview-web"
}