Skip to content

TheInformationLab/Metadata-Starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tableau Metadata API - Simple Query Scripts

A minimal Python setup for querying Tableau's Metadata API using GraphQL. Just write your query and run it. Or use the scripts which we have built out for you to help you get started.

Quick Start

  1. Install dependencies:
pip install -r requirements.txt
  1. Set up your credentials:
    • Rename.env.example to .env
    • Fill in your Tableau Server details:
TABLEAU_SERVER_URL=https://your-server.tableau.com
TABLEAU_SITE_ID=your-site-id
TABLEAU_PAT_NAME=your-pat-name
TABLEAU_PAT_SECRET=your-pat-secret
  1. Run a query script (from the project root):
python examples/query_workbooks.py

Need a different query? Swap in any other file under examples/, e.g. python examples/query_basic_filter.py.

Structure

  • helpers.py - Shared authentication/query helpers (imported by every example)
  • examples/query_workbooks.py - Default "list workbooks" example (run as-is)
  • examples/query_*.py - Additional ready-to-run samples:
    • query_basic_filter.py – find a workbook by name
    • query_multiple_filters.py – combine filters
    • query_order_results.py – apply ordering and limits
    • query_limit_results.py – demonstrate pagination/limits
    • query_with_variables.py – pass GraphQL variables at runtime

Creating New Queries

Just copy examples/query_workbooks.py into a new file (keep it inside examples/) and modify the query variable:

from helpers import sign_in, query_metadata, sign_out
import json

# Your GraphQL query here
query = """
{
    workbooks {
        name
        luid
    }
}
"""

# Execute (this part stays the same)
token, site_luid, server_url = sign_in()
result = query_metadata(token, site_luid, server_url, query)
sign_out(token, server_url)

# Print results
print(json.dumps(result, indent=2))

Run it with:

python examples/my_new_query.py

Getting Personal Access Tokens

  1. Log in to your Tableau Server/Cloud
  2. Go to your my account settings
  3. Navigate to "Personal Access Tokens"
  4. Create a new token (you'll get a name and secret)
  5. Add both to your .env file

Resources

Security Note

  • Never commit your .env file (it's in .gitignore)
  • Keep your Personal Access Token secret secure

About

A project which allows you to easily set up and output queries to the Metadata API using Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages