Dars is a Python UI framework for building modern, interactive web apps with only Python code. Write your interface in Python, export it to static HTML/CSS/JS, and deploy anywhere.
Project description
Dars Framework
Dars is a multiplatform Python UI framework for building modern, interactive web and desktop apps with Python code. Write your interface in Python, export it to web technologies and deploy anywhere.
pip install dars-framework
Some Javascript and css stack required for advanced personalization.
Try dars without installing nothing(single page mode) just visit the Dars Playground
How It Works
- Build your UI using Python classes and components (like Text, Button, Container, Page, etc).
- Preview instantly with hot-reload using
app.rTimeCompile(). - Export your app to static web files with a single CLI command.
- Export to native desktop apps (BETA) using project config
format: "desktop"anddars build. - Use multipage, layouts, scripts, and more—see docs for advanced features.
- For more information visit the Documentation
Quick Example: Your First App
from dars.all import *
app = App(title="Hello World", theme="dark")
index = Page(
Text(
text="Hello World",
style={
'font-size': '48px',
'color': '#2c3e50',
'margin-bottom': '20px',
'font-weight': 'bold',
'text-align': 'center'
}
),
Text(
text="Hello World",
style={
'font-size': '20px',
'color': '#7f8c8d',
'margin-bottom': '40px',
'text-align': 'center'
}
),
Button(
text="Click Me!",
on_click= alert('Hello from DARS!'),
style={
'background-color': '#3498db',
'color': 'white',
'padding': '15px 30px',
'border': 'none',
'border-radius': '8px',
'font-size': '18px',
'cursor': 'pointer',
'transition': 'background-color 0.3s'
}
),
style={
'display': 'flex',
'flex-direction': 'column',
'align-items': 'center',
'justify-content': 'center',
'min-height': '100vh',
'background-color': '#f0f2f5',
'font-family': 'Arial, sans-serif'
}
)
app.add_page("index", index, title="Hello World", index=True)
if __name__ == "__main__":
app.rTimeCompile()
Modern State Management (State V2)
Dars Framework includes a pure state management system that makes building reactive UIs simple and intuitive. No verbose syntax - just clean Python code.
Quick Start
from dars.all import *
# Create a component
display = Text("0", id="counter")
# Create state with default values
counter = State(display, text=0)
# Use reactive operations
increment_btn = Button("+1", on_click=counter.text.increment(by=1))
decrement_btn = Button("-1", on_click=counter.text.decrement(by=1))
reset_btn = Button("Reset", on_click=counter.reset())
Core Reactive Operations
All Property Types Supported:
State V2 can update any component property: text, html, style, class_name, attrs.
Increment/Decrement (numeric props only):
counter.text.increment(by=1) # Increase by 1
counter.text.decrement(by=1) # Decrease by 1
Set Any Property:
counter.text.set(value=100) # Set text
counter.class_name.set("active") # Set CSS class
counter.style.set({"color": "red"}) # Set styles
counter.attrs.set({"title": "Info"}) # Set attributes
Update Multiple Properties:
state.update(
text="Done!",
class_name="success",
style={"color": "green"}
)
Auto Operations (Continuous):
# Auto-increment every second
timer.text.auto_increment(by=1, interval=1000)
# Stop auto operation
timer.text.stop_auto()
Reset to Defaults:
state.reset() # Restore all properties to initial values
Auto-Incrementing Timer Example
from dars.all import *
app = App("Timer Demo")
# Create timer display
timer_display = Text("0", id="timer", style={"font-size": "36px"})
timer = State(timer_display, text=0)
# Control buttons
start_btn = Button("Start", on_click=timer.text.auto_increment(by=1, interval=1000))
stop_btn = Button("Stop", on_click=timer.text.stop_auto())
reset_btn = Button("Reset", on_click=timer.reset())
page = Page(Container(timer_display, start_btn, stop_btn, reset_btn))
app.add_page("index", page, index=True)
Animation System
Dars includes 15+ built-in animations that integrate seamlessly with state management:
Basic Animations:
from dars.all import fadeIn, fadeOut, pulse, shake, sequence
# Single animation
button.on_click = fadeIn(id="element", duration=500)
# Chained animations
button.on_click = sequence(
fadeIn(id="box", duration=400),
pulse(id="box", scale=1.2, iterations=2),
shake(id="box", intensity=5)
)
Available Animations:
- Opacity:
fadeIn,fadeOut - Movement:
slideIn,slideOut(8 directions) - Scaling:
scaleIn,scaleOut - Interactive:
shake,bounce,pulse,rotate,flip - Effects:
colorChange,morphSize
Combining State & Animations:
button.on_click = sequence(
counter.text.increment(by=1),
pulse(id="counter", scale=1.2),
fadeOut(id="counter", duration=200),
counter.text.set(value=0),
fadeIn(id="counter", duration=200)
)
Dynamic Updates with this()
Update components directly without pre-defining states:
from dars.all import *
# Self-updating button
btn = Button("Click Me!", on_click=this().state(
text="Clicked!",
style={"background-color": "green"}
))
# With animations
btn = Button("Pulse", on_click=[
pulse(id="btn", scale=1.1),
this().state(text="Done!")
])
Script Chaining with .then()
Chain asynchronous operations using .then():
from dars.all import *
from dars.scripts.dscript import RawJS, dScript
# Chain file read with state update
read_btn = Button("Load", on_click=
read_text("data.txt").then(
this().state(text=RawJS(dScript.ARG))
)
)
# Multi-step chain
button.on_click = sequence(
fadeOut(id="status"),
state.text.set(value="Loading...")
).then(
fadeIn(id="status")
).then(
this().state(text="Complete!")
)
New State V2 docs here: State V2
SPA Routing System
Dars 1.4.6 introduces a powerful client-side routing system for Single Page Applications:
Basic Routing
Use the @route decorator or route parameter to create SPA routes:
from dars.all import *
app = App(title="My SPA")
# Using decorator
@route("/")
def home():
return Page(Text("Home Page"))
# Using parameter
about_page = Page(Text("About Us"))
app.add_page("about", about_page, route="/about")
app.add_page("home", home())
Nested Routes with Outlet
Create complex layouts with parent-child routes using the Outlet component:
# Parent layout with navigation
@route("/dashboard")
def dashboard():
return Page(
Text("Dashboard", style={"fontSize": "24px"}),
Container(
Link("Settings", href="/dashboard/settings"),
Link("Profile", href="/dashboard/profile"),
id="nav",
),
Outlet(), # Child routes render here
style={"padding": "20px"}
)
# Child routes
settings_page = Page(Text("Settings Content"))
profile_page = Page(Text("Profile Content"))
# NOTE if you don't assign index=True to one of the pages when using more than 1 page with SPA route system
# you get a 404 error because the router doesn't knwow the index page and cannot assign it as index.
# this is probably going to be fixed in next updates
app.add_page("dashboard", dashboard(), index=True)
app.add_page("settings", settings_page, route="/dashboard/settings", parent="dashboard")
app.add_page("profile", profile_page, route="/dashboard/profile", parent="dashboard")
404 Error Handling
Dars automatically handles 404 errors with a default page, or you can customize it:
# Custom 404 page
custom_404 = Page(
Text("Oops! Page not found", style={"fontSize": "32px", "color": "red"}),
Link("Go Home", href="/")
)
app.set_404_page(custom_404)
Hot Reload for SPAs
The development preview server includes intelligent hot reload:
- Detects changes and reloads automatically
- Stops polling after 10 errors to prevent browser lag
- Clean console output without spam
CLI Usage
| Command | What it does |
|---|---|
dars export my_app.py --format html |
Export app to HTML/CSS/JS in ./my_app_web |
dars init --type desktop |
Scaffold desktop-capable project (BETA) |
dars build (desktop config) |
Build desktop app artifacts (BETA) |
dars preview ./my_app_web |
Preview exported app locally |
dars init my_project |
Create a new Dars project (also creates dars.config.json) |
dars init --update |
Create/Update dars.config.json in current dir |
dars build |
Build using dars.config.json (entry/outdir/format) |
dars config validate |
Validate dars.config.json and print report |
dars info my_app.py |
Show info about your app |
dars formats |
List supported export formats |
dars --help |
Show help and all CLI options |
Tip: use dars doctor to review optional tooling that can enhance bundling/minification.
Desktop Export (BETA)
- Mark your project for desktop in
dars.config.jsonwith"format": "desktop". - Initialize backend scaffolding with
dars init --type desktop(or--update). - Build with
dars buildto produce desktop artifacts underdist/. - This feature is in BETA: usable for testing, not yet recommended for production.
- Visit dars official website
- Visit the dars official Documentation now on separate website.
- Try dars without installing nothing just visit the Dars Playground
Local Execution and Live Preview
To test your app locally before exporting, use the hot-reload preview from any Python file that defines your app:
if __name__ == "__main__":
app.rTimeCompile()
Then run your file directly:
python my_app.py
This will start a local server at http://localhost:8000 so you can view your app in the browser—no manual export needed. You can change the port with:
python my_app.py --port 8088
You can also use the CLI preview command on an exported app:
dars preview ./my_exported_app
This will start a local server at http://localhost:8000 to view your exported app in the browser.
Project Configuration (dars.config.json)
Dars can read build/export settings from a dars.config.json at your project root. It is created automatically by dars init, and you can add it to existing projects with dars init --update.
Example default:
{
"entry": "main.py",
"format": "html",
"outdir": "dist",
"publicDir": null,
"include": [],
"exclude": ["**/__pycache__", ".git", ".venv", "node_modules"],
"bundle": true,
"defaultMinify": true,
"viteMinify": true
}
entry: Python entry file. Used bydars buildanddars export config.format: Export format. Currently onlyhtmlis supported.outdir: Output directory. Used bydars buildand default fordars exportwhen not overridden.publicDir: Folder (e.g.,public/orassets/) copied into the output. If null, it is autodetected.include/exclude: Basic filters for copying frompublicDir.bundle: Reserved for future use. CLI exports and build already bundle appropriately.defaultMinify: Toggle the built-in Python minifier (safe, conservatively preserves<pre>,<code>,script,style,textarea). Controls HTML minification and provides JS/CSS fallback when advanced tools are unavailable. Defaulttrue.viteMinify: Toggle the Vite/esbuild minifier for JS/CSS. Defaulttrue.
Validate your config:
dars config validate
Build using config:
dars build
Export using the config entry and outdir:
dars export config --format html
See LandingPage docs for details: state_management.md, events.md, scripts.md, routing.md.
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 Distributions
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 dars_framework-1.4.9-py3-none-any.whl.
File metadata
- Download URL: dars_framework-1.4.9-py3-none-any.whl
- Upload date:
- Size: 831.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0459914931abeb13a770691611d0f30d724e040bc87e61dfe9310119bd5e3223
|
|
| MD5 |
a604462d8b2744581a7af3646a1caa62
|
|
| BLAKE2b-256 |
f09b29209eb20d4d642d61ba7c7a5475eb99367eb61dbe033e8fef26614422c0
|