A Declarative DSL for Building Analytics Dashboards
DashSpec is a YAML-based domain-specific language (DSL) that transforms simple declarative specifications into rich, interactive Streamlit dashboards. Write dashboards in minutes, not hours.
# This 15-line spec generates a complete interactive dashboard
dsl_version: "1.3.0"
dashboard:
title: "Revenue Analytics"
data_source:
type: "parquet"
path: "data/sales.parquet"
pages:
- title: "Overview"
layout:
components:
- visualization:
chart_type: "line"
roles: { x: "date", y: "revenue", color: "region" }- 15+ visualization types: Line, bar, scatter, histogram, box, violin, heatmap, KDE, ECDF, and more
- Semantic role mapping: Use intuitive roles (
x,y,color,size,by) instead of plotting APIs - Multi-page layouts: Organize complex dashboards into logical sections
- Flexible grid system: Full-width, half-width, or custom component sizing
- Default formatting: Define formatting once, apply everywhere via inheritance
- Rich metadata: Dataset context, descriptions, and documentation built-in
- JSON Schema validation: Catch errors before rendering
- Version migration tools: Automatic upgrade from v1.2 → v1.3
8 pre-built dashboards across diverse domains demonstrate the DSL's capabilities:
| Domain | Dashboard | Dataset | Key Insights |
|---|---|---|---|
| 🛡️ Security | Fraud Detection | 284K credit card transactions | Anomaly patterns, class imbalance, feature importance |
| 🎵 Entertainment | Spotify Analytics | 114K tracks | Audio features, popularity trends, artist analysis |
| 🌍 Environmental | Air Quality | 1.7M AQI readings | Pollutant distributions, geographic patterns, temporal trends |
| 🛒 E-commerce | Amazon Reviews | 568K reviews | Rating patterns, helpfulness analysis, sentiment insights |
| 👔 HR Analytics | Employee Attrition | 1.5K employees | Retention factors, satisfaction drivers, compensation analysis |
| 🚗 Transportation | US Accidents | 7.7M accidents | Severity patterns, weather impact, geographic hotspots |
| 🎬 Media | TMDB Movies | 4.8K films | Box office trends, genre profitability, rating distributions |
| 🔒 Cybersecurity | Network Intrusion | 47K connections | Traffic analysis, protocol patterns, attack detection |
# Clone the repository
git clone <repository-url>
cd dashspec
# Install dependencies
pip install -r requirements.txt# Option 1: Dashboard gallery (browse all dashboards)
streamlit run app.py
# Option 2: Single dashboard
streamlit run run_dashboard.py -- dsl/examples/fraud_detection.yaml
# Option 3: Use make shortcuts
make dashboard-gallery # Gallery view
make dashboard-fraud # Fraud detection
make dashboard-spotify # Spotify analytics
make help # See all optionsCreate a YAML file in dsl/examples/:
dsl_version: "1.3.0"
dashboard:
id: "my_analysis"
title: "My Data Analysis"
metadata:
dataset_name: "My Dataset"
description: "Insightful analysis of my data"
# Optional: Define default formatting for all visualizations
default_formatting:
numeric:
format: ",.2f"
currency:
format: "$,.0f"
data_source:
type: "parquet"
path: "data/processed/my_data.parquet"
pages:
- id: "overview"
title: "Overview"
layout:
type: "grid"
components:
# Line chart
- id: "trend"
type: "visualization"
title: "Trend Over Time"
width: "full"
visualization:
chart_type: "line"
roles:
x: "date"
y: "value"
color: "category"
# Histogram
- id: "distribution"
type: "visualization"
title: "Value Distribution"
width: "half"
visualization:
chart_type: "histogram"
roles:
x: "value"
config:
bins: 30
# Scatter plot
- id: "correlation"
type: "visualization"
title: "Feature Correlation"
width: "half"
visualization:
chart_type: "scatter"
roles:
x: "feature1"
y: "feature2"
color: "category"
size: "importance"Then run:
streamlit run run_dashboard.py -- dsl/examples/my_analysis.yamlhistogram: Frequency distributions with customizable binskde: Kernel density estimation for smooth distributionsecdf: Empirical cumulative distribution functionsbox: Box plots for quartile analysisviolin: Combined box plot and KDE
scatter: Bivariate relationships with color/size encodingline: Time series and trend analysisheatmap: Correlation matrices and 2D density
bar: Categorical comparisons (vertical)barh: Horizontal bar chartscount: Frequency counts by category
table: Interactive data tables with search/sortsummary_statistics: Automated statistical summaries
facet_grid: Small multiples by category- Multiple charts per dashboard with flexible layouts
Instead of specifying plotting parameters, DashSpec uses semantic roles:
roles:
x: "date" # X-axis variable
y: "revenue" # Y-axis variable
color: "region" # Color encoding
size: "population" # Size encoding (scatter plots)
by: "category" # Faceting/grouping variableDefine formatting once at the dashboard level, automatically inherited by all visualizations:
default_formatting:
numeric:
format: ",.2f" # Thousands separator, 2 decimals
percentage:
format: ".1%" # Percentage with 1 decimal
currency:
format: "$,.0f" # Currency with no decimals
date:
format: "%Y-%m-%d" # ISO date formatOverride at the field level when needed:
visualization:
chart_type: "bar"
roles:
x: "product"
y: "profit"
field_formats:
profit:
format: "$,.2f" # Override default currency formatOrganize complex analyses into logical sections:
pages:
- id: "overview"
title: "Executive Summary"
layout:
components: [...]
- id: "details"
title: "Detailed Analysis"
layout:
components: [...]
- id: "methodology"
title: "Data & Methods"
layout:
components: [...]DashSpec includes an ETL pipeline for processing Kaggle datasets:
# Configure Kaggle API (see docs/etl_pipeline_guide.md)
# ~/.kaggle/kaggle.json
# Process all datasets
python run_etl.py
# Process specific datasets
python run_etl.py --datasets credit_card_fraud spotify_tracks
# Use deployment config with sampling
python run_etl.py --config config/datasets_deploy.yaml
# Inspect processed data
python inspect_datasets.py --list
python inspect_datasets.py --show credit_card_fraud- Automated downloads from Kaggle
- Smart transformations: Column standardization, missing value handling, type optimization
- Data profiling: Comprehensive statistics and quality metrics
- Efficient storage: Parquet format with Snappy compression
- Deployment sampling: Configurable sampling strategies for cloud deployment
dashspec/
├── dsl/
│ ├── examples/ # 14 dashboard specifications
│ ├── schemas/ # JSON schemas (v1.0, v1.1, v1.2, v1.3)
│ ├── core/ # DSL core (parser, validators)
│ └── renderers/ # Rendering engines
│ └── streamlit/ # Streamlit renderer
├── etl/ # ETL pipeline modules
│ ├── config.py # Configuration models
│ ├── extractor.py # Kaggle downloader
│ ├── transformer.py # Data transformations
│ ├── sampler.py # Sampling strategies
│ ├── loader.py # Parquet writer
│ └── pipeline.py # Pipeline orchestrator
├── config/
│ ├── datasets.yaml # Full dataset configuration
│ └── datasets_deploy.yaml # Deployment config with sampling
├── data/
│ ├── processed/ # Parquet files (122MB)
│ └── metadata/ # Dataset metadata
├── app.py # Dashboard gallery
├── run_dashboard.py # Single dashboard runner
├── run_etl.py # ETL pipeline runner
└── tests/ # Test suite
- DSL Guide: Complete DSL reference with examples
- ETL Pipeline Guide: Data processing workflow
- Migration Guide: Upgrading dashboards to v1.3
- Data Sources: Available datasets and descriptions
Validate dashboard specs before rendering:
python -c "from dsl.core.validators import validate_dashboard_spec; \
validate_dashboard_spec('dsl/examples/my_dashboard.yaml')"Upgrade v1.2 dashboards to v1.3 with default formatting:
python scripts/migrate_v1.2_to_v1.3.py dsl/examples/old_dashboard.yamlDashSpec's modular architecture allows custom rendering backends:
from dsl.core.parser import DashboardParser
from dsl.renderers.streamlit.renderer import StreamlitRenderer
# Parse dashboard spec
parser = DashboardParser()
dashboard_ir = parser.parse("my_dashboard.yaml")
# Render with Streamlit
renderer = StreamlitRenderer()
renderer.render(dashboard_ir)See fraud_detection.yaml for a production-ready example featuring:
- Multi-page layout (Overview, Patterns, Correlations)
- 8 different visualization types
- Default formatting with field-level overrides
- Rich metadata and documentation
- Advanced chart configurations
# Run all tests
make test
# Run specific test suites
pytest tests/test_dsl_v13.py # DSL v1.3 tests
pytest tests/test_formatting.py # Formatting tests
pytest tests/test_dashboards_v13.py # Dashboard integration tests
# Run with coverage
make test-coverageReady for Streamlit Cloud deployment:
- 122MB processed data (sampled for cloud limits)
- Streamlit configuration included (
.streamlit/config.toml) - Requirements.txt with pinned versions
- No external dependencies beyond Python packages
Contributions welcome! Areas of interest:
- New visualization types
- Additional rendering backends (Plotly Dash, Bokeh, etc.)
- Enhanced validation and error messages
- Dashboard templates for specific domains
See LICENSE for details.
Built with: Python 3.11+ • Streamlit • Pandas • Plotly • Pydantic