README
Datalayer Core
Datalayer Core
Ξ Datalayer Core
The foundational Python SDK for the Datalayer AI Platform
Overview
Datalayer Core is the foundational package that powers the Datalayer AI Platform. It provides both a Python SDK and Command Line Interface (CLI) for AI engineers, data scientists, and researchers to seamlessly integrate scalable compute runtimes into their workflows.
This package serves as the base foundation used by many other Datalayer packages, containing core application classes, configuration, and unified APIs for authentication, runtime management, and code execution in cloud-based environments.
Key Features
- 🔐 Simple Authentication: Easy token-based authentication with environment variable support
- ⚡ Runtime Management: Create and manage scalable compute runtimes (CPU/GPU) for code execution
- 📸 Snapshot Management: Create and manage compute snapshots of your runtimes for reproducible environments
- 🔒 Secrets Management: Securely handle sensitive data and credentials in your workflows
- 🐍 Python SDK: Programmatic access to Datalayer platform with context managers and clean resource management
- 🌐 TypeScript/React SDK: React components and services for building Jupyter-based applications
- 💻 Command Line Interface: CLI tools for managing runtimes, snapshots, and platform resources
- 🔧 Base Classes: Core application classes and configuration inherited by other Datalayer projects
- 📓 Jupyter Integration: ServiceManager and collaboration providers for notebook experiences
- 🧭 Universal Navigation: Smart navigation hooks that auto-detect and work with React Router, Next.js, or native browser
Installation
Python SDK
Install Datalayer Core using pip:
pip install datalayer-core
TypeScript/React SDK
Install as an npm package:
npm install @datalayer/core
Development Installation
git clone https://github.com/datalayer/core.git
cd core
# Python development
pip install -e .[test]
# TypeScript development
npm install
Quick Start with Python
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_core import DatalayerClient
# Using environment variable
client = DatalayerClient()
# Or pass token directly
client = DatalayerClient(token="your-token-here")
if client.authenticate():
print("Successfully authenticated!")
2. Execute Code in a Runtime
Use context managers to create runtimes and ensure proper resource cleanup:
from datalayer_core import DatalayerClient
client = DatalayerClient()
# Execute code in a managed runtime
with client.create_runtime() as runtime:
response = runtime.execute("print('Hello from Datalayer!')")
print(response.stdout)
3. Using the CLI
The CLI provides command-line access to Datalayer platform features:
# List available runtimes
datalayer runtime list
# Create a new runtime
datalayer runtime create ai-env --given-name my-runtime-123
# Execute a script in a runtime
datalayer runtime exec my-script.py --runtime <runtime-id>
# Create a snapshot from a runtime but do not terminate the runtime
datalayer snapshots create <pod-name> my-snapshot 'AI work!' False
Examples
Python Examples
For comprehensive Python usage examples, see the examples/
directory which includes:
- FastAPI + scikit-learn: Web application with ML models
- Streamlit + scikit-learn: Interactive data science apps
- PyTorch GPU workloads: High-performance computing examples
- Decorator patterns: Remote function execution with
@datalayer
- And more: Complete examples with documentation and setup instructions
TypeScript/React Examples
Run the interactive examples locally:
# Install dependencies
npm install
# Set your Datalayer API token in .env
echo "VITE_DATALAYER_API_TOKEN=your-token-here" > .env
# Start the examples server
npm run example
Available at http://localhost:3000/:
- DatalayerNotebookExample: Full integration with Datalayer services and collaboration
- NotebookExample: Basic Jupyter notebook in React
- CellExample: Individual code cell execution
- ReactRouterAdvancedExample: Comprehensive navigation demo with React Router integration
- ReactRouterNavigationExample: Basic navigation with route parameters
- NativeNavigationExample: Browser-native navigation fallback
Next.js Application Example
A complete Next.js application demonstrating platform integration:
cd examples/nextjs-notebook
npm install
npm run dev
Features:
- Token authentication with Datalayer IAM
- Browse and create notebooks from your workspace
- Select compute environments for execution
- Interactive notebook viewer with real-time outputs
- Clean, responsive UI with GitHub Primer components
Platform Integration
Datalayer adds AI capabilities and scalable compute runtimes to your development workflows. The platform is designed to seamlessly integrate into your existing processes and supercharge your computations with the processing power you need.
Key platform features accessible through this SDK and CLI:
- Remote Runtimes: Execute code on powerful remote machines with CPU, RAM, and GPU resources
- Multiple Interfaces: Access and consume runtimes through Python SDK, CLI, or other integrated tools
- Scalable Compute: Dynamically scale your computational resources based on workload requirements
Documentation
- Command Line Interface (CLI): https://docs.datalayer.app/cli/
- Core Python SDK: core.datalayer.tech/python/
- Platform Documentation: docs.datalayer.app
- API Reference: API documentation
Development
Building the Library
# Build TypeScript library
npm run build:lib
# Build Python package
python -m build
Setup
# Install Python dependencies
pip install -e .[test]
# Install TypeScript dependencies
npm install
Code Quality
This project maintains high code quality standards with automated linting, formatting, and type checking:
# Run all checks (format, lint, type-check)
npm run check
# Auto-fix all issues
npm run check:fix
# Individual commands
npm run lint # ESLint with React/TypeScript rules
npm run lint:fix # Auto-fix linting issues
npm run format # Prettier formatting
npm run format:check # Check formatting without changes
npm run type-check # TypeScript compilation check
Pre-commit hooks automatically run formatting and linting on staged files via Husky and lint-staged.
Running Tests
# Python tests
pip install -e .[test]
pytest datalayer_core/tests/
# TypeScript tests
npm run test
# TypeScript type checking
npm run type-check
npm run test:watch # Watch mode
npm run test:coverage # With coverage
Contributing
This SDK is designed to be simple and extensible. We welcome contributions! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
For issues and enhancement requests, please use the GitHub issue tracker.
Architecture
Datalayer Core serves as the foundation for the entire Datalayer ecosystem:
- Base Classes: Core application classes inherited by other Datalayer packages
- Configuration Management: Centralized configuration system for all Datalayer components
- Authentication Layer: Unified authentication across all Datalayer services
- Runtime Abstraction: Common interface for different types of compute runtimes
- Resource Management: Automatic cleanup and lifecycle management
Use Cases
- AI/ML Development: Scale your machine learning workflows with cloud compute using SDK or CLI
- Data Analysis: Process large datasets with powerful remote runtimes
- Research: Collaborate on computational research with reproducible environments
- Automation: Integrate Datalayer into CI/CD pipelines and automated workflows using CLI tools
- Prototyping: Quickly test ideas without local hardware limitations
License
This project is licensed under the BSD 3-Clause License.
Support
- Documentation: Datalayer Platform Documentation
- Issues: GitHub Issues
- Community: Datalayer Platform
🚀 AI Platform for Data Analysis
Get started with Datalayer today!