Templates let you define a computer environment once and launch multiple computers from it. Pre-install dependencies, clone repositories, and configure settings.
Quick Start
from orgo import Template, Computer
# Create a template
template = Template( "data-science" )
template.run( "pip install numpy pandas matplotlib" )
template.build()
# Launch computers from it
computer = Computer( template = "data-science" )
Creating Templates
Basic Template
from orgo import Template
# Initialize with a name
template = Template( "my-template" )
# Add commands to run during build
template.run( "apt-get update" )
template.run( "apt-get install -y python3-pip" )
template.run( "pip install requests beautifulsoup4" )
# Build and push to registry
template.build()
Chained Syntax
All methods return self for chaining:
template = Template( "web-scraper" )
template.run( "apt-get update && apt-get install -y chromium-browser" ) \
.run( "pip install selenium playwright" ) \
.env( "DISPLAY" , ":99" ) \
.build()
Template Methods
run(command)
Execute shell commands during build:
template.run( "apt-get update" )
template.run( "pip install pandas numpy scikit-learn" )
template.run( "npm install -g typescript" )
copy(src, dest)
Copy local files into the template:
template.copy( "./config.json" , "/app/config.json" )
template.copy( "./scripts" , "/app/scripts" )
The context parameter in build() controls the build context directory. Files must be within this directory to be copied.
env(key, value)
Set environment variables:
template.env( "PYTHONPATH" , "/app" )
template.env( "NODE_ENV" , "production" )
workdir(path)
Set the working directory:
clone(repo_url, dest)
Clone a git repository:
template.clone( "https://github.com/user/repo.git" )
template.clone( "https://github.com/user/repo.git" , "/app" )
build(context)
Build and publish the template:
# Build with current directory as context
template.build()
# Build with specific context
template.build( "./my-app" )
Using Templates
By Name
After building a template, reference it by name:
computer = Computer( template = "data-science" )
By Object
Pass the template object directly (builds automatically if needed):
template = Template( "ml-env" )
template.run( "pip install torch transformers" )
computer = Computer( template = template) # Builds automatically
In a Workspace
Store templates in a specific workspace:
template = Template( "prod-env" , workspace = "production" )
template.run( "pip install gunicorn" )
template.build()
# Use in the same workspace
computer = Computer( workspace = "production" , template = "prod-env" )
Examples
Python Data Science
from orgo import Template, Computer
template = Template( "python-ds" )
template.run( "apt-get update && apt-get install -y python3-pip" ) \
.run( "pip install numpy pandas matplotlib seaborn scikit-learn jupyter" ) \
.env( "PYTHONUNBUFFERED" , "1" ) \
.build()
computer = Computer( template = "python-ds" , ram = 8 )
computer.prompt( "Open Jupyter notebook and create a data analysis" )
Node.js Development
template = Template( "nodejs-dev" )
template.run( "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -" ) \
.run( "apt-get install -y nodejs" ) \
.run( "npm install -g yarn typescript ts-node" ) \
.workdir( "/app" ) \
.build()
computer = Computer( template = "nodejs-dev" )
Web Scraping
template = Template( "scraper" )
template.run( "apt-get update" ) \
.run( "apt-get install -y chromium-browser chromium-chromedriver" ) \
.run( "pip install selenium beautifulsoup4 requests" ) \
.build()
computer = Computer( template = "scraper" )
computer.prompt( "Scrape the top headlines from news.ycombinator.com" )
Custom Application
template = Template( "my-app" )
template.clone( "https://github.com/myorg/myapp.git" , "/app" ) \
.workdir( "/app" ) \
.run( "pip install -r requirements.txt" ) \
.copy( "./config.prod.json" , "/app/config.json" ) \
.env( "APP_ENV" , "production" ) \
.build( "." ) # Use current directory as build context for COPY
computer = Computer( template = "my-app" )
Requirements
Building templates requires Docker with BuildKit:
# Install Docker
# https://docs.docker.com/get-docker/
# Verify installation
docker --version
docker buildx version
The SDK automatically configures a remote builder that connects to Orgo’s build infrastructure.
Best Practices
Use descriptive template names
# Good
template = Template( "python-ml-pytorch" )
template = Template( "nodejs-18-typescript" )
# Avoid
template = Template( "env1" )
template = Template( "test" )
Combine commands to reduce layers
# Good - single layer
template.run( "apt-get update && apt-get install -y python3-pip git curl" )
# Less efficient - multiple layers
template.run( "apt-get update" )
template.run( "apt-get install -y python3-pip" )
template.run( "apt-get install -y git" )
template.run( "apt-get install -y curl" )
Clean up after installing
template.run( "apt-get update && apt-get install -y python3-pip && rm -rf /var/lib/apt/lists/*" )
Pin versions for reproducibility
template.run( "pip install numpy==1.24.0 pandas==2.0.0" )
Troubleshooting
Build fails with 'docker not found'
Install Docker Desktop or Docker Engine:
Build fails with connection error
The build uses Orgo’s remote builder. Ensure you have:
A valid ORGO_API_KEY set
Network access to orgoforge.fly.dev:1234
Template not found when launching computer
Make sure the template was built successfully: template = Template( "my-template" )
template.run( "pip install requests" )
image_ref = template.build() # Check this succeeds
print ( f "Built: { image_ref } " )
# Then use it
computer = Computer( template = "my-template" )