langchain-daytona-data-analysis 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 LangChain, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: langchain-daytona-data-analysis
3
+ Version: 0.1.0
4
+ Summary: An integration package connecting DaytonaDataAnalysis and LangChain
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.9,<4.0
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Requires-Dist: daytona (>=0.113.2,<0.114.0)
17
+ Requires-Dist: langchain-core (>=0.3.15,<0.4.0)
18
+ Project-URL: Repository, https://github.com/langchain-ai/langchain
19
+ Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22daytona-data-analysis%3D%3D0%22&expanded=true
20
+ Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/partners/daytona-data-analysis
21
+ Description-Content-Type: text/markdown
22
+
23
+ # langchain-daytona-data-analysis
24
+
25
+ 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.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install -U langchain-daytona-data-analysis
31
+ ```
32
+ The `daytona` package must also be installed to use `DaytonaDataAnalysisTool`:
33
+ ```bash
34
+ pip install -U daytona
35
+ ```
36
+
37
+ You must configure credentials for Daytona. You can do this in one of three ways:
38
+
39
+ 1. Set the `DAYTONA_API_KEY` environment variable:
40
+ ```bash
41
+ export DAYTONA_API_KEY="your-daytona-api-key"
42
+ ```
43
+
44
+ 2. Add it to a `.env` file in your project root:
45
+ ```env
46
+ DAYTONA_API_KEY=your-daytona-api-key
47
+ ```
48
+
49
+ 3. Pass the API key directly when instantiating `DaytonaDataAnalysisTool`:
50
+ ```python
51
+ from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
52
+
53
+ tool = DaytonaDataAnalysisTool(daytona_api_key="your-daytona-api-key")
54
+ ```
55
+
56
+ ## Instantiation
57
+
58
+ Import and instantiate the tool:
59
+
60
+ ```python
61
+ from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
62
+ from daytona import ExecutionArtifacts
63
+
64
+ # Optionally, you can pass an on_result callback.
65
+ # This callback lets you apply custom logic to the data analysis result.
66
+ # For example, you can save outputs, display charts, or trigger other actions.
67
+ def process_data_analysis_result(result: ExecutionArtifacts):
68
+ print(result)
69
+
70
+ tool = DaytonaDataAnalysisTool(
71
+ daytona_api_key="your-daytona-api-key", # Only pass if not set as DAYTONA_API_KEY environment variable
72
+ on_result=process_data_analysis_result
73
+ )
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ `DaytonaDataAnalysisTool` can be used in three ways:
79
+
80
+
81
+ ### Direct Invocation with Args
82
+
83
+ ```python
84
+ tool.invoke({'data_analysis_python_code': "print('Hello World')"})
85
+ ```
86
+
87
+ ### Invocation with ToolCall
88
+
89
+ ```python
90
+ model_generated_tool_call = {
91
+ "args": {'data_analysis_python_code': "print('Hello World')"},
92
+ "id": "1",
93
+ "name": tool.name,
94
+ "type": "tool_call",
95
+ }
96
+
97
+ tool.invoke(model_generated_tool_call)
98
+ ```
99
+
100
+ ### Usage Inside an Agent
101
+
102
+ ```python
103
+ from langchain.agents import create_agent
104
+ from langchain_anthropic import ChatAnthropic
105
+
106
+ model = ChatAnthropic(
107
+ model_name="claude-haiku-4-5-20251001",
108
+ temperature=0,
109
+ max_tokens_to_sample=1024,
110
+ timeout=None,
111
+ max_retries=2,
112
+ stop=None
113
+ )
114
+
115
+ agent = create_agent(model, tools=[tool])
116
+ ```
117
+
118
+ ## API Reference
119
+
120
+ The following public methods are available on `DaytonaDataAnalysisTool`:
121
+
122
+ ### `download_file(remote_path)`
123
+ Downloads a file from the sandbox by its remote path.
124
+ - `remote_path`: `str` — Path to the file in the sandbox.
125
+ - **Returns:** `bytes` — File contents.
126
+
127
+ **Example:**
128
+ ```python
129
+ # Download a file from the sandbox
130
+ file_bytes = tool.download_file("/home/daytona/results.csv")
131
+ ```
132
+
133
+ ---
134
+
135
+ ### `upload_file(file, description)`
136
+ Uploads a file to the sandbox. The file is placed in `/home/daytona/`.
137
+ - `file`: `IO` — File-like object to upload.
138
+ - `description`: `str` — Description of the file, explaining its purpose and the type of data it contains.
139
+ - **Returns:** [`SandboxUploadedFile`](#sandboxuploadedfile) — Metadata about the uploaded file.
140
+
141
+ **Example:**
142
+ 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.
143
+
144
+ ```python
145
+ with open("sales_q3_2025.csv", "rb") as f:
146
+ uploaded = tool.upload_file(
147
+ f,
148
+ "CSV file containing Q3 2025 retail sales transactions. Columns: transaction_id, date, product, quantity, revenue."
149
+ )
150
+ ```
151
+
152
+ ---
153
+
154
+ ### `remove_uploaded_file(uploaded_file)`
155
+ Removes a previously uploaded file from the sandbox.
156
+ - `uploaded_file`: [`SandboxUploadedFile`](#sandboxuploadedfile) — The file to remove.
157
+
158
+ **Example:**
159
+ ```python
160
+ # Remove an uploaded file
161
+ tool.remove_uploaded_file(uploaded)
162
+ ```
163
+
164
+ ---
165
+
166
+ ### `get_sandbox()`
167
+ Gets the current sandbox instance.
168
+ - **Returns:** [`Sandbox`](#sandbox) — Sandbox instance.
169
+
170
+ 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](#sandbox) data structure section below.
171
+
172
+ **Example:**
173
+ ```python
174
+ sandbox = tool.get_sandbox()
175
+ ```
176
+
177
+ ---
178
+
179
+ ### `install_python_packages(package_names)`
180
+ Installs one or more Python packages in the sandbox using pip.
181
+ - `package_names`: `str` or `List[str]` — Name(s) of the package(s) to install.
182
+
183
+ > **Note:** The list of preinstalled packages in a sandbox can be found at [Daytona Default Snapshot documentation](https://www.daytona.io/docs/en/snapshots/#default-snapshot).
184
+
185
+ **Example:**
186
+ ```python
187
+ # Install a single package
188
+ tool.install_python_packages("pandas")
189
+
190
+ # Install multiple packages
191
+ tool.install_python_packages(["numpy", "matplotlib"])
192
+ ```
193
+
194
+ ---
195
+
196
+ ### `close()`
197
+ Closes and deletes the sandbox environment.
198
+
199
+ > **Note:** Call this method when you are finished with all data analysis tasks to properly clean up resources and avoid unnecessary usage.
200
+
201
+ **Example:**
202
+ ```python
203
+ # Close the sandbox and clean up
204
+ tool.close()
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Data Structures
210
+
211
+ ### SandboxUploadedFile
212
+ Represents metadata about a file uploaded to the sandbox.
213
+
214
+ - `name`: `str` — Name of the uploaded file in the sandbox
215
+ - `remote_path`: `str` — Full path to the file in the sandbox
216
+ - `description`: `str` — Description provided during upload
217
+
218
+ ### Sandbox
219
+ Represents a Daytona sandbox instance.
220
+
221
+ See the full structure and API in the [Daytona Python SDK Sandbox documentation](https://www.daytona.io/docs/en/python-sdk/sync/sandbox/#sandbox).
222
+
@@ -0,0 +1,199 @@
1
+ # langchain-daytona-data-analysis
2
+
3
+ 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.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install -U langchain-daytona-data-analysis
9
+ ```
10
+ The `daytona` package must also be installed to use `DaytonaDataAnalysisTool`:
11
+ ```bash
12
+ pip install -U daytona
13
+ ```
14
+
15
+ You must configure credentials for Daytona. You can do this in one of three ways:
16
+
17
+ 1. Set the `DAYTONA_API_KEY` environment variable:
18
+ ```bash
19
+ export DAYTONA_API_KEY="your-daytona-api-key"
20
+ ```
21
+
22
+ 2. Add it to a `.env` file in your project root:
23
+ ```env
24
+ DAYTONA_API_KEY=your-daytona-api-key
25
+ ```
26
+
27
+ 3. Pass the API key directly when instantiating `DaytonaDataAnalysisTool`:
28
+ ```python
29
+ from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
30
+
31
+ tool = DaytonaDataAnalysisTool(daytona_api_key="your-daytona-api-key")
32
+ ```
33
+
34
+ ## Instantiation
35
+
36
+ Import and instantiate the tool:
37
+
38
+ ```python
39
+ from langchain_daytona_data_analysis import DaytonaDataAnalysisTool
40
+ from daytona import ExecutionArtifacts
41
+
42
+ # Optionally, you can pass an on_result callback.
43
+ # This callback lets you apply custom logic to the data analysis result.
44
+ # For example, you can save outputs, display charts, or trigger other actions.
45
+ def process_data_analysis_result(result: ExecutionArtifacts):
46
+ print(result)
47
+
48
+ tool = DaytonaDataAnalysisTool(
49
+ daytona_api_key="your-daytona-api-key", # Only pass if not set as DAYTONA_API_KEY environment variable
50
+ on_result=process_data_analysis_result
51
+ )
52
+ ```
53
+
54
+ ## Usage
55
+
56
+ `DaytonaDataAnalysisTool` can be used in three ways:
57
+
58
+
59
+ ### Direct Invocation with Args
60
+
61
+ ```python
62
+ tool.invoke({'data_analysis_python_code': "print('Hello World')"})
63
+ ```
64
+
65
+ ### Invocation with ToolCall
66
+
67
+ ```python
68
+ model_generated_tool_call = {
69
+ "args": {'data_analysis_python_code': "print('Hello World')"},
70
+ "id": "1",
71
+ "name": tool.name,
72
+ "type": "tool_call",
73
+ }
74
+
75
+ tool.invoke(model_generated_tool_call)
76
+ ```
77
+
78
+ ### Usage Inside an Agent
79
+
80
+ ```python
81
+ from langchain.agents import create_agent
82
+ from langchain_anthropic import ChatAnthropic
83
+
84
+ model = ChatAnthropic(
85
+ model_name="claude-haiku-4-5-20251001",
86
+ temperature=0,
87
+ max_tokens_to_sample=1024,
88
+ timeout=None,
89
+ max_retries=2,
90
+ stop=None
91
+ )
92
+
93
+ agent = create_agent(model, tools=[tool])
94
+ ```
95
+
96
+ ## API Reference
97
+
98
+ The following public methods are available on `DaytonaDataAnalysisTool`:
99
+
100
+ ### `download_file(remote_path)`
101
+ Downloads a file from the sandbox by its remote path.
102
+ - `remote_path`: `str` — Path to the file in the sandbox.
103
+ - **Returns:** `bytes` — File contents.
104
+
105
+ **Example:**
106
+ ```python
107
+ # Download a file from the sandbox
108
+ file_bytes = tool.download_file("/home/daytona/results.csv")
109
+ ```
110
+
111
+ ---
112
+
113
+ ### `upload_file(file, description)`
114
+ Uploads a file to the sandbox. The file is placed in `/home/daytona/`.
115
+ - `file`: `IO` — File-like object to upload.
116
+ - `description`: `str` — Description of the file, explaining its purpose and the type of data it contains.
117
+ - **Returns:** [`SandboxUploadedFile`](#sandboxuploadedfile) — Metadata about the uploaded file.
118
+
119
+ **Example:**
120
+ 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.
121
+
122
+ ```python
123
+ with open("sales_q3_2025.csv", "rb") as f:
124
+ uploaded = tool.upload_file(
125
+ f,
126
+ "CSV file containing Q3 2025 retail sales transactions. Columns: transaction_id, date, product, quantity, revenue."
127
+ )
128
+ ```
129
+
130
+ ---
131
+
132
+ ### `remove_uploaded_file(uploaded_file)`
133
+ Removes a previously uploaded file from the sandbox.
134
+ - `uploaded_file`: [`SandboxUploadedFile`](#sandboxuploadedfile) — The file to remove.
135
+
136
+ **Example:**
137
+ ```python
138
+ # Remove an uploaded file
139
+ tool.remove_uploaded_file(uploaded)
140
+ ```
141
+
142
+ ---
143
+
144
+ ### `get_sandbox()`
145
+ Gets the current sandbox instance.
146
+ - **Returns:** [`Sandbox`](#sandbox) — Sandbox instance.
147
+
148
+ 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](#sandbox) data structure section below.
149
+
150
+ **Example:**
151
+ ```python
152
+ sandbox = tool.get_sandbox()
153
+ ```
154
+
155
+ ---
156
+
157
+ ### `install_python_packages(package_names)`
158
+ Installs one or more Python packages in the sandbox using pip.
159
+ - `package_names`: `str` or `List[str]` — Name(s) of the package(s) to install.
160
+
161
+ > **Note:** The list of preinstalled packages in a sandbox can be found at [Daytona Default Snapshot documentation](https://www.daytona.io/docs/en/snapshots/#default-snapshot).
162
+
163
+ **Example:**
164
+ ```python
165
+ # Install a single package
166
+ tool.install_python_packages("pandas")
167
+
168
+ # Install multiple packages
169
+ tool.install_python_packages(["numpy", "matplotlib"])
170
+ ```
171
+
172
+ ---
173
+
174
+ ### `close()`
175
+ Closes and deletes the sandbox environment.
176
+
177
+ > **Note:** Call this method when you are finished with all data analysis tasks to properly clean up resources and avoid unnecessary usage.
178
+
179
+ **Example:**
180
+ ```python
181
+ # Close the sandbox and clean up
182
+ tool.close()
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Data Structures
188
+
189
+ ### SandboxUploadedFile
190
+ Represents metadata about a file uploaded to the sandbox.
191
+
192
+ - `name`: `str` — Name of the uploaded file in the sandbox
193
+ - `remote_path`: `str` — Full path to the file in the sandbox
194
+ - `description`: `str` — Description provided during upload
195
+
196
+ ### Sandbox
197
+ Represents a Daytona sandbox instance.
198
+
199
+ See the full structure and API in the [Daytona Python SDK Sandbox documentation](https://www.daytona.io/docs/en/python-sdk/sync/sandbox/#sandbox).
@@ -0,0 +1,15 @@
1
+ from importlib import metadata
2
+
3
+ from langchain_daytona_data_analysis.tools import DaytonaDataAnalysisTool
4
+
5
+ try:
6
+ __version__ = metadata.version(__package__)
7
+ except metadata.PackageNotFoundError:
8
+ # Case where package metadata is not available.
9
+ __version__ = ""
10
+ del metadata # optional, avoids polluting the results of dir(__package__)
11
+
12
+ __all__ = [
13
+ "DaytonaDataAnalysisTool",
14
+ "__version__",
15
+ ]