AmorphicApiClient

class openapi_client.amorphic_api_client.AmorphicApiClient(configuration, role_id, custom_logger=None, enable_audit_stats=False)[source]

Bases: ApiClient

Custom API client for Amorphic API that extends the base ApiClient

__init__(configuration, role_id, custom_logger=None, enable_audit_stats=False)[source]

Initialize the Amorphic API client with the given configuration and role ID.

Key Steps: 1. Initialize logger (custom or default) 2. Set up usage statistics collection if enabled 3. Create management API instance with optional usage stats tracking 4. Check version compatibility with the Amorphic API 5. Log system information if debug mode is enabled

Parameters:
  • configuration (Configuration) – The configuration object containing: - host: API host URL - api_key: Authentication key dictionary - ssl_ca_cert: SSL certificate path (optional) - debug: Enable debug logging

  • role_id (str) – The role ID for authentication and API calls

  • custom_logger (Optional[logging.Logger]) – Custom logger instance. If not provided, a default logger will be created with console output.

  • enable_audit_stats (bool) – Enable automatic usage statistics collection for product team analytics. Defaults to True, can be set to False to disable usage stats.

Returns:

Initialized client instance ready for API calls

Return type:

AmorphicApiClient

Raises:
  • ValueError – If the API version is not compatible with the required version range

  • Exception – If system information cannot be retrieved during initialization

classmethod create_with_auth(host, role_id, ssl_ca_cert=None, debug=False, aws_profile=None, env_var=None, ssm_parameter=None, secret_arn=None, token=None, custom_logger=None)[source]

Factory method to create AmorphicApiClient with flexible authentication.

Key Steps: 1. Fetch authentication token from specified source (if not provided directly) 2. Create Configuration object with host, token, and SSL settings 3. Initialize AmorphicApiClient with the configuration 4. Return fully configured client instance

Parameters:
  • host (str) – API host URL (e.g., ‘https://api.amorphic.com’)

  • role_id (str) – Role ID for authentication and API calls

  • ssl_ca_cert (Optional[str]) – SSL CA certificate path for custom certificates

  • debug (bool) – Enable debug mode for detailed logging

  • aws_profile (Optional[str]) – AWS profile name for local development

  • env_var (Optional[str]) – Environment variable name containing token

  • ssm_parameter (Optional[str]) – SSM parameter name containing token

  • secret_arn (Optional[str]) – Secrets Manager secret ARN containing token

  • token (Optional[str]) – Direct token value (bypasses token fetching)

  • custom_logger (Optional[logging.Logger]) – Custom logger instance

Returns:

Configured client instance ready for API calls

Return type:

AmorphicApiClient

Raises:
  • ValueError – If no token source is configured and no direct token provided

  • NoCredentialsError – If AWS credentials are not configured for SSM/Secrets Manager

  • ClientError – If AWS service calls fail (SSM/Secrets Manager)

get_audit_stats()[source]

Get comprehensive usage statistics for the current session.

Key Steps: 1. Check if usage stats are enabled 2. Return usage statistics including total operations and method call counts 3. Include operation history with timestamps and details 4. Return disabled message if usage stats are not enabled

Parameters:

None

Returns:

Dictionary containing:
  • total_operations: Total number of operations performed

  • method_calls: Dictionary of method calls with their counts

  • operation_history: List of operation details with timestamps

OR - message: ‘Usage statistics are disabled’ if disabled

Return type:

Dict[str, Any]

Raises:

None – This method has no external dependencies

get_audit_summary()[source]

Get human-readable usage stats summary for the current session.

Key Steps: 1. Check if usage stats are enabled 2. Build summary with total operations count 3. Add breakdown by method calls with their counts 4. Return formatted string summary

Parameters:

None

Returns:

Human-readable summary of usage statistics or “Usage statistics are disabled”

Return type:

str

Raises:

None – This method has no external dependencies

get_system_information(role_id)[source]

Get system information from the Amorphic API.

Key Steps: 1. Validate that role_id is provided and not empty 2. Call the management API to retrieve system information 3. Return system information including version, environment, project details 4. Handle and re-raise any API exceptions

Parameters:

role_id (str) – The role ID for authentication. Must be provided and non-empty.

Returns:

The system information response containing:
  • version: API version

  • environment: Environment name

  • project_name: Project name

  • project_shortname: Project shortname

  • aws_region: AWS region

  • aws_account_id: AWS account ID

Return type:

SystemInformation

Raises:
  • ValueError – If role_id is None or empty

  • ApiException – If the API call fails

Overview:

The AmorphicApiClient is an enhanced API client that extends the base OpenAPI ApiClient to provide additional functionality for interacting with the Amorphic Data Platform APIs. It includes system information retrieval, authentication, and role management capabilities.

Key Features:

  • Enhanced Authentication: Built-in support for multiple token sources

  • System Information: Automatic retrieval of platform information during initialization

Basic Usage:

import certifi
from openapi_client.amorphic_api_client import AmorphicApiClient
from openapi_client.api.datasets_api import DatasetsApi

# Create client with environment variable token
client = AmorphicApiClient.create_with_auth(
    host="https://your-instance.amorphic.com/api",
    role_id="your-role-id",
    ssl_ca_cert=certifi.where(),
    debug=False,
    aws_profile=None,
    env_var='PAT_TOKEN'
)

# Use with any API
datasets_api = DatasetsApi(client)

# Example: List datasets
datasets = datasets_api.list_datasets(role_id="your-role-id")

Authentication Options:

# Option 1: Environment variable
client = AmorphicApiClient.create_with_auth(
    host="https://api.example.com",
    role_id="role-123",
    ssl_ca_cert=certifi.where(),
    debug=False,
    aws_profile=None,
    env_var='PAT_TOKEN'
)

# Option 2: AWS SSM Parameter Store
client = AmorphicApiClient.create_with_auth(
    host="https://api.example.com",
    role_id="role-123",
    ssl_ca_cert=certifi.where(),
    debug=False,
    aws_profile='myprofile',
    ssm_parameter='/myapp/api/token'
)

# Option 3: AWS Secrets Manager
client = AmorphicApiClient.create_with_auth(
    host="https://api.example.com",
    role_id="role-123",
    ssl_ca_cert=certifi.where(),
    debug=False,
    aws_profile=None,
    secret_arn='arn:aws:secretsmanager:us-east-1:123456789012:secret:mytoken'
)

# Option 4: Direct token
client = AmorphicApiClient.create_with_auth(
    host="https://api.example.com",
    role_id="role-123",
    ssl_ca_cert=certifi.where(),
    debug=False,
    aws_profile=None,
    token='your-direct-token'
)