{"id":4702,"library":"pycarlo","title":"Monte Carlo Python SDK (Pycarlo)","description":"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.","status":"active","version":"0.12.292","language":"en","source_language":"en","source_url":"https://github.com/monte-carlo-data/monte-carlo-python-sdk-examples","tags":["data observability","sdk","api client","monte carlo data"],"install":[{"cmd":"pip install -U pycarlo","lang":"bash","label":"Install or Upgrade"}],"dependencies":[],"imports":[{"symbol":"Client","correct":"from pycarlo.core import Client"},{"symbol":"Query","correct":"from pycarlo.core import Query"},{"symbol":"Mutation","correct":"from pycarlo.core import Mutation"},{"symbol":"Session","correct":"from pycarlo.core import Session"},{"symbol":"CircuitBreakerService","correct":"from pycarlo.features.circuit_breakers import CircuitBreakerService"}],"quickstart":{"code":"import os\nfrom pycarlo.core import Client, Query, Session\n\n# Configure session using environment variables or a named profile\n# For production, it's recommended to set MCD_ID and MCD_TOKEN environment variables.\n# Alternatively, you can configure via the Monte Carlo CLI: `montecarlo configure`\n# If using a named profile, ensure ~/.mcd/profiles.ini is set up.\n\nmcd_id = os.environ.get('MCD_ID', 'your_mcd_id_here')\nmcd_token = os.environ.get('MCD_TOKEN', 'your_mcd_token_here')\n\n# Instantiate a client. By default, it uses the 'default' profile or environment variables.\n# You can also pass credentials explicitly or specify a profile:\n# client = Client(Session(mcd_id=mcd_id, mcd_token=mcd_token))\nclient = Client()\n\n# Create a query object\nquery = Query()\nquery.get_user.email()\n\n# Execute the query\ntry:\n    response = client(query)\n    user_email = response.get_user.email\n    print(f\"Current user email: {user_email}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `MCD_ID` and `MCD_TOKEN` environment variables are set, or run `montecarlo configure` via the CLI to set up a default profile. For explicit control, pass `mcd_id` and `mcd_token` to `pycarlo.core.Session`.","message":"API Key Configuration: Pycarlo requires an API Key ID (MCD_ID) and API Secret (MCD_TOKEN) for authentication. These are typically sourced from environment variables or a configuration file (~/.mcd/profiles.ini) created by the Monte Carlo CLI (`montecarlo configure`). Incorrect or missing credentials will prevent the SDK from functioning.","severity":"gotcha","affected_versions":"All"},{"fix":"Keep your Pycarlo SDK updated to the latest version to avoid warnings and ensure full feature and schema support. `pip install -U pycarlo`.","message":"Enum Backward Compatibility: Unlike `sgqlc`'s default behavior, Pycarlo is designed to be backward compatible with new enum values introduced in the Monte Carlo API. If the API returns an enum value not present in your SDK version, it will be returned as a string with a warning, instead of raising an error. While this prevents breakage, it means your local SDK might not fully reflect the latest API schema.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to the documentation for specific imports. Most basic operations start with `pycarlo.core`.","message":"Separation of Core and Features: Pycarlo is divided into `core` for direct API queries/mutations and `features` for higher-level convenience functions (e.g., circuit breakers, dbt, pii filtering). Ensure you import from the correct submodule (e.g., `from pycarlo.core import Client` vs. `from pycarlo.features.circuit_breakers import CircuitBreakerService`).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}