An integration package connecting DaytonaDataAnalysis and LangChain
Project description
langchain-daytona-data-analysis
This package provides the DaytonaDataAnalysisTool - LangChain tool integration that enables agents to perform secure Python data analysis in a sandboxed environment. It supports multi-step workflows, file uploads/downloads, and custom result handling, making it ideal for automating data analysis tasks with LangChain agents.
Installation
pip install -U langchain-daytona-data-analysis
You must configure credentials for Daytona. You can do this in one of three ways:
-
Set the
DAYTONA_API_KEYenvironment variable:export DAYTONA_API_KEY="your-daytona-api-key"
-
Add it to a
.envfile in your project root:DAYTONA_API_KEY=your-daytona-api-key
-
Pass the API key directly when instantiating
DaytonaDataAnalysisTool:from langchain_daytona_data_analysis import DaytonaDataAnalysisTool tool = DaytonaDataAnalysisTool(daytona_api_key="your-daytona-api-key")
Instantiation
Import and instantiate the tool:
from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
from daytona import ExecutionArtifacts
# Optionally, you can pass an on_result callback.
# This callback lets you apply custom logic to the data analysis result.
# For example, you can save outputs, display charts, or trigger other actions.
def process_data_analysis_result(result: ExecutionArtifacts):
print(result)
tool = DaytonaDataAnalysisTool(
daytona_api_key="your-daytona-api-key", # Only pass if not set as DAYTONA_API_KEY environment variable
on_result=process_data_analysis_result
)
Usage
DaytonaDataAnalysisTool can be used in three ways:
Direct Invocation with Args
tool.invoke({'data_analysis_python_code': "print('Hello World')"})
Invocation with ToolCall
model_generated_tool_call = {
"args": {'data_analysis_python_code': "print('Hello World')"},
"id": "1",
"name": tool.name,
"type": "tool_call",
}
tool.invoke(model_generated_tool_call)
Usage Inside an Agent
from langchain.agents import create_agent
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
model_name="claude-haiku-4-5-20251001",
temperature=0,
max_tokens_to_sample=1024,
timeout=None,
max_retries=2,
stop=None
)
agent = create_agent(model, tools=[tool])
API Reference
The following public methods are available on DaytonaDataAnalysisTool:
download_file(remote_path)
Downloads a file from the sandbox by its remote path.
remote_path:str— Path to the file in the sandbox.- Returns:
bytes— File contents.
Example:
# Download a file from the sandbox
file_bytes = tool.download_file("/home/daytona/results.csv")
upload_file(file, description)
Uploads a file to the sandbox. The file is placed in /home/daytona/.
file:IO— File-like object to upload.description:str— Description of the file, explaining its purpose and the type of data it contains.- Returns:
SandboxUploadedFile— Metadata about the uploaded file.
Example:
Suppose you want to analyze sales data for a retail business. You have a CSV file named sales_q3_2025.csv containing columns like transaction_id, date, product, quantity, and revenue. You want to upload this file and provide a description that gives context for the analysis.
with open("sales_q3_2025.csv", "rb") as f:
uploaded = tool.upload_file(
f,
"CSV file containing Q3 2025 retail sales transactions. Columns: transaction_id, date, product, quantity, revenue."
)
remove_uploaded_file(uploaded_file)
Removes a previously uploaded file from the sandbox.
uploaded_file:SandboxUploadedFile— The file to remove.
Example:
# Remove an uploaded file
tool.remove_uploaded_file(uploaded)
get_sandbox()
Gets the current sandbox instance.
- Returns:
Sandbox— Sandbox instance.
This method provides access to the Daytona sandbox instance, allowing you to inspect sandbox properties and metadata, as well as perform any sandbox-related operations. For details on available attributes and methods, see the Sandbox data structure section below.
Example:
sandbox = tool.get_sandbox()
install_python_packages(package_names)
Installs one or more Python packages in the sandbox using pip.
package_names:strorList[str]— Name(s) of the package(s) to install.
Note: The list of preinstalled packages in a sandbox can be found at Daytona Default Snapshot documentation.
Example:
# Install a single package
tool.install_python_packages("pandas")
# Install multiple packages
tool.install_python_packages(["numpy", "matplotlib"])
close()
Closes and deletes the sandbox environment.
Note: Call this method when you are finished with all data analysis tasks to properly clean up resources and avoid unnecessary usage.
Example:
# Close the sandbox and clean up
tool.close()
Data Structures
SandboxUploadedFile
Represents metadata about a file uploaded to the sandbox.
name:str— Name of the uploaded file in the sandboxremote_path:str— Full path to the file in the sandboxdescription:str— Description provided during upload
Sandbox
Represents a Daytona sandbox instance.
See the full structure and API in the Daytona Python SDK Sandbox documentation.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_daytona_data_analysis-0.1.1.tar.gz.
File metadata
- Download URL: langchain_daytona_data_analysis-0.1.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.9.6 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
921ecdf98d5343cc6b4865cc1d031aaf58623273142b89e6d318c5444dbc1519
|
|
| MD5 |
d2776330ebb2ee0a954d93d1cd80f49d
|
|
| BLAKE2b-256 |
16565f7cb1d8f3985217d862b999196152048abef7c16711a4181c71e3d3b313
|
File details
Details for the file langchain_daytona_data_analysis-0.1.1-py3-none-any.whl.
File metadata
- Download URL: langchain_daytona_data_analysis-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.9.6 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c974c7f8777d24888321e7dfaf8e07e53462b822f478fe3ebefc7613c271d689
|
|
| MD5 |
4085ad55e91bfc9e8d956d9e4b1f11bb
|
|
| BLAKE2b-256 |
e8683f38374f5e5306a5a05c8728678fe221e1d434bd72da98e7712ed39c062e
|