Skip to main content

Tableau Prep Flow SDK - Programmatically generate .tfl files

Project description

cwprep - Tableau Prep Flow SDK

A Python SDK for programmatically generating Tableau Prep data flow (.tfl) files. Built through reverse-engineering the TFL JSON structure, enabling flow creation and modification via code without 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/Oracle
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
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, Output
  • demo_cleaning.py - Filter, Calculate, Rename
  • demo_aggregation.py - Union, Aggregate, Pivot
  • demo_comprehensive.py - All features combined

MCP Server

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

Installation

pip install cwprep[mcp]

Usage

# Local (stdio)
cwprep-mcp

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

Claude Desktop Configuration

Add to your Claude Desktop config (claude_desktop_config.json):

{
  "mcpServers": {
    "cwprep": {
      "command": "cwprep-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
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: Procedural guidance for flow construction, API reference, and Tableau Prep calculation syntax rules.

Directory Structure

cwprep/
├── .agents/skills/      # AI Agent skills and technical references
├── 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)
├── examples/            # Demo scripts
├── docs/                # Documentation
└── tests/               # Unit tests

Configuration

Create config.yaml for default settings:

database:
  host: localhost
  username: root
  dbname: mydb
  port: "3306"
  db_class: mysql

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

Changelog

See changelog.md for version history.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cwprep-0.2.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cwprep-0.2.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file cwprep-0.2.0.tar.gz.

File metadata

  • Download URL: cwprep-0.2.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for cwprep-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2f3b8103ea13b66edeb9365c4e137f32cd5b42ea70911fa06e95f3ccbe767a34
MD5 e8aea8aca7346c976713123f28790be2
BLAKE2b-256 9d1cf83edb1b0daab7bae1d95a71b32559d025477c3f89729e366fc482c60373

See more details on using hashes here.

File details

Details for the file cwprep-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cwprep-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for cwprep-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c4dee0caf0b6c8112e973e2519c655452dd7c6d9b88c1bcaf8ade2c5246602f
MD5 10121a85cf03cc502cbdc911e13e79e3
BLAKE2b-256 c632e5376679bb76f2b68ec9f29bfc86d450352ea26214e722542fc935b789aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page