Skip to main content

Overview

Transform's Python Interface allows users to express MQL requests to query their metrics and dimensions in Python scripts and notebooks.

Installation#

Our Python API is shipped with our command-line interface.

pip install transform

Before querying Transform, you must be authenticated by running the following on the cli:

mql setup

Examples of Querying Metrics#

To pull this into a notebook or Python script, you can run the following, which shows an example of querying a metric called messages with dimensions ds, and a where constraint.

from transform import mql
df = mql.query(metrics=["messages"], dimensions=["ds"], where="is_thread")

You can optionally instantiate the object manually. This will allow you to pass an API key and authenticate and you should use this mechanism if you are not already authenticated.

# Instantiating the object manuallyfrom transform.mql import MQLClient
"""Pass:   - api_key if you want to manually provide an api_key  - mql_server_url if you want to override the mql server
DEFAULT: values in ~/.transform/config.yml"""mql = MQLClient(api_key: Optional[str], mql_server_url: Optional[str])
df = mql.query(metrics=["messages"], dimensions=["ds"], where="is_thread")

Python Interface Functions#

The interface supports most commands that Tranform's MQL CLI supports.

Optional: if you instantiated the MQL client manually, you could declare it as a variable called mql such that mql = MQLClient().