Skip to main content

Getting Started with Data Quality as Code

This guide will help you install the OpenMetadata Python SDK and configure authentication to start running data quality tests programmatically.

Prerequisites

Before you begin, ensure you have:
  • Python 3.10 or higher installed
  • pip package manager
  • Access to an OpenMetadata 2.0.2 instance
  • A JWT token for authentication (see Authentication below)

Installation

Install the openmetadata-ingestion package with the necessary extras for your use case:

Basic Installation

Installation with Database Connectors

Install additional dependencies based on the databases you’ll be testing:

Installation with DataFrame Support

If you plan to use DataFrame validation features:

Installation with Multiple Features

Combine multiple extras as needed:

Authentication

Data Quality as Code requires authentication with your OpenMetadata instance. The SDK supports JWT token authentication.

Getting a JWT Token

You can obtain a JWT token in two ways:
Note: The Bots tile under Settings is only visible to users with Admin privileges. If you don’t see it, ask your organization’s Collate Admin to generate a bot token for you or grant you Admin access.

Option 1: Using an Existing Bot Token

OpenMetadata provides pre-configured bots like the ingestion-bot:
  1. Log in to your OpenMetadata instance
  2. Navigate to Settings > Bots
  3. Find the ingestion-bot (or create a new bot)
  4. Copy the JWT token
Obtain Bot JWT Token

Option 2: Creating a Custom Bot

For production use, create a dedicated bot with specific permissions:
  1. Go to Settings > Bots
  2. Click Add Bot
  3. Provide a name and description
  4. Assign appropriate roles (typically DefaultBotPolicy and Ingestion Bot Policy)
  5. Copy the generated JWT token

Configuring the SDK

Once you have a JWT token, configure the SDK in your Python code.
If your organization uses an external secrets manager for credential storage, initialize it before this first configure() call, not after. SecretsManagerFactory is a singleton: whichever call runs first wins, so initializing it later in Using External Secrets Managers has no effect once configure() has already run here. See that section before continuing if this applies to you.

Using Environment Variables

For better security, let configure pick them up from environment variables:
Set the environment variable before running your script:

Configuration Parameters

The configure() function accepts the following parameters:

Using External Secrets Managers

The Test Runner guide also links here for reference while you’re testing.

Important Note

If your OpenMetadata instance uses database-stored credentials (the default configuration), you do not need to follow this guide. The SDK will automatically retrieve and decrypt credentials. This guide is only necessary when your organization uses an external secrets manager for credential storage.

Why This is Required

The TestRunner API executes data quality tests directly from your Python code (e.g., within your ETL pipelines). To connect to your data sources, it needs to:
  1. Retrieve the service connection configuration from OpenMetadata
  2. Decrypt the credentials stored in your secrets manager
  3. Establish a connection to the data source
  4. Execute the test cases
Without proper secrets manager configuration, the SDK cannot decrypt credentials and will fail to connect to your data sources.

Matching Your Collate Backend’s Secrets Manager

Configure TestRunner to match whatever secrets manager provider your Collate backend already uses. The SDK cannot discover this automatically.
  • Self-hosted Collate: your administrator already configured the secrets manager for your deployment. Use the same provider and loader values described in Configuration by Provider.
  • Collate SaaS: the secrets manager is part of the managed platform, so you don’t configure or control it yourself. Contact your Collate administrator for the secrets manager provider, for example SecretsManagerProvider.managed_aws. Also ask for the tenant’s region or vault name and access credentials scoped for your use. These details are tenant-specific, and you can’t find them in code or guess them.

General Setup Steps

  1. Contact your OpenMetadata/Collate administrator to obtain:
    • The secrets manager type (AWS, Azure, GCP, etc.)
    • The secrets manager loader configuration
    • Required environment variables or configuration files
    • Any additional setup (IAM roles, service principals, etc.)
  2. Install required dependencies for your secrets manager provider
  3. Configure environment variables with access credentials
  4. Initialize the SecretsManagerFactory before using TestRunner
  5. Authenticate with an ingestion-bot JWT instead of a personal user token. See Authentication for how to obtain one.
  6. Configure the SDK and run your tests

Example using AWS Secrets Manager

Required Dependencies:
Example Configuration:

Configuration by Provider

AWS and AWS Parameters Store

Collate’s ingestion extras: aws (e.g pip install 'openmetadata-ingestion[aws]') SecretsManagerProvider: (one of)
  • SecretsManagerProvider.aws
  • SecretsManagerProvider.managed_aws
  • SecretsManagerProvider.aws_ssm
  • SecretsManagerProvider.managed_aws_ssm
Environment variables:
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION

Azure Key Vault

Collate’s ingestion extras: azure (e.g pip install 'openmetadata-ingestion[azure]') SecretsManagerProvider: (one of)
  • SecretsManagerProvider.azure_kv
  • SecretsManagerProvider.managed_azure_kv
Environment variables:
  • AZURE_CLIENT_ID
  • AZURE_CLIENT_SECRET
  • AZURE_TENANT_ID
  • AZURE_KEY_VAULT_NAME

Google Cloud Secret Manager

Collate’s ingestion extras: gcp (e.g pip install 'openmetadata-ingestion[gcp]') SecretsManagerProvider: SecretsManagerProvider.gcp Environment variables:
  • GOOGLE_APPLICATION_CREDENTIALS: path to the file with the credentials json file
  • GOOGLE_CLOUD_PROJECT

Troubleshooting

Error: “Cannot decrypt service connection”

Cause: Secrets manager not initialized or misconfigured Solution: Ensure SecretsManagerFactory is initialized before calling configure() or creating the TestRunner

Error: “SecretsManagerFactory settings don’t take effect”

Cause: SecretsManagerFactory is a singleton. Only the first call in a Python process takes effect. If configure(), TestRunner, or anything else from metadata.sdk runs first, even through an earlier import, the factory already initializes with defaults. Later SecretsManagerFactory(...) calls are silently ignored. Solution: Call SecretsManagerFactory(...) as the first SDK-related statement in your script. Restart the session if you’re in a long-running or interactive environment, such as a notebook, where the SDK might already have been used.

Error: “Access Denied” or “Unauthorized”

Cause: Insufficient permissions to access secrets Solution:
  • Verify IAM role/service principal has correct permissions
  • Check credentials are valid and not expired
  • Ensure correct region/vault name is specified

Error: “Module not found” for secrets manager

Cause: Missing dependencies for your secrets manager Solution: Install required extras:

Tests Fail with Connection Errors

Cause: Credentials not properly decrypted or secrets manager misconfigured Solution:
  1. Verify secrets manager provider matches your OpenMetadata backend configuration
  2. Test credential access independently (e.g., using AWS CLI, Azure CLI, gcloud)
  3. Check network connectivity to secrets manager service
  4. Enable debug logging to see detailed error messages:

Contact Your Administrator

If you’re unsure about:
  • Which secrets manager your organization uses
  • Required environment variables or configuration
  • Access credentials or IAM roles
  • Permissions needed
Contact your OpenMetadata or Collate administrator for the specific configuration required in your environment.

For More Information

These related pages provide more detail on secrets manager configuration:

Verify Installation

Create a simple test to verify your setup:
Replace "your_service.database.schema.table" with the fully qualified name of an actual table in your OpenMetadata instance.

Your First Data Quality Test

Now that you’re set up, let’s run your first data quality test:

Common Installation Issues

Connection Timeout

If you experience connection timeouts, verify:
  1. OpenMetadata instance is running and accessible
  2. API URL is correct (should end with /api)
  3. Network connectivity between your script and OpenMetadata
  4. Firewall rules allow the connection

Import Errors

If you encounter import errors:
Verify the package is installed correctly:
If not listed, reinstall:

Next Steps

Now that you have the SDK installed and configured:

Additional Resources