Skip to main content

Python SDK for Daytona

Project description

Daytona SDK for Python

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

Prerequisites

Before using the Daytona SDK, you need to have a running Daytona server instance and proper configuration.

Server Installation

For detailed instructions on installing and setting up the Daytona server, please refer to the official installation guide at: https://github.com/daytonaio/daytona

Configuration

To use the SDK, you'll need two essential pieces of information:

  1. Server Address:

    • Run daytona server config to get your server's configuration
    • Look for the API URL value in the output
    • For testing and development, you can use the FRP address provided
    • For production environments, it's recommended to use a static address
  2. API Key:

    • Generate a new API key by running:
      daytona api-key generate
      
    • Save this key securely as it will be needed to authenticate with the server

Installation

You can install the package using pip:

pip install daytona-sdk

Quick Start

Here's a simple example of using the SDK:

from daytona_sdk import Daytona

# Initialize the Daytona client
daytona = Daytona()

# Create the workspace instance
workspace = daytona.create()

# Run the code securely inside the workspace
response = workspace.process.code_run('print("Hello World!")')
print(response.result)

Features

  • Workspace Management: Create, manage and remove workspaces
  • 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 workspaces

Configuration

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

from daytona_sdk import Daytona, DaytonaConfig

config = DaytonaConfig(
    api_key='your-api-key',
    server_url='https://your-daytona-server',
    target='your-target'
)

daytona = Daytona(config)

Or using environment variables:

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

Examples

Execute command

response = workspace.process.code_run('print("Sum of 3 and 4 is " + str(3 + 4))')
if response.code != 0:
    print(f"Error: {response.code} {response.result}")
else:
    print(response.result)

File Operations

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

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

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

Git Operations

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

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

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

Language Server Protocol

# Create and start a language server
lsp = workspace.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

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache License, Version 2.0 - see below for details:

Copyright 2024 Daytona

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

For the full license text, please see the Apache License 2.0.

Project details


Release history Release notifications | RSS feed

This version

0.3.1

Download files

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

Source Distribution

daytona_sdk-0.3.1.tar.gz (72.2 kB view details)

Uploaded Source

Built Distribution

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

daytona_sdk-0.3.1-py3-none-any.whl (176.7 kB view details)

Uploaded Python 3

File details

Details for the file daytona_sdk-0.3.1.tar.gz.

File metadata

  • Download URL: daytona_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 72.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for daytona_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7b2836589845fe35a603feb8453a18da58d19905f3dbc54d5c59823513c397cd
MD5 b02b040d761d063ca80562abc1a34b1c
BLAKE2b-256 f8dcbf4c05df4da4177c7f80de7d0c13355b62773652f53d5068d44f77e713df

See more details on using hashes here.

File details

Details for the file daytona_sdk-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: daytona_sdk-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 176.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for daytona_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e6d91ceca86b905c0f178a98e1aa84e0b80b26d2dedc04290d1947e7810572e
MD5 17d833d41381c71d876d29d973eb1690
BLAKE2b-256 e76098b0d1bf868c670fa00b21c86ff0435ef2aef1386cdbe8607aae6bc04a1e

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