aixplain.modules.model.integration
AuthenticationSchema Objects
class AuthenticationSchema(Enum)
Enumeration of supported authentication schemes for integrations.
This enum defines the various authentication methods that can be used when connecting to external services through integrations.
Attributes:
BEARER_TOKENstr - Bearer token authentication scheme.OAUTH1str - OAuth 1.0 authentication scheme.OAUTH2str - OAuth 2.0 authentication scheme.API_KEYstr - API key authentication scheme.BASICstr - Basic authentication scheme (username/password).NO_AUTHstr - No authentication required.
BaseAuthenticationParams Objects
class BaseAuthenticationParams(BaseModel)
Base model for authentication parameters used in integrations.
This class defines the common parameters that are used across different authentication schemes when connecting to external services.
Attributes:
nameOptional[Text] - Optional name for the connection. Defaults to None.connector_idOptional[Text] - Optional ID of the connector. Defaults to None.
build_connector_params
def build_connector_params(**kwargs) -> BaseAuthenticationParams
Build authentication parameters for a connector from keyword arguments.
This function creates a BaseAuthenticationParams instance from the provided keyword arguments, extracting the name and connector_id if present.
Arguments:
**kwargs- Arbitrary keyword arguments. Supported keys:- name (Optional[Text]): Name for the connection
- connector_id (Optional[Text]): ID of the connector
Returns:
BaseAuthenticationParams- An instance containing the extracted parameters.
Example:
>>> params = build_connector_params(name="My Connection", connector_id="123") >>> print(params.name) 'My Connection'
Integration Objects
class Integration(Model)
__init__
def __init__(id: Text,
name: Text,
description: Text = "",
api_key: Optional[Text] = None,
supplier: Union[Dict, Text, Supplier, int] = "aiXplain",
version: Optional[Text] = None,
function: Optional[Function] = None,
is_subscribed: bool = False,
cost: Optional[Dict] = None,
function_type: Optional[FunctionType] = FunctionType.INTEGRATION,
**additional_info) -> None
Initialize a new Integration instance.
Arguments:
idText - ID of the Integration.nameText - Name of the Integration.descriptionText, optional - Description of the Integration. Defaults to "".api_keyText, optional - API key for the Integration. Defaults to None.supplierUnion[Dict, Text, Supplier, int], optional - Supplier of the Integration. Defaults to "aiXplain".versionText, optional - Version of the Integration. Defaults to "1.0".functionFunction, optional - Function of the Integration. Defaults to None.is_subscribedbool, optional - Whether the user is subscribed. Defaults to False.costDict, optional - Cost of the Integration. Defaults to None.function_typeFunctionType, optional - Type of the function. Must be FunctionType.INTEGRATION. Defaults to FunctionType.INTEGRATION.name0 - Any additional Integration info to be saved.
Raises:
name1 - If function_type is not FunctionType.INTEGRATION.
connect
def connect(authentication_schema: AuthenticationSchema,
args: Optional[BaseAuthenticationParams] = None,
data: Optional[Dict] = None,
**kwargs) -> ModelResponse
Connect to the integration using the specified authentication scheme.
This method establishes a connection to the integration service using the provided authentication method and credentials. The required parameters vary depending on the authentication scheme being used.
Arguments:
authentication_schemaAuthenticationSchema - The authentication scheme to use (e.g., BEARER_TOKEN, OAUTH1, OAUTH2, API_KEY, BASIC, NO_AUTH).argsOptional[BaseAuthenticationParams], optional - Common connection parameters. If not provided, will be built from kwargs. Defaults to None.dataOptional[Dict], optional - Authentication-specific parameters required by the chosen authentication scheme. Defaults to None.**kwargs- Additional keyword arguments used to build BaseAuthenticationParams if args is not provided. Supported keys:- name (str): Name for the connection
- connector_id (str): ID of the connector
Returns:
ModelResponse- A response object containing:- data (Dict): Contains connection details including:
- id (str): Connection ID (can be used with ModelFactory.get(id))
- redirectURL (str, optional): URL to complete OAuth authentication (only for OAuth1/OAuth2)
Raises:
ValueError- If the authentication schema is not supported by this integration or if required parameters are missing from the data dictionary.
Examples:
Using Bearer Token authentication: >>> integration.connect( ... AuthenticationSchema.BEARER_TOKEN, ... data={"token": "1234567890"}, ... name="My Connection" ... )
Using OAuth2 authentication: >>> response = integration.connect( ... AuthenticationSchema.OAUTH2, ... name="My Connection" ... ) >>> # For OAuth2, you'll need to visit the redirectURL to complete auth >>> print(response.data.get("redirectURL"))
Using API Key authentication: >>> integration.connect( ... AuthenticationSchema.API_KEY, ... data={"api_key": "your-api-key"}, ... name="My Connection" ... )
__repr__
def __repr__()
Return a string representation of the Integration instance.
Returns:
str- A string in the format "Integration: <name> by <supplier> (id=<id>)". If supplier is a dictionary, uses supplier['name'], otherwise uses supplier directly.