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.
- Install dependencies:
pip install -r requirements.txt- Set up your credentials:
- Rename
.env.exampleto.env - Fill in your Tableau Server details:
- Rename
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- Run a query script (from the project root):
python examples/query_workbooks.pyNeed a different query? Swap in any other file under
examples/, e.g.python examples/query_basic_filter.py.
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 namequery_multiple_filters.py– combine filtersquery_order_results.py– apply ordering and limitsquery_limit_results.py– demonstrate pagination/limitsquery_with_variables.py– pass GraphQL variables at runtime
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- Log in to your Tableau Server/Cloud
- Go to your my account settings
- Navigate to "Personal Access Tokens"
- Create a new token (you'll get a name and secret)
- Add both to your
.envfile
- Never commit your
.envfile (it's in.gitignore) - Keep your Personal Access Token secret secure