Python SDK
A simple, intuitive SDK for AI engineers to work with the Datalayer platform.
This SDK provides a unified interface for authentication, runtime creation, and code execution in Datalayer Runtimes.
Features
- Simple Authentication: Easy token-based authentication with environment variable support
- Runtime Management: Create and manage compute runtimes (CPU/GPU) for code execution
- Runtime Snapshot Management: Create and manage compute snapshots of your runtimes
- Context Managers: Clean resource management with Python context managers
Installation
pip install datalayer_core
Quick Start
1. Authentication
Set your Datalayer token as an environment variable:
export DATALAYER_TOKEN="your-token-here"
Or pass it directly to the SDK:
from datalayer import DatalayerClient
client = DatalayerClient(token="your-token-here")
if client.authenticate():
print("Successfully authenticated!")
2. Execute Code in a Runtime
You can use a context manager to create a Runtime and ensure it is correctly terminated after code execution.
from datalayer_core import DatalayerClient
client = DatalayerClient()
with client.create_runtime() as runtime:
response = runtime.execute("Hello world!")
print(response.stdout)
3. Save a Runtime Snapshot
TODO
from datalayer_core import DatalayerClient
client = DatalayerClient()
with client.create_runtime() as runtime:
response = runtime.execute("a = 123")
print(response.stdout)
snapshot = runtime.create_snapshot(stop=False)
print(snapshot)
4. Set Secrets
TODO
from datalayer_core import DatalayerClient
client = DatalayerClient()
created_secret = client.create_secret(
name="MY_SECRET",
description="This is a test secret",
value="super_secret_value!",
)
print(created_secret)
# Use your secret!
with client.create_runtime() as runtime:
response = runtime.execute("import os;print(len(os.environ["MY_SECRET"]))")
print(response.stdout)
Contributing
This SDK is designed to be simple and extensible. Feel free to submit issues and enhancement requests!
License
This SDK is open source software licensed under the BSD 3-Clause License.