Skip to main content

client

Datalayer AI SDK - A simple SDK for AI engineers to work with Datalayer.

Provides authentication, runtime creation, and code execution capabilities.

class DatalayerClient(run_url: str = 'https://prod1.datalayer.run', token: Optional[str] = None)

SDK for Datalayer AI platform.

Provides a unified interface for authentication, runtime creation, and code execution in Datalayer environments.

Parameters

  • run_url : str

    Datalayer server URL. Defaults to "https://prod1.datalayer.run".

  • token : Optional[str]

    Authentication token (can also be set via DATALAYER_TOKEN env var).

__init__(run_url: str = 'https://prod1.datalayer.run', token: Optional[str] = None)

Initialize the Datalayer SDK.

Parameters

  • run_url : str

    Datalayer server URL. Defaults to "https://prod1.datalayer.run".

  • token : Optional[str]

    Authentication token (can also be set via DATALAYER_TOKEN env var).

run_url

Get the Datalayer server URL.

Returns

  • str

    The configured Datalayer server URL.

authenticate() -> bool

Validate authentication credentials.

Returns

  • bool

    True if authentication is successful.

get_profile() -> datalayer_core.sdk.profile.Profile

Get the user's profile information.

Returns

  • Profile

    A Profile object containing user details.

list_environments() -> list[datalayer_core.sdk.environments.Environment]

List all available environments.

Returns

  • list[Environment]

    A list of available environments.

create_runtime(name: Optional[str] = None, environment: str = 'python-cpu-env', time_reservation: float = 10.0, snapshot_name: Optional[str] = None) -> datalayer_core.sdk.runtimes.Runtime

Create a new runtime (kernel) for code execution.

Parameters

  • name : str, optional

    Name of the runtime to create.

  • environment : str, optional

    Environment type (e.g., "python-cpu-env"). Type of resources needed (cpu, gpu, etc.).

  • time_reservation : Minutes, optional

    Time reservation in minutes for the runtime. Defaults to 10 minutes.

  • snapshot_name : Optional[str], optional

    Name of the snapshot to create from. If provided, the runtime will be created from this snapshot.

Returns

  • Runtime

    A runtime object for code execution.

list_runtimes() -> list[datalayer_core.sdk.runtimes.Runtime]

List all running runtimes.

Returns

  • list[Runtime]

    List of Runtime objects representing active runtimes.

terminate_runtime(runtime: Union[datalayer_core.sdk.runtimes.Runtime, str]) -> bool

Terminate a running Runtime.

Parameters

  • runtime : Union[Runtime, str]

    Runtime object or pod name string to terminate.

Returns

  • bool

    True if termination was successful, False otherwise.

list_secrets() -> list[datalayer_core.sdk.secrets.Secret]

List all secrets available in the Datalayer environment.

Returns

  • list[Secret]

    A list of Secret objects.

create_secret(name: str, description: str, value: str, secret_type: str = <SecretType.GENERIC: 'generic'>) -> 'Secret'

Create a new secret.

Parameters

  • name : str

    Name of the secret.

  • description : str

    Description of the secret.

  • value : str

    Value of the secret.

  • secret_type : str

    Type of the secret (e.g., "generic", "password", "key", "token").

Returns

  • Secret

    The created secret object.

delete_secret(secret: Union[str, datalayer_core.sdk.secrets.Secret]) -> dict[str, str]

Delete a secret by its unique identifier.

Parameters

  • secret : Union[str, Secret]

    Unique identifier of the secret or a Secret object.

Returns

  • dict[str, str]

    Response dictionary with deletion status.

create_snapshot(runtime: Optional[ForwardRef('Runtime')] = None, pod_name: Optional[str] = None, name: Optional[str] = None, description: Optional[str] = None, stop: bool = True) -> 'RuntimeSnapshot'

Create a snapshot of the current runtime state.

Parameters

  • runtime : Optional[Runtime]

    The runtime object to create a snapshot from.

  • pod_name : Optional[str]

    The pod name of the runtime.

  • name : Optional[str]

    Name for the new snapshot.

  • description : Optional[str]

    Description for the new snapshot.

  • stop : bool

    Whether to stop the runtime after creating snapshot.

Returns

  • RuntimeSnapshot

    The created snapshot object.

list_snapshots() -> list[datalayer_core.sdk.snapshots.RuntimeSnapshot]

List all snapshots.

Returns

  • list[RuntimeSnapshot]

    A list of snapshots associated with the user.

delete_snapshot(snapshot: Union[str, datalayer_core.sdk.snapshots.RuntimeSnapshot]) -> dict[str, str]

Delete a specific snapshot.

Parameters

  • snapshot : Union[str, RuntimeSnapshot]

    Snapshot object or UID string to delete.

Returns

  • dict[str, str]

    The result of the deletion operation.

create_token(name: str, description: str, expiration_date: int = 0, token_type: Union[str, datalayer_core.tokens.create.createapp.TokenType] = <TokenType.USER: 'user_token'>) -> dict[str, typing.Any]

Create a new token.

Parameters

  • name : str

    Name of the token.

  • description : str

    Description of the token.

  • expiration_date : int, default 0

    Expiration date of the token in seconds since epoch.

  • token_type : Union[str, TokenType], default TokenType.USER

    Type of the token (e.g., "user", "admin").

Returns

  • dict[str, Any]

    A dictionary containing the created token and its details.

list_tokens() -> list[datalayer_core.sdk.tokens.Token]

List all tokens.

Returns

  • list[Token]

    A list of tokens associated with the user.

delete_token(token: Union[str, datalayer_core.sdk.tokens.Token]) -> bool

Delete a specific token.

Parameters

  • token : Union[str, Token]

    Token object or UID string to delete.

Returns

  • bool

    The result of the deletion operation.