Responsive server components in Python
Project description
falk
falk is a Python based web framework for responsive server components. falk components hold their state cryptographically signed on the client side. This makes the server fully stateless and easy to scale.
falk components can contain business logic, HTML markup, external and inline stylesheets and scripts, can communicate with the server over HTTP REST or websockets.
Demo
# pip install uvicorn[websocket] falk
# uvicorn --app-dir=./ demo:app
from falk.components import HTML5Base
from falk.asgi import get_asgi_app
def Counter(initial_render, props, state, add_callback):
# initialize state object
if initial_render:
state.update({
"count": props.get("initial_value", 0),
})
# this callback gets called when the button is clicked
# (callbacks can be sync or async)
def increment(args):
state["count"] += args[0]
add_callback(increment)
return """
<button onclick="{{ falk.run_callback('increment', [1]) }}">
Count: <strong>{{ state.count }}</strong>
</button>
"""
def Index(HTML5Base=HTML5Base, Counter=Counter):
return """
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<style>
.container {
margin: 0 auto;
margin-top: 2em;
}
button {
padding: 5px 10px;
margin-bottom: 10px;
}
</style>
<HTML5Base title="falk Hello World">
<div class="container">
<h1>falk Hello World</h1>
{% for i in range(5) %}
<Counter initial_value="{{ i }}" />
<br/>
{% endfor %}
</div>
</HTML5Base>
"""
def configure_app(set_setting, add_route):
set_setting("debug", True)
add_route("/", Index)
app = get_asgi_app(configure_app)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file falk-0.7.2.tar.gz.
File metadata
- Download URL: falk-0.7.2.tar.gz
- Upload date:
- Size: 232.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af37216700a972561a5cd49b688cb667b4953d58f715d2b4fe19af62c46ff5fa
|
|
| MD5 |
1c5af85d20dd98a4630ca157199fedb8
|
|
| BLAKE2b-256 |
262cbd57c2e12c9dc02dc1245d02c303ad5130cf6e0b72e5f171304819d0d00b
|
File details
Details for the file falk-0.7.2-py3-none-any.whl.
File metadata
- Download URL: falk-0.7.2-py3-none-any.whl
- Upload date:
- Size: 94.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5673be20e482bcf637cbd84acbc642ab56ddddc639558ebe25068688d28c1d59
|
|
| MD5 |
c5aa952d2ea894c921783b59fc3ea167
|
|
| BLAKE2b-256 |
8ee7713cee6320386908e6e06d570d606b0174808ab5fe648ff32881773d3cf9
|