Cwprep

Created By
imgwho2 months ago
ai generate tableau prep file
Overview

cwprep - Text-to-PrepFlow Engine

cwprep is a Python-based engine that enables Text-to-PrepFlow generation.

By reverse-engineering the .tfl JSON structure and providing a built-in MCP (Model Context Protocol) server, cwprep acts as a bridge between LLMs (like Claude, Gemini) and Tableau Prep. You can now generate, modify, and build data cleaning flows simply through natural language conversations or Python scripts, without ever opening the GUI!

Author: Cooper Wenhua <imgwho@gmail.com>

Installation

pip install cwprep

Quick Start

from cwprep import TFLBuilder, TFLPackager

# Create builder
builder = TFLBuilder(flow_name="My Flow")

# Add database connection
conn_id = builder.add_connection(
    host="localhost",
    username="root",
    dbname="mydb"
)

# Add input tables
orders = builder.add_input_table("orders", "orders", conn_id)
customers = builder.add_input_table("customers", "customers", conn_id)

# Join tables
joined = builder.add_join(
    name="Orders + Customers",
    left_id=orders,
    right_id=customers,
    left_col="customer_id",
    right_col="customer_id",
    join_type="left"
)

# Add output
builder.add_output_server("Output", joined, "My_Datasource")

# Build and save
flow, display, meta = builder.build()
TFLPackager.save_tfl("./my_flow.tfl", flow, display, meta)

By default, both the SDK and MCP output only the final .tfl/.tflx archive. Use save_to_folder() only when you explicitly want the exploded folder for inspection.

Features

FeatureMethodDescription
Database Connectionadd_connection()Connect to MySQL/PostgreSQL/SQL Server
File Connectionadd_file_connection()Connect to Excel (.xlsx/.xls) or CSV files
SQL Inputadd_input_sql()Custom SQL query input
Table Inputadd_input_table()Direct table connection
Excel Inputadd_input_excel()Read from Excel worksheet
CSV Inputadd_input_csv()Read from CSV file
CSV Unionadd_input_csv_union()Merge multiple CSV files
Joinadd_join()left/right/inner/full joins (single or multi-column)
Unionadd_union()Merge multiple tables
Filteradd_filter()Expression-based filter
Value Filteradd_value_filter()Keep/exclude by values
Keep Onlyadd_keep_only()Select columns
Remove Columnsadd_remove_columns()Drop columns
Renameadd_rename()Rename columns
Calculationadd_calculation()Tableau formula fields
Quick Calcadd_quick_calc()Quick clean (lowercase/uppercase/trim/remove)
Change Typeadd_change_type()Change column data types
Duplicate Columnadd_duplicate_column()Duplicate (copy) a column
Aggregateadd_aggregate()GROUP BY with SUM/AVG/COUNT
Pivotadd_pivot()Rows to columns
Unpivotadd_unpivot()Columns to rows
Outputadd_output_server()Publish to Tableau Server
TFLX Packagingbuild(is_packaged=True)Generate .tflx with embedded data files
SQL TranslationSQLTranslatorTranslate TFL flows to equivalent ANSI SQL

Examples

See the examples/ directory for complete demos:

  • demo_basic.py - Input, Join, Output
  • demo_cleaning.py - Filter, Calculate, Rename
  • demo_field_operations.py - Quick Calc, Change Type, Duplicate Column
  • demo_aggregation.py - Union, Aggregate, Pivot
  • demo_comprehensive.py - All features combined
  • prompts.md - 8 ready-to-use MCP prompt templates for AI-driven flow generation

MCP Server

cwprep includes a built-in Model Context Protocol server, enabling AI clients (Claude Desktop, Cursor, Gemini CLI, etc.) to generate TFL files directly.

Prerequisites

MethodRequirement
uvx (recommended)Install uv — it auto-downloads cwprep[mcp] in an isolated env
pip installPython ≥ 3.8 + pip install cwprep[mcp]

Quick Start

# Local (stdio)
cwprep-mcp

# Remote (Streamable HTTP)
cwprep-mcp --transport streamable-http --port 8000

TIP

Upgrading? If you previously used uvx with an older version, clear the cache to pick up the latest release:

uv cache clean cwprep

Client Configuration

All clients below use the uvx method (recommended). Replace uvx with cwprep-mcp if you prefer a local pip install.

Claude Desktop

Edit config file:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "cwprep": {
      "command": "uvx",
      "args": ["--from", "cwprep[mcp]", "cwprep-mcp"]
    }
  }
}
Cursor

Settings → MCP → Add new MCP server, or edit ~/.cursor/mcp.json:

{
  "mcpServers": {
    "cwprep": {
      "command": "uvx",
      "args": ["--from", "cwprep[mcp]", "cwprep-mcp"]
    }
  }
}
VS Code (Copilot)

Create .vscode/mcp.json in project root:

{
  "servers": {
    "cwprep": {
      "command": "uvx",
      "args": ["--from", "cwprep[mcp]", "cwprep-mcp"]
    }
  }
}
Windsurf (Codeium)

Edit ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "cwprep": {
      "command": "uvx",
      "args": ["--from", "cwprep[mcp]", "cwprep-mcp"]
    }
  }
}
Claude Code (CLI)
claude mcp add cwprep -- uvx --from "cwprep[mcp]" cwprep-mcp
Gemini CLI

Edit ~/.gemini/settings.json:

{
  "mcpServers": {
    "cwprep": {
      "command": "uvx",
      "args": ["--from", "cwprep[mcp]", "cwprep-mcp"]
    }
  }
}
Continue (VS Code / JetBrains)

Edit ~/.continue/config.yaml:

mcpServers:
  - name: cwprep
    command: uvx
    args:
      - --from
      - cwprep[mcp]
      - cwprep-mcp
Remote HTTP Mode (any client)

Start the server:

cwprep-mcp --transport streamable-http --port 8000

Then configure your client with the endpoint: http://your-server-ip:8000/mcp

Available MCP Capabilities

TypeNameDescription
🔧 Toolgenerate_tflGenerate .tfl/.tflx file from flow definition
🔧 Tooltranslate_to_sqlTranslate flow definition or .tfl file to ANSI SQL
🔧 Toollist_supported_operationsList all supported node types
🔧 Toolvalidate_flow_definitionValidate flow definition before generating
📖 Resourcecwprep://docs/api-referenceSDK API reference
📖 Resourcecwprep://docs/calculation-syntaxTableau Prep calculation syntax
📖 Resourcecwprep://docs/best-practicesCommon pitfalls and flow design rules
💬 Promptdesign_data_flowInteractive flow design assistant
💬 Promptexplain_tfl_structureTFL file structure explanation

AI Skill Support

This project includes a specialized AI Skill for assistants like Claude or Gemini to help you build flows.

  • Location: .agents/skills/tfl-generator/
  • Features: MCP server index with fallback SDK usage guide. Detailed API and syntax references are served via MCP Resources from src/cwprep/references/.

Directory Structure

cwprep/
├── .agents/skills/      # AI Agent skills (MCP index)
├── src/cwprep/          # SDK source code
│   ├── builder.py       # TFLBuilder class
│   ├── packager.py      # TFLPackager class
│   ├── translator.py    # SQLTranslator class
│   ├── expression_translator.py  # ExpressionTranslator class
│   ├── config.py        # Configuration utilities
│   ├── mcp_server.py    # MCP Server (Tools, Resources, Prompts)
│   └── references/      # MCP Resource documents (.md)
├── examples/            # Demo scripts
├── docs/                # Documentation
└── tests/               # Unit tests

Configuration

Create config.yaml for default settings:

# MySQL (default)
database:
  host: localhost
  port: 3306
  dbname: mydb
  type: mysql

# SQL Server (Windows Authentication)
# database:
#   host: localhost
#   type: sqlserver
#   authentication: sspi
#   schema: dbo

# PostgreSQL
# database:
#   host: localhost
#   port: 5432
#   dbname: mydb
#   type: postgres

tableau_server:
  url: http://your-server
  default_project: Default

Changelog

See changelog.md for version history.

License

AGPL-3.0 License

Server Config

{
  "mcpServers": {
    "cwprep": {
      "command": "uvx",
      "args": [
        "--from",
        "cwprep[mcp]",
        "cwprep-mcp"
      ]
    }
  }
}
Project Info
Created At
2 months ago
Updated At
2 months ago
Author Name
imgwho
Star
-
Language
-
License
-
Category
Tags

Recommend Servers

View All
Open Code
@github

14 hours ago
Picsart Genai MCP
@Picsart

**Picsart MCP — 150+ AI Models for Images, Video & Audio, One Connection** Picsart's AI Playground brings together more than 150 generative AI models from 24+ providers into one place. The MCP server is the developer and agent interface to that playground — a single connection that gives any AI agent or coding assistant the ability to generate images, video, audio, and text without managing a tangle of separate API keys, billing accounts, or SDKs. **What it generates** - **Images** — Text-to-image, style transfer, AI upscaling, background removal, image enhancement. Powered by models including Flux and other leading image generation providers. - **Video** — Text-to-video and image-to-video generation with top-tier models: Sora, Kling, and Veo, with more added regularly. - **Audio** — Voice synthesis, sound generation, and audio creation via ElevenLabs and other audio providers. - **Text** — Creative copywriting, captions, and content generation integrated directly into multi-modal workflows. **Why it's different from calling model APIs directly** Most creative AI workflows end up routing through three or four separate APIs — one for image generation, another for video, another for voice. Each comes with its own pricing model, rate limits, and integration overhead. Picsart MCP collapses that into one connection. Pricing is pay-per-generation. No monthly model subscriptions stacked on top of each other — access to the full model library for what you actually use. Compared to maintaining individual subscriptions across the leading generative AI providers, that difference runs to several thousand dollars a year. **Works wherever agents work** Picsart MCP follows the Model Context Protocol standard, which means it plugs into any MCP-compatible environment: - **Claude Desktop** — Add to `claude_desktop_config.json`, restart, and your Claude sessions can generate media on demand. - **Claude Code** — Run `claude mcp add` or drop the config into `.mcp.json` in your project root. Works immediately in the CLI and in IDE-integrated sessions. - **Cursor** — Add to `.cursor/mcp.json`. Every Cursor agent and AI panel gets creative generation capabilities. - **ChatGPT** — Compatible via MCP-to-plugin bridge. - **Hermes, Cowork, and other agentic frameworks** — Any tool that supports MCP transport (Streamable HTTP or stdio) connects without modification. **Get started in under a minute** ```json { "mcpServers": { "picsart-gen-ai": { "type": "http", "url": "https://api.picsart.com/gen-ai/mcp" } } } ``` Add this block to your MCP client's config file, drop in your Picsart API key, and restart. The full model library is available immediately — no additional setup, no per-model configuration. **Built for agentic workflows** The tools exposed by Picsart MCP are designed to work as steps inside larger agent pipelines, not just one-off generation requests. A workflow might look like: agent receives a brief → generates a hero image with Flux → generates a short video loop with Kling → synthesizes a voiceover with ElevenLabs → returns all three assets in one pass. That entire sequence runs through a single MCP server, from a single API key, billed per generation. **Part of the Picsart AI Playground** The MCP server is one interface to Picsart's broader AI Playground — a platform that aggregates the world's leading generative AI models so creators, developers, and agents can access them without vendor lock-in. The Playground is also available via direct API and web UI for non-agent workflows.

19 hours ago
X402 Trust

19 hours ago