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.
<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 as State()
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 a dist/{component}/
folder with compiled .py
and .svelte
files.
compiler.build()
will create an app.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
.svelte
file of the component within App.svelte
and run npm run dev
as well as uv run python app.py
running the fastapi backend and see it in actionNote: When creating reactive State()
variables use python type annotation format variable: annotation = State(default_value)
otherwise compilation won't include such variables.
.fluid
files combining Python logic, HTML templates, and CSS stylesThis project is currently in early experimental development. The core features being implemented are:
Once stability is achieved, Fluidframe will follows this kind of application behaviour.