Tableau Prep Flow SDK - Programmatically generate .tfl files
Project description
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!
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_to_folder("./output", flow, display, meta)
TFLPackager.pack_zip("./output", "./my_flow.tfl")
Features
| Feature | Method | Description |
|---|---|---|
| Database Connection | add_connection() |
Connect to MySQL/PostgreSQL/SQL Server |
| SQL Input | add_input_sql() |
Custom SQL query input |
| Table Input | add_input_table() |
Direct table connection |
| Join | add_join() |
left/right/inner/full joins |
| Union | add_union() |
Merge multiple tables |
| Filter | add_filter() |
Expression-based filter |
| Value Filter | add_value_filter() |
Keep/exclude by values |
| Keep Only | add_keep_only() |
Select columns |
| Remove Columns | add_remove_columns() |
Drop columns |
| Rename | add_rename() |
Rename columns |
| Calculation | add_calculation() |
Tableau formula fields |
| Quick Calc | add_quick_calc() |
Quick clean (lowercase/uppercase/trim/remove) |
| Change Type | add_change_type() |
Change column data types |
| Duplicate Column | add_duplicate_column() |
Duplicate (copy) a column |
| Aggregate | add_aggregate() |
GROUP BY with SUM/AVG/COUNT |
| Pivot | add_pivot() |
Rows to columns |
| Unpivot | add_unpivot() |
Columns to rows |
| Output | add_output_server() |
Publish to Tableau Server |
Examples
See the examples/ directory for complete demos:
demo_basic.py- Input, Join, Outputdemo_cleaning.py- Filter, Calculate, Renamedemo_field_operations.py- Quick Calc, Change Type, Duplicate Columndemo_aggregation.py- Union, Aggregate, Pivotdemo_comprehensive.py- All features combinedprompts.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
| Method | Requirement |
|---|---|
uvx (recommended) |
Install uv — it auto-downloads cwprep[mcp] in an isolated env |
pip install |
Python ≥ 3.8 + pip install cwprep[mcp] |
Quick Start
# Local (stdio)
cwprep-mcp
# Remote (Streamable HTTP)
cwprep-mcp --transport streamable-http --port 8000
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
| Type | Name | Description |
|---|---|---|
| 🔧 Tool | generate_tfl |
Generate .tfl file from flow definition |
| 🔧 Tool | list_supported_operations |
List all supported node types |
| 🔧 Tool | validate_flow_definition |
Validate flow definition before generating |
| 📖 Resource | cwprep://docs/api-reference |
SDK API reference |
| 📖 Resource | cwprep://docs/calculation-syntax |
Tableau Prep calculation syntax |
| 📖 Resource | cwprep://docs/best-practices |
Common pitfalls and flow design rules |
| 💬 Prompt | design_data_flow |
Interactive flow design assistant |
| 💬 Prompt | explain_tfl_structure |
TFL 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
│ ├── 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
MIT License
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 Distribution
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 cwprep-0.4.0.tar.gz.
File metadata
- Download URL: cwprep-0.4.0.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b62e29045b1d8b15d13e252f5f89cee618ec1370e74bbe9f474e7cdc886094d8
|
|
| MD5 |
ab723c041e7932e2b55416dd25558f0c
|
|
| BLAKE2b-256 |
7b3e61d37a5e2008a08b51d9ca048225009852008ab919e63a53920a07d11dc2
|
File details
Details for the file cwprep-0.4.0-py3-none-any.whl.
File metadata
- Download URL: cwprep-0.4.0-py3-none-any.whl
- Upload date:
- Size: 27.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ee44c250d72fb2a8e76af93805a499494203d9ad8d514e90ffa75233845f0ab
|
|
| MD5 |
e677778cbe64ad7b0f352b18d44eca85
|
|
| BLAKE2b-256 |
882d5c162de1a6c8ab90a36ecd8a272f1f324c016a94e9d92cc382358ec5ef06
|