Skip to content

[FEATURE] Add --template Option to preswald init for Pre-Built App Templates #524

@amrutha97

Description

@amrutha97

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

  • Add --template <template-name> option to preswald init
  • Supported templates:
    • default: basic text() component and scaffold (current behavior)
    • csv-dashboard: Table + plot + slider using a sample CSV
    • geojson-map: Load GeoJSON and render with geo()
    • time-series: Line chart + filter slider
    • comparison: Two plots with shared filters
  • Place template contents in preswald/templates/<template-name>/
  • Automatically copy files into <project_name> dir:
    • hello.py
    • preswald.toml
    • secrets.toml
    • data/ and images/ as needed
  • Provide a helpful error message if template doesn't exist
  • Update preswald --help to list available templates

🛠 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

  • CLI Reference → preswald init
  • Quickstart → Mention templates
  • Add template previews to website/docs

🔮 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions