FluidSvelte is an experimental Python-based full-stack web framework that unifies frontend and backend development using a component-based approach inspired by Svelte to extend developments of Fluidframe. It allows developers to write full-stack components in a single file using Python, HTML, CSS and optional Javascript/Typescript.
- Single-file components with Python, HTML, and CSS
- Fine-grained reactivity system similar to Svelte 5's runes
- Automatic compilation of components into Python backend and Svelte frontend code
- Seamless state synchronization between frontend and backend
- Type-safe communication using Protocol Buffers
- gRPC-based client-server communication
<script type="python">
count: int = State(0)
def increment():
nonlocal count
count += 1
def decrement():
nonlocal count
count -= 1
</script>
<button onclick={increment}>Increment</button>
<p>The count is: {count}</p>
<button onclick={decrement}>Decrement</button>
<style>
p {
color: #ffffff;
font-size: 1rem;
}
</style>
-
Clone the library and install dependencies using astral uv with
uv sync
-
create a
.fluid
file for example (currently only supports equivalent of$state
rune from svelte asState()
in python parallel with basic data types such as numbers, strings and booleans) -
Try running
test.py
file by providing the.fluid
component name and it will create adist/{component}/
folder with compiled.py
and.svelte
files. -
compiler.build()
will create anapp.py
backend server which binds the functional routes to the server -
Run the generated app.py and use the generated
.svelte
component file within a svelte app as component (will later be combined together to be served completely from python itself)For creating a svelte app use
npm
and the following commands:npm create vite@latest <project_name> -- --template svelte
cd <project_name>
npm install
- Use the fluidsvelte compiler generated
.svelte
file of the component withinApp.svelte
and runnpm run dev
as well asuv run python app.py
running the fastapi backend and see it in action
Note: When creating reactive State()
variables use python type annotation format variable: annotation = State(default_value)
otherwise compilation won't include such variables.
- Write components in
.fluid
files combining Python logic, HTML templates, and CSS styles - The Fluid compiler processes these files to generate:
- Python backend code for business logic
- Svelte frontend components for UI
- Protocol Buffer definitions for type-safe communication (Not implemented)
- Frontend interactions trigger gRPC calls to the backend (currently uses http post requests instead)
- State updates are controlled by backend with python logic and state lives in frontend
- Frontend: Svelte 5 with runes for reactivity
- Backend: Python with gRPC server
- Communication: Protocol Buffers and gRPC
- Component Compiler: Python AST-based parser and code generator
This project is currently in early experimental development. The core features being implemented are:
- Basic component compiler
- State management system
- gRPC communication layer (http communication layer currently)
- Code generation for Python and Svelte
Once stability is achieved, Fluidframe will follows this kind of application behaviour.