Skip to main content

A Python client library for interacting with the VizQL Data Service API

Project description

VizQL Data Service Python SDK

Tableau Supported GitHub Python Version

OpenAPI

The VizQL Data Service Python SDK is a lightweight client library that enables interaction with Tableau's VizQL Data Service APIs. It supports both cloud and on-premises deployments, offering both synchronous and asynchronous methods for querying the VizQL Data Service APIs.

Consider reading VizQL Data Service in the following order:

🔧 Installation

python -m venv --system-site-packages venv # Optional command: set up a python virtual environment before installing the vizql_data_service_py package
source venv/bin/activate    # A continuation of the first command for Unix/MacOS users. This activates the virtual environment for Unix/MacOS
venv\Scripts\activate       # A continuation of the first command for Windows users. This activates the virtual environment for Windows

pip install vizql-data-service-py

🚀 Quick Start

Importing Required Modules

from vizql_data_service_py import (
    ReadMetadataRequest,
    QueryRequest,
    Datasource,
    Connection,
    VizQLDataServiceClient,
    read_metadata,
    query_datasource,
    DimensionField,
    MeasureField,
    Function,
    Query
)

Setting Up Server Connection

To create Server and Auth instances, please refer to the Tableau Server Client (Python) Authentication Guide. For JWT authentication setup, see the Configure Connected Apps with Direct Trust documentation.

Note: Authentication methods vary between Tableau Cloud and On-premises deployments:

  • Tableau Cloud: Supports JWT and Personal Access Token (PAT) authentication
  • Tableau On-premises: Supports JWT, PAT, and username/password authentication

Configuring Data Source

# Create a data source instance with optional connection parameters
datasource = Datasource(
    datasourceLuid="<datasource-luid>",
    # Optional: Configure connections for external data sources
    connections=[
        Connection(
            connectionUsername="<connection-username>",
            connectionPassword="<connection-password>"
        )
    ]
)

Sign in, Read Metadata and Query Data Sources

import tableauserverclient as TSC

# Choose one of these auth mechanisms
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
# tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD', 'SITENAME')
# tableau_auth = TSC.JWTAuth('JWT', 'SITENAME')

server_url = 'https://SERVER_URL'
server = TSC.Server(server_url)

with server.auth.sign_in(tableau_auth):
    client = VizQLDataServiceClient(server_url, server, tableau_auth)
    # Define your query fields
    query = Query(
        # Example: sample Superstore data source
        # Aggregate SUM(Sales) by Category
        fields=[
            DimensionField(fieldCaption="Category"),
            MeasureField(fieldCaption="Sales", function=Function.SUM),
        ]
    )
    # Step 1: Read metadata
    read_metadata_request = ReadMetadataRequest(
        datasource=datasource
    )
    read_metadata_response = read_metadata.sync(
        client=client, body=read_metadata_request
    )
    print(f"Read Metadata Response: {read_metadata_response}")

    # Step 2: Execute query
    query_request = QueryRequest(
        query=query, datasource=datasource
    )
    query_response = query_datasource.sync(
        client=client, body=query_request
    )
    print(f"Query Datasource Response: {query_response}")

API Methods

The SDK provides two ways to make API calls:

# Simple way - just get the response data
response = read_metadata.sync(client=client, body=read_metadata_request)

# Detailed way - get response data, status code and headers
response, status, headers = read_metadata.sync_detailed(client=client, body=read_metadata_request)

Both methods work for read_metadata and query_datasource. Use sync_detailed() when you need HTTP response details like status code and headers.

This SDK is built using datamodel-codegen to generate all VizQL Data Service models based on Pydantic v2. For detailed API documentation and model specifications, please refer to the VizQLDataServiceOpenAPISchema.json file.

Note: While raw JSON requests are supported, we strongly recommend using the provided Python pydantic v2 objects to construct requests. This approach offers several advantages:

  • Type safety and validation at compile time
  • Better IDE support with autocompletion
  • Consistent request structure
  • Easier maintenance and debugging

For comprehensive examples demonstrating various query patterns and filter combinations, please check the examples directory.

📘 Supported Features

  • ✅ Read metadata of Tableau published datasources
  • ✅ Query published datasources with selectable fields and queries supports various filters
  • ✅ Synchronous and Asynchronous Python client support
  • ✅ Authentication using Tableau username/password, JWT or PAT
  • ✅ Works with both Tableau Cloud and Tableau Server (on-prem)
  • ✅ OpenAPI schema generated Python Pydantic v2 models for type-safe API interactions

🛠️ Requirements

  • Python 3.9+
  • pip 20.0+
  • Tableau Server 2025.1+ or Tableau Cloud

🤝 Contributing

To contribute, see our CONTRIBUTING.md Guide. A list of all our contributors to date is in CONTRIBUTORS.md.

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

vizql_data_service_py-1.1.0.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

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

vizql_data_service_py-1.1.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file vizql_data_service_py-1.1.0.tar.gz.

File metadata

  • Download URL: vizql_data_service_py-1.1.0.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for vizql_data_service_py-1.1.0.tar.gz
Algorithm Hash digest
SHA256 85a80d6d3ae2557a2cecb352e7be1dbce71dd77d24c2f956fbf581635f7ef0e6
MD5 ae1b771fd575e76431c0f1ae9d758015
BLAKE2b-256 afeca0330c5c551a6561f1a3db376bd003f3caa3b1f54e0773e4716ab72aee4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for vizql_data_service_py-1.1.0.tar.gz:

Publisher: push.yml on tableau/VizQL-Data-Service

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vizql_data_service_py-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vizql_data_service_py-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 812c4be60c95fde235f0211b264f34b217bee738c52a8bc3d9383e9fc45a3795
MD5 405e066d9c79b091fb364a9ca039d8da
BLAKE2b-256 33521027f3734b82a01b8839fd6742620d46d8e275f34d9fcc9fff67a9eb5aa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for vizql_data_service_py-1.1.0-py3-none-any.whl:

Publisher: push.yml on tableau/VizQL-Data-Service

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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