DEV Community

Cover image for Mastering Daytona Integration in Python: A Detailed Step-by-Step Guide ๐Ÿš€
Vraj Chaudhari
Vraj Chaudhari

Posted on

Mastering Daytona Integration in Python: A Detailed Step-by-Step Guide ๐Ÿš€

What is Daytona?

Daytona is an open-source Development Environment Manager (DEM) that simplifies development workflows, enabling you to create reproducible development environments based on OCI containers. In this guide, Iโ€™ll walk you through the process of integrating Daytona with a python project by demonstrating how, I integrated my python project Askpixie made using Reflex Framework, step by step.

Install Daytona on your Machine

To begin, visit the official Daytona documentation for installation:
Daytona Documentation
Daytona supports multiple platforms, including:

  • Linux

  • Windows

  • macOS

Since Iโ€™m using a macOS, I will proceed with the macOS installation.

Option 1: Install via Terminal (Recommended)
Run the following command directly in your terminal:

(curl -sf -L https://download.daytona.io/daytona/install.sh | sudo bash) && daytona server -y && daytona
Enter fullscreen mode Exit fullscreen mode

This will install Daytona and start the server automatically.

Option 2: Manual Installation

If you prefer manual installation, you can install Daytona in your desired path. For me, itโ€™s in the Documents folder.

Image of showing path for daytona installation

  1. Download Daytona (ARM64 for Apple Silicon):
# ARM64/Apple Silicon
curl -sf -L https://download.daytona.io/daytona/v0.49/daytona-darwin-arm64 -o daytona
Enter fullscreen mode Exit fullscreen mode

Note: For intel based macs, the above command is replaced with:

# x86-64/Intel-based
curl -sf -L https://download.daytona.io/daytona/v0.49/daytona-darwin-amd64 -o daytona
Enter fullscreen mode Exit fullscreen mode
  1. Once downloaded, make the file executable:
chmod +x ./daytona
Enter fullscreen mode Exit fullscreen mode

Installing Docker Desktop

Daytona requires Docker to run Workspaces. If you donโ€™t have Docker installed:

  • Download and install Docker Desktop.

  • Start the Docker Desktop application to ensure it runs in the background.

Start the Daytona Server

Once Daytona is installed

  1. Open the terminal and navigate to the directory where Daytona is installed. For me, itโ€™s in Documents:
cd ~/Documents
Enter fullscreen mode Exit fullscreen mode

To start the Daytona server, run:

./daytona serve
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can just run:

./daytona
Enter fullscreen mode Exit fullscreen mode

This will open the Daytona CLI, as shown below:

Daytona ClI

Here, press Enter on the daytona server option to start the Daytona server daemon. The CLI will prompt you to confirm:

Daytona Server Daemon

Once you click Yes, the Daytona server daemon will start, and you should see this message:

Server Started

Set Up Git Provider

To connect Daytona to your GitHub repository:

  • Open the Daytona CLI.

  • Select daytona git-provider add

it will show this type of window:
Since my project is hosted on GitHub, I will select GitHub.

git provider add

It will then ask for a Personal Access Token
Personal Access Token

You can get more details about creating PAT from here

Note: While creating PAT give this access to:

  • repo

  • read:user, user:email

  • admin:repo_hook

After giving PAT, you can choose Commit Signing Method:

Commit Signing Method

You can get more details about signature verification from here.

Once you complete all this your Git provider will be registered.

Set Up a Cloud Provider

To manage cloud environments such as AWS, Azure, or GCP, youโ€™ll need to install the necessary cloud provider. Run this command to set it up:

./daytona provider install
Enter fullscreen mode Exit fullscreen mode

Select Your Development Environment

A "Target" refers to the platform where your environment will run, such as Docker (local or remote), AWS, GCP, or other cloud services. Choose your target by running this command:

./daytona
Enter fullscreen mode Exit fullscreen mode

Then, select daytona target set from the CLI options:

daytona target set

I am running my environment locally using Docker, so I select local-docker.

Configure Your IDE

Daytona allows seamless integration with a range of IDEs, such as VS Code, IntelliJ, and others. To set up your preferred IDE, run the following command:

./daytona ide
Enter fullscreen mode Exit fullscreen mode

I am using VSCode (browser) one, but you can use any IDE of your choice.

Add the devcontainer.json to Your Repository

Create a .devcontainer/devcontainer.json file to define the development container setup. This file configures your development environment and ensures that all required dependencies are automatically installed.

You can manually create a devcontainer.json file, or use tools like Devcontainer AI to generate one for you. Below is the devcontainer.json I used for Askpixie:

Devcontainer.json

Create a Daytona Workspace

Now that Daytona is connected to GitHub and your cloud provider is set, itโ€™s time to create a workspace. Run the following command and provide the URL of your GitHub repository:

./daytona create <github repo url>
Enter fullscreen mode Exit fullscreen mode

Daytona will fetch your repository, create a workspace, and provision the development environment.

You Are All Set!

Daytona will now open your project in the selected IDE, and you can start developing your project without any setup headaches!

Troubleshooting: Permission Denied Error

On macOS, you might encounter a permission denied error while starting the Daytona server. To resolve this, use the following command to grant executable permissions:

chmod +x ./daytona
Enter fullscreen mode Exit fullscreen mode

Avoid using sudo to change permissions, as it can cause issues with workspace creation. The chmod command should resolve the issue.

Conclusion
By following this guide, youโ€™ve successfully integrated Daytona within your project and set up a smooth development environment. Daytona simplifies managing reproducible development environments, allowing you to focus on what matters most โ€” coding!

Top comments (0)