Python SDK

Documentation for Ardent's Python SDK implementation and usage.

The Ardent Python SDK provides a convenient way to interact with Ardent's capabilities directly from your Python applications. This SDK wraps our REST API and provides an intuitive interface for Python developers.

Installation

You can install the Ardent Python SDK using pip:

pip install ardent-sdk

Authentication

The SDK requires both a public and secret key for authentication:

For almost all use cases do not add the base_url parameter. Only set it if you're using an on prem deployment with a custom URL.

from ardent import ArdentClient

client = ArdentClient(
    public_key="your_public_key",
    secret_key="your_secret_key",
    base_url="https://your-custom-url.com"

)

Core Functions

Executing Jobs

Executing a new job for Ardent to run:

response = client.create_and_execute_job(
    message="Fix the failing airflow pipeline",
)

Managing Configurations

Set a new configuration:

MongoDB:

# Example for MongoDB config
config = client.set_config(
    config_type="mongodb",
    connection_string="mongodb://...",
    databases=[{"name": "mydb", "collections": [{"name": "users"}]}]
)

Airflow:

# Example for Airflow config
config = client.set_config(
    config_type="airflow",
    github_token="ghp_1a2b3c4d5e6f7g8h9i0j",  # GitHub personal access token
    repo="https://github.com/your-org/airflow-dags",
    dag_path="dags/",
    host="http://your-airflow-instance:8080",
    username="airflow_user",
    password="your_secure_password"
)

Azure SQL Server:

# Example for Azure SQL Server config
config = client.set_config(
    config_type="azureSQLServer",
    server="your-server.database.windows.net",
    username="your_admin_user",
    password="your_secure_password",
    version="18",
    databases=[{
        "name": "your_database_name"
    }]
)

Databricks Jobs:

# Example for Databricks Jobs config
config = client.set_config(
    config_type="databricksJobs",
    workspace_url="dbc-xxx.cloud.databricks.com",
    access_token="dapi1234567890abcdef",
    github_token="ghp_1a2b3c4d5e6f7g8h9i0j",
    repo="https://github.com/your-org/databricks-jobs",
    repo_path="/Repos/your.email@company.com/"
)

Databricks SQL:

# Example for Databricks SQL config
config = client.set_config(
    config_type="databricks",
    server_hostname="dbc-xxx.cloud.databricks.com",
    http_path="/sql/1.0/warehouses/abc123def456",
    access_token="dapi1234567890abcdef",
    catalogs=[{
        "name": "example_catalog",
        "databases": [{
            "name": "example_database",
            "tables": [{
                "name": "example_table"
            }]
        }]
    }]
)

MySQL:

# Example for MySQL config
config = client.set_config(
    config_type="mysql",
    host="your-mysql-instance.region.rds.amazonaws.com",
    port="3306",
    username="your_mysql_user",
    password="your_secure_password",
    databases=[{
        "name": "example_database"
    }]
)

PostgreSQL:

# Example for PostgreSQL config
config = client.set_config(
    config_type="postgreSQL",
    Hostname="your-postgres-instance.region.neon.tech",
    Port="5432",
    username="your_postgres_user",
    password="your_secure_password",
    databases=[{
        "name": "example_database"
    }]
)

Snowflake:

# Example for Snowflake config
config = client.set_config(
    config_type="snowflake",
    account="your-account-identifier",
    user="your_snowflake_user",
    password="your_secure_password",
    warehouse="your_warehouse_name",
    databases=[{
        "name": "example_database"
    }]
)

Supabase:

# Example for Supabase config
config = client.set_config(
    config_type="supabase",
    project_url="https://your-project.supabase.co",
    api_key="your-supabase-service-role-key",
    databases=[]  # Supabase will auto-detect available databases
)

TigerBeetle:

# Example for TigerBeetle config
config = client.set_config(
    config_type="tigerbeetle",
    cluster_id="0",  # Cluster ID for your TigerBeetle instance
    replica_addresses=["localhost:3000"]  # List of replica addresses
)

Delete a configuration:

response = client.delete_config(config_id="5245432a2123")

Error Handling

The SDK provides specific error types for different scenarios:

Authentication Errors

Used when there are issues with API keys or authentication.

from ardent import ArdentAuthError

try:
    response = client.create_and_execute_job(message="Query the database")
except ArdentAuthError:
    print("Authentication failed - check your API keys")

Validation Errors

Occurs when provided parameters don't meet the required format or constraints.

from ardent import ArdentValidationError

try:
    response = client.set_config(config_type="invalid_type")
except ArdentValidationError:
    print("Invalid parameters - check your input values")

API Errors

General API errors including rate limits, server errors, or other API-related issues.

from ardent import ArdentAPIError

try:
    response = client.create_job(message="")
except ArdentAPIError as e:
    print(f"API error occurred: {e}")
    print(f"Status code: {e.status_code}")  # If available

Cleanup

When you're done with the client, you can clean up resources:

client.close()