Skip to content

Commit cd8fb83

Browse files
committed
init commit
0 parents  commit cd8fb83

33 files changed

Lines changed: 3059 additions & 0 deletions

.github/workflows/playwright.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v5
13+
- name: Set up Python
14+
uses: actions/setup-python@v6
15+
with:
16+
python-version: '3.12'
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt
21+
- name: Ensure browsers are installed
22+
run: python -m playwright install --with-deps
23+
- name: Run your tests
24+
run: pytest tests/*.py -v
25+
- uses: actions/upload-artifact@v4
26+
if: ${{ !cancelled() }}
27+
with:
28+
name: playwright-traces
29+
path: test-results/

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# Virtual environments
10+
.venv

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# HTMX Examples
2+
3+
This repository demonstrates how to build modern, dynamic user interfaces using **HTMX** with a **FastAPI** backend in Python 3.12.6.
4+
Instead of relying on JSON APIs and heavy JavaScript, this project follows the **Hypermedia-Driven Application (HDA)** architecture: the backend sends HTML fragments directly, and HTMX handles DOM updates seamlessly.
5+
6+
## 🛠️ Tech Stack
7+
8+
- **Backend**: [FastAPI](https://fastapi.tiangolo.com/) (Python) and [Jinja2](https://jinja.palletsprojects.com/) as template engine
9+
- **Frontend**: [HTMX](https://htmx.org/) with plain HTML, [Pico CSS](https://picocss.com/) and some [_hyperscript](https://hyperscript.org/)
10+
- **Testing**: [Playwright](https://playwright.dev/python/) for end-to-end tests
11+
- **Data Source**: [Random User API](https://randomuser.me/api/)
12+
13+
All frontend dependencies are loaded directly from `index.html` via `<script>` tags.
14+
15+
## ▶️ Running the App
16+
17+
Install dependencies and start the development server:
18+
19+
python -m venv ./venv
20+
source ./venv/bin/activate
21+
22+
pip install -r requirements.txt
23+
uvicorn main:app --reload
24+
25+
App is reachable under: `http://127.0.0.1:8000/`
26+
Swagger: `http://127.0.0.1:8000/docs`
27+
Redoc: `http://127.0.0.1:8000/redoc`
28+
29+
## 🧪 Run tests
30+
31+
For tests, user data is loaded from `user_data.json` instead of being fetched from `randomuser.me`.
32+
33+
All tests:
34+
35+
pytest tests/*.py -v
36+
37+
Run a specific test:
38+
39+
pytest tests/test_htmx_form.py -v
40+
pytest tests/test_htmx_scrolling.py -v
41+
pytest tests/test_htmx_stream.py -v
42+
pytest tests/test_htmx_table.py -v
43+
44+
## 🌟 Examples
45+
All examples fetch user data from [https://randomuser.me/api/](https://randomuser.me/api/).
46+
47+
### Data Table
48+
Dynamically load and display user data in a responsive table.
49+
Some _hyperscript is used to handle HTML form validation. Sweetalert2 is used to confirm a deletion.
50+
51+
![data table screenshot](./screenshots/data-table.png "Data Table Screenshot")
52+
![data table add screenshot](./screenshots/data-table-add.png "Data Table Add Screenshot")
53+
![data table delete screenshot](./screenshots/data-table-delete.png "Data Table Delete Screenshot")
54+
55+
### Form Handling
56+
Submit and validate forms without page reloads.
57+
Some JavaScript is used to handle HTML form validation.
58+
59+
![form step 1 screenshot](./screenshots/form-step1.png "Form Step 1 Screenshot")
60+
![form step 2 screenshot](./screenshots/form-step2.png "Form Step 2 Screenshot")
61+
![form success screenshot](./screenshots/form-success.png "Form Success Screenshot")
62+
63+
### Server-Sent Events (SSE) Streaming
64+
Real-time updates via HTMX streams.
65+
Good way to get data pushed from the server for interaction websockets needs to be used.
66+
67+
![stream screenshot](./screenshots/stream.png "Stream Screenshot")
68+
69+
### Infinite Scrolling
70+
Load additional content as the user scrolls.
71+
A typincal thing while consuming content to scroll over endless entries.
72+
73+
![scrolling screenshot](./screenshots/scrolling.png "Scrolling Screenshot")
74+
75+
## 💬 Feedback
76+
Star this repo if you found it useful. Use the github issue tracker to give feedback on this repo.

0 commit comments

Comments
 (0)