Goal
Improve the preswald init CLI command to accept a --template flag that lets users choose from a set of curated app templates. Each template bootstraps a different type of Preswald project with example hello.py, preswald.toml, and mock data files tailored to a use case (e.g., CSV dashboard, GeoJSON map, time-series plot, etc).
📌 Motivation
Currently, preswald init <project_name> scaffolds a single generic app with a basic hello.py. This is great for minimalism but misses an opportunity to help new users get started with more realistic examples.
Adding a --template flag will:
- Let users pick a template suited for their data or use case
- Showcase Preswald’s full capability right from the start
- Cut down the time it takes to build a working data app
- Turn the CLI into an educational onboarding tool
✅ Acceptance Criteria
🛠 Implementation Plan
1. Update CLI: preswald/cli.py
@app.command("init")
def init(project_name: str, template: str = "default"):
from preswald.engine.init import scaffold_project
scaffold_project(project_name, template)
2. Template Folder Structure
preswald/
templates/
default/
hello.py
preswald.toml
csv-dashboard/
hello.py
preswald.toml
data/sample.csv
geojson-map/
hello.py
preswald.toml
data/map.geojson
...
3. In init.py:
def scaffold_project(project_name, template="default"):
import shutil
template_path = Path(__file__).parent / "templates" / template
if not template_path.exists():
raise Exception(f"Template '{template}' not found.")
shutil.copytree(template_path, project_name)
print(f"✅ Project initialized with '{template}' template in ./{project_name}")
🧪 Example Usage
preswald init sales_dashboard --template csv-dashboard
preswald init earthquake_map --template geojson-map
preswald init basic_app --template default
📄 Example: csv-dashboard/hello.py
from preswald import connect, get_df, slider, table, plotly, text
import plotly.express as px
text("# Sales Dashboard")
connect()
df = get_df("sample_csv")
threshold = slider("Min Quantity", min_val=0, max_val=100, default=10)
filtered = df[df["quantity"] > threshold]
fig = px.bar(filtered, x="product", y="quantity")
plotly(fig)
table(filtered)
📚 Docs To Update
🔮 Future Ideas
- Add
preswald template list to enumerate templates
- Allow remote templates (
--template-url)
- Community-contributed template registry
preswald template publish to create shareable blueprints
Goal
Improve the
preswald initCLI command to accept a--templateflag that lets users choose from a set of curated app templates. Each template bootstraps a different type of Preswald project with examplehello.py,preswald.toml, and mock data files tailored to a use case (e.g., CSV dashboard, GeoJSON map, time-series plot, etc).📌 Motivation
Currently,
preswald init <project_name>scaffolds a single generic app with a basichello.py. This is great for minimalism but misses an opportunity to help new users get started with more realistic examples.Adding a
--templateflag will:✅ Acceptance Criteria
--template <template-name>option topreswald initdefault: basictext()component and scaffold (current behavior)csv-dashboard: Table + plot + slider using a sample CSVgeojson-map: Load GeoJSON and render withgeo()time-series: Line chart + filter slidercomparison: Two plots with shared filterspreswald/templates/<template-name>/<project_name>dir:hello.pypreswald.tomlsecrets.tomldata/andimages/as neededpreswald --helpto list available templates🛠 Implementation Plan
1. Update CLI:
preswald/cli.py2. Template Folder Structure
3. In
init.py:🧪 Example Usage
📄 Example:
csv-dashboard/hello.py📚 Docs To Update
preswald init🔮 Future Ideas
preswald template listto enumerate templates--template-url)preswald template publishto create shareable blueprints