PyHAT-stack / web-async-patterns

This repo shows patterns you can use to elevate Python web apps via streaming HTML and htmx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proof of concept: Streaming HTML with Python

Inspired by Taylor Hunt's incredible explanation of how he turned a slow Fortune 20 webapp into a snappy experience, even on a cheap Android phone, I made this repo to show the current capability of Django to render streaming HTML.

This technique is best used to improve the perceptual performance for expensive database queries or slow API calls. The idea is that the user could start seeing the page come together while the query or calls are happening. Rendering of the page will pause once it hits the block that is waiting on the data, but being able to see the page render should make the user feel as though the website is performing faster.

Referencing Taylor's blog post:

Both of these pages show search results in 2.5 seconds. But they sure don't feel the same.

This concept shows how a recommendation engine takes some time to recommend four products, based for the current user.

Viewing the concept

Open a terminal at the root of this project and type the following:

python -m venv .venv --prompt stream_python
# If in Windows:
.venv/Scripts/activate
# otherwise
source .venv/bin/
# Then
pip install -r requirements.txt
uvicorn stream.asgi:application --reload 

You can then click the link in the terminal or go to http://127.0.0.1:8000 to view the page.

Thanks

Thanks to https://github.com/fajar7xx/ecommerce-template-tailwind-1 for the HTML template.

About

This repo shows patterns you can use to elevate Python web apps via streaming HTML and htmx


Languages

Language:HTML 74.0%Language:JavaScript 13.1%Language:Python 12.9%