Monte Carlo Python SDK (Pycarlo)

0.12.292 · active · verified Sun Apr 12

Pycarlo is Monte Carlo's Python SDK, providing programmatic access to the Monte Carlo data observability platform's APIs. It enables users to execute queries and mutations against the Monte Carlo API and leverage higher-level features for common data operations. The library is actively maintained and frequently updated, with a current version of 0.12.292 and requires Python 3.9 or greater.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Pycarlo client and execute a basic query to retrieve the current user's email. Authentication is handled via environment variables (MCD_ID, MCD_TOKEN), a Monte Carlo CLI-configured profile (~/.mcd/profiles.ini), or by explicitly passing credentials to the Session. It's recommended to use environment variables or CLI profiles for security in production environments.

import os
from pycarlo.core import Client, Query, Session

# Configure session using environment variables or a named profile
# For production, it's recommended to set MCD_ID and MCD_TOKEN environment variables.
# Alternatively, you can configure via the Monte Carlo CLI: `montecarlo configure`
# If using a named profile, ensure ~/.mcd/profiles.ini is set up.

mcd_id = os.environ.get('MCD_ID', 'your_mcd_id_here')
mcd_token = os.environ.get('MCD_TOKEN', 'your_mcd_token_here')

# Instantiate a client. By default, it uses the 'default' profile or environment variables.
# You can also pass credentials explicitly or specify a profile:
# client = Client(Session(mcd_id=mcd_id, mcd_token=mcd_token))
client = Client()

# Create a query object
query = Query()
query.get_user.email()

# Execute the query
try:
    response = client(query)
    user_email = response.get_user.email
    print(f"Current user email: {user_email}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →