Skip to main content

Python SDK for Daytona

Project description

Daytona SDK for Python

A Python SDK for interacting with the Daytona API, providing a simple interface for Daytona Sandbox management, Git operations, file system operations, and language server protocol support.

Installation

You can install the package using pip:

pip install daytona

Quick Start

Here's a simple example of using the SDK:

from daytona import Daytona

# Initialize using environment variables
daytona = Daytona()

# Create a sandbox
sandbox = daytona.create()

# Run code in the sandbox
response = sandbox.process.code_run('print("Hello World!")')
print(response.result)

# Clean up when done
daytona.delete(sandbox)

Configuration

The SDK can be configured using environment variables or by passing a configuration object:

from daytona import Daytona, DaytonaConfig

# Initialize with configuration
config = DaytonaConfig(
    api_key="your-api-key",
    api_url="your-api-url",
    target="us"
)
daytona = Daytona(config)

Or using environment variables:

  • DAYTONA_API_KEY: Your Daytona API key
  • DAYTONA_API_URL: The Daytona API URL
  • DAYTONA_TARGET: Your target environment

You can also customize sandbox creation:

sandbox = daytona.create(CreateSandboxFromSnapshotParams(
    language="python",
    env_vars={"PYTHON_ENV": "development"},
    auto_stop_interval=60,  # Auto-stop after 1 hour of inactivity
    auto_archive_interval=60,  # Auto-archive after a Sandbox has been stopped for 1 hour
    auto_delete_interval=120 # Auto-delete after a Sandbox has been stopped for 2 hours
))

Features

  • Sandbox Management: Create, manage and remove sandboxes
  • Git Operations: Clone repositories, manage branches, and more
  • File System Operations: Upload, download, search and manipulate files
  • Language Server Protocol: Interact with language servers for code intelligence
  • Process Management: Execute code and commands in sandboxes

Examples

Execute Commands

# Execute a shell command
response = sandbox.process.exec('echo "Hello, World!"')
print(response.result)

# Run Python code
response = sandbox.process.code_run('''
x = 10
y = 20
print(f"Sum: {x + y}")
''')
print(response.result)

File Operations

# Upload a file
sandbox.fs.upload_file(b'Hello, World!', 'path/to/file.txt')

# Download a file
content = sandbox.fs.download_file('path/to/file.txt')

# Search for files
matches = sandbox.fs.find_files(root_dir, 'search_pattern')

Git Operations

# Clone a repository
sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')

# List branches
branches = sandbox.git.branches('path/to/repo')

# Add files
sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])

Language Server Protocol

# Create and start a language server
lsp = sandbox.create_lsp_server('typescript', 'path/to/project')
lsp.start()

# Notify the lsp for the file
lsp.did_open('path/to/file.ts')

# Get document symbols
symbols = lsp.document_symbols('path/to/file.ts')

# Get completions
completions = lsp.completions('path/to/file.ts', {"line": 10, "character": 15})

Contributing

Daytona is Open Source under the Apache License 2.0, and is the copyright of its contributors. If you would like to contribute to the software, read the Developer Certificate of Origin Version 1.1 (https://developercertificate.org/). Afterwards, navigate to the contributing guide to get started.

Code in _sync directory shouldn't be edited directly. It should be generated from the corresponding async code in the _async directory using the sync_generator.py script.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

daytona-0.22.1.tar.gz (91.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

daytona-0.22.1-py3-none-any.whl (114.4 kB view details)

Uploaded Python 3

File details

Details for the file daytona-0.22.1.tar.gz.

File metadata

  • Download URL: daytona-0.22.1.tar.gz
  • Upload date:
  • Size: 91.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.12 Linux/6.10.14-linuxkit

File hashes

Hashes for daytona-0.22.1.tar.gz
Algorithm Hash digest
SHA256 66798613a348c794953811492618530a399315d44a7930a65287c8d47c33dd49
MD5 5f4e82b8330fa127b1adbb8571b5fd9b
BLAKE2b-256 97754f7871325158dcb6151b6c226d272eb6c53c66622e2435cde79c4dd545c7

See more details on using hashes here.

File details

Details for the file daytona-0.22.1-py3-none-any.whl.

File metadata

  • Download URL: daytona-0.22.1-py3-none-any.whl
  • Upload date:
  • Size: 114.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.12 Linux/6.10.14-linuxkit

File hashes

Hashes for daytona-0.22.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f22cf8ef41f02ba5dc3ac189df8afe640ce147d6c232e69f63c7243589072e46
MD5 ba132d2ec856e2b71f7636c9a3c719d3
BLAKE2b-256 14483de02fe47e2171c0e1aa7def90727648e2d235200c75eb3c91427c50fc8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page