morphcloud 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 Morph
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,190 @@
1
+ Metadata-Version: 2.1
2
+ Name: morphcloud
3
+ Version: 0.1.0
4
+ Summary: A CLI tool for creating, managing, and interacting with Morph Cloud Runtimes.
5
+ Home-page: https://github.com/morph-labs/morphcloud
6
+ Author: Morph Labs
7
+ Author-email: jobs@morph.so
8
+ Project-URL: Bug Tracker, https://github.com/morph-labs/morphcloud/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.7
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests
16
+ Requires-Dist: tqdm
17
+ Requires-Dist: argparse
18
+ Requires-Dist: shutil
19
+ Requires-Dist: psutil
20
+ Requires-Dist: streamlit
21
+ Requires-Dist: anthropic
22
+ Requires-Dist: openai
23
+ Requires-Dist: pillow
24
+ Requires-Dist: httpx
25
+ Requires-Dist: fire
26
+ Requires-Dist: playwright
27
+ Requires-Dist: bs4
28
+ Requires-Dist: click
29
+ Requires-Dist: pytest
30
+ Requires-Dist: pydantic
31
+ Requires-Dist: httpx
32
+
33
+ # MorphCloud Python SDK
34
+
35
+ ## Overview
36
+
37
+ MorphCloud is a platform designed to spin up remote AI devboxes we call runtimes. It provides a suite of code intelligence tools and a Python SDK to manage, create, delete, and interact with runtime instances.
38
+
39
+ ## Setup Guide
40
+
41
+ ### Prerequisites
42
+
43
+ Python 3.8 or higher
44
+
45
+ Go to [https//:cloud.morph.so](http://cloud.morph.so), log in with the provided credentials and create an API key.
46
+
47
+ Set the API key as an environment variable MORPH\_API\_KEY.
48
+
49
+ ### Installation
50
+
51
+ ```
52
+ git clone https://github.com/morph-labs/morph-python-sdk.git
53
+ cd morphcloud
54
+ ```
55
+ (activate any python environment as needed)...
56
+ ```
57
+ pip install -e .
58
+ ```
59
+
60
+ export MORPH\_API\_KEY=your\_api\_key\_here
61
+
62
+ ## Quick Start
63
+
64
+ To start using MorphCloud, you can create and manage runtime instances using the provided classes and methods. Here's a basic example to create a runtime instance:
65
+
66
+ ```py
67
+ from morphcloud import Runtime
68
+
69
+ runtime = Runtime.create() # This will print a url allowing you to view the runtime remote desktop url
70
+
71
+ # The runtime instance is stopped and deleted upon script termination.
72
+
73
+ # Alternatively you could create a runtime only for a specific function using:
74
+
75
+ with Runtime.create() as runtime:
76
+ # You can perform any actions inside of the environment in here.
77
+ # .....
78
+ result = runtime.execute.semantic_search (query="a function that ...", max_results=5)
79
+ )
80
+ print(result) # {success:True, result: {results: [...]}}
81
+ func_refs = results [0]['refs']
82
+
83
+ linter_result = runtime.execute.lint(files = ["my_repo/file1.py", "my_repo/file2.py"])
84
+
85
+
86
+ # Outside of the with scope the runtime instance is stopped and deleted.
87
+ ```
88
+
89
+ ## Configure the Runtime
90
+
91
+ You can create a runtime environment that automatically executes a setup script in two ways:
92
+
93
+ ```py
94
+ runtime = Runtime.create(setup="/local_path/to/setup_script")
95
+ # Alternatively
96
+ runtime = Runtime.create(setup=[
97
+ "sudo apt update",
98
+ "sudo apt install -y tmux git build-essential",
99
+ "git clone my_public_repo_url.git"
100
+ ]
101
+ ```
102
+
103
+ You can also customize the VM configurations:
104
+
105
+ ```py
106
+ runtime = Runtime.create(
107
+ vcpus=2, # number of cpus
108
+ memory=2048, # mb
109
+ )
110
+ ```
111
+
112
+ ## Connecting to a Runtime
113
+
114
+ If you created a runtime instance from the web UI and you wish to connect to it:
115
+
116
+ ```py
117
+ from morphcloud import Runtime
118
+
119
+ runtime = Runtime.create(id=YOUR_RUNTIME_ID)
120
+
121
+ # Stop it manually on cloud.morph.so or using
122
+ runtime.stop()
123
+ ```
124
+
125
+ ## Saving a Runtime
126
+
127
+ To save the state of the remote runtime for future use:
128
+
129
+ ```py
130
+ from morphcloud import Runtime
131
+
132
+ with Runtime.create() as runtime:
133
+ # You can perform any actions inside of the environment in here.
134
+ # .....
135
+ result = runtime.execute.terminal_command(command="npm start", terminal_name="optional_name")) # This will run async on the runtime environment.
136
+ terminal_status = runtime.execute.observe_terminals() # This will return a dict with the most recent outputs of all active terminals in the runtime.
137
+ snapshot_id = runtime.snapshot.create()
138
+
139
+
140
+ Runtime.snapshot.list() # returns a list of all snapshot_ids
141
+
142
+ ```
143
+
144
+ To create a new runtime instance from the same point where `npm start` is running:
145
+
146
+ ```py
147
+ runtime = Runtime.create(snapshot_id = YOUR_SNAPSHOT_ID)
148
+
149
+ # To delete a snapshot
150
+ _ = Runtime.snapshot.delete(YOUR_SNAPSHOT_ID)
151
+ ```
152
+
153
+ ### Cloning
154
+
155
+ If you would like to run multiple instances in parallel to do a task in the same environment:
156
+
157
+ ```py
158
+ from morphcloud import Runtime
159
+
160
+ runtime = Runtime.create()
161
+ # You can perform any actions inside of the environment in here.
162
+ # .....
163
+ runtimes = runtime.clone(5) # creates a list of 5 runtime objects.
164
+
165
+ for r in runtimes:
166
+ # do stuff...
167
+
168
+ # all runtime instances are terminated upon script completion.
169
+ ```
170
+
171
+ ## AI Integration
172
+
173
+ MorphCloud provides built-in support for integrating with AI models through standardized tool formats. You can easily convert runtime actions to formats compatible with popular AI models:
174
+
175
+ ```python
176
+ from morphcloud import Runtime
177
+
178
+ runtime = Runtime.create()
179
+
180
+ # Get tools in Anthropic's format
181
+ anthropic_tools = runtime.actions.as_anthropic_tools()
182
+
183
+ # Get tools in OpenAI's function calling format
184
+ openai_tools = runtime.actions.as_openai_tools()
185
+
186
+ ```
187
+
188
+ ## Examples
189
+
190
+ There are several examples in the `examples` directory. Notably, there are two key examples: [search.py](https://github.com/morph-labs/morphcloud/blob/main/examples/search.py), which showcases repository cloning, semantic code search, and function analysis, and [agent_skeleton.py](https://github.com/morph-labs/morphcloud/blob/main/examples/agent_skeleton.py), which provides a good starting point to create simple AI agents that interact with the cloud development environment.
@@ -0,0 +1,158 @@
1
+ # MorphCloud Python SDK
2
+
3
+ ## Overview
4
+
5
+ MorphCloud is a platform designed to spin up remote AI devboxes we call runtimes. It provides a suite of code intelligence tools and a Python SDK to manage, create, delete, and interact with runtime instances.
6
+
7
+ ## Setup Guide
8
+
9
+ ### Prerequisites
10
+
11
+ Python 3.8 or higher
12
+
13
+ Go to [https//:cloud.morph.so](http://cloud.morph.so), log in with the provided credentials and create an API key.
14
+
15
+ Set the API key as an environment variable MORPH\_API\_KEY.
16
+
17
+ ### Installation
18
+
19
+ ```
20
+ git clone https://github.com/morph-labs/morph-python-sdk.git
21
+ cd morphcloud
22
+ ```
23
+ (activate any python environment as needed)...
24
+ ```
25
+ pip install -e .
26
+ ```
27
+
28
+ export MORPH\_API\_KEY=your\_api\_key\_here
29
+
30
+ ## Quick Start
31
+
32
+ To start using MorphCloud, you can create and manage runtime instances using the provided classes and methods. Here's a basic example to create a runtime instance:
33
+
34
+ ```py
35
+ from morphcloud import Runtime
36
+
37
+ runtime = Runtime.create() # This will print a url allowing you to view the runtime remote desktop url
38
+
39
+ # The runtime instance is stopped and deleted upon script termination.
40
+
41
+ # Alternatively you could create a runtime only for a specific function using:
42
+
43
+ with Runtime.create() as runtime:
44
+ # You can perform any actions inside of the environment in here.
45
+ # .....
46
+ result = runtime.execute.semantic_search (query="a function that ...", max_results=5)
47
+ )
48
+ print(result) # {success:True, result: {results: [...]}}
49
+ func_refs = results [0]['refs']
50
+
51
+ linter_result = runtime.execute.lint(files = ["my_repo/file1.py", "my_repo/file2.py"])
52
+
53
+
54
+ # Outside of the with scope the runtime instance is stopped and deleted.
55
+ ```
56
+
57
+ ## Configure the Runtime
58
+
59
+ You can create a runtime environment that automatically executes a setup script in two ways:
60
+
61
+ ```py
62
+ runtime = Runtime.create(setup="/local_path/to/setup_script")
63
+ # Alternatively
64
+ runtime = Runtime.create(setup=[
65
+ "sudo apt update",
66
+ "sudo apt install -y tmux git build-essential",
67
+ "git clone my_public_repo_url.git"
68
+ ]
69
+ ```
70
+
71
+ You can also customize the VM configurations:
72
+
73
+ ```py
74
+ runtime = Runtime.create(
75
+ vcpus=2, # number of cpus
76
+ memory=2048, # mb
77
+ )
78
+ ```
79
+
80
+ ## Connecting to a Runtime
81
+
82
+ If you created a runtime instance from the web UI and you wish to connect to it:
83
+
84
+ ```py
85
+ from morphcloud import Runtime
86
+
87
+ runtime = Runtime.create(id=YOUR_RUNTIME_ID)
88
+
89
+ # Stop it manually on cloud.morph.so or using
90
+ runtime.stop()
91
+ ```
92
+
93
+ ## Saving a Runtime
94
+
95
+ To save the state of the remote runtime for future use:
96
+
97
+ ```py
98
+ from morphcloud import Runtime
99
+
100
+ with Runtime.create() as runtime:
101
+ # You can perform any actions inside of the environment in here.
102
+ # .....
103
+ result = runtime.execute.terminal_command(command="npm start", terminal_name="optional_name")) # This will run async on the runtime environment.
104
+ terminal_status = runtime.execute.observe_terminals() # This will return a dict with the most recent outputs of all active terminals in the runtime.
105
+ snapshot_id = runtime.snapshot.create()
106
+
107
+
108
+ Runtime.snapshot.list() # returns a list of all snapshot_ids
109
+
110
+ ```
111
+
112
+ To create a new runtime instance from the same point where `npm start` is running:
113
+
114
+ ```py
115
+ runtime = Runtime.create(snapshot_id = YOUR_SNAPSHOT_ID)
116
+
117
+ # To delete a snapshot
118
+ _ = Runtime.snapshot.delete(YOUR_SNAPSHOT_ID)
119
+ ```
120
+
121
+ ### Cloning
122
+
123
+ If you would like to run multiple instances in parallel to do a task in the same environment:
124
+
125
+ ```py
126
+ from morphcloud import Runtime
127
+
128
+ runtime = Runtime.create()
129
+ # You can perform any actions inside of the environment in here.
130
+ # .....
131
+ runtimes = runtime.clone(5) # creates a list of 5 runtime objects.
132
+
133
+ for r in runtimes:
134
+ # do stuff...
135
+
136
+ # all runtime instances are terminated upon script completion.
137
+ ```
138
+
139
+ ## AI Integration
140
+
141
+ MorphCloud provides built-in support for integrating with AI models through standardized tool formats. You can easily convert runtime actions to formats compatible with popular AI models:
142
+
143
+ ```python
144
+ from morphcloud import Runtime
145
+
146
+ runtime = Runtime.create()
147
+
148
+ # Get tools in Anthropic's format
149
+ anthropic_tools = runtime.actions.as_anthropic_tools()
150
+
151
+ # Get tools in OpenAI's function calling format
152
+ openai_tools = runtime.actions.as_openai_tools()
153
+
154
+ ```
155
+
156
+ ## Examples
157
+
158
+ There are several examples in the `examples` directory. Notably, there are two key examples: [search.py](https://github.com/morph-labs/morphcloud/blob/main/examples/search.py), which showcases repository cloning, semantic code search, and function analysis, and [agent_skeleton.py](https://github.com/morph-labs/morphcloud/blob/main/examples/agent_skeleton.py), which provides a good starting point to create simple AI agents that interact with the cloud development environment.
@@ -0,0 +1,9 @@
1
+ """
2
+ Copyright (c) 2024 Morph Labs. All rights reserved.
3
+ Released under the license as described in the file LICENSE.
4
+ """
5
+
6
+ from .runtime import Runtime
7
+
8
+ __version__ = "0.1.0"
9
+ __all__ = ["Runtime"]