Name | morphcloud JSON |
Version |
0.1.16
JSON |
| download |
home_page | None |
Summary | A Python SDK and CLI tool for creating, managing, and interacting with Morph Cloud VMs. |
upload_time | 2024-12-18 09:43:29 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | Apache-2.0 |
keywords |
cli
cloud
morph
runtimes
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# MorphCloud Python SDK
## Overview
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.
## Setup Guide
### Prerequisites
Python 3.11 or higher
Go to [https://cloud.morph.so](https://cloud.morph.so/web/api-keys), log in with the provided credentials and create an API key.
Set the API key as an environment variable `MORPH_API_KEY`.
### Installation
```
pip install morphcloud
```
Export the API key:
```
export MORPH_API_KEY="your-api-key"
```
## Python API
The SDK provides a Python API to interact with the MorphCloud API.
The following example creates a minimal vm snapshot, starts and instance then sets up a simple HTTP server and makes an HTTP request to it.
```py
import time
import requests
import tempfile
from morphcloud.api import MorphCloudClient
# Connect to the MorphCloud API
# The API key can be set through the client or as an environment variable MORPH_API_KEY
client = MorphCloudClient()
# Create a snapshot with 1 vCPU, 128MB memory, 700MB disk size, and the image "morphvm-minimal"
snapshot = client.snapshots.create(vcpus=1, memory=128, disk_size=700, image_id="morphvm-minimal")
# Start an instance from the snapshot and open an SSH connection
with client.instances.start(snapshot_id=snapshot.id) as instance, instance.ssh() as ssh:
# Install uv and python using the ssh connection
ssh.run(["curl -LsSf https://astral.sh/uv/install.sh | sh"]).raise_on_error()
ssh.run(["echo 'source $HOME/.local/bin/env' >> $HOME/.bashrc"]).raise_on_error()
ssh.run(["uv", "python", "install"]).raise_on_error()
# Create an index.html file locally and copy it to the instance
with tempfile.NamedTemporaryFile(mode="w") as f:
f.writelines("<h1>Hello, World!</h1>")
f.flush()
ssh.copy_to(f.name, "index.html")
# Start an HTTP server on the instance with a tunnel to the local machine and run it in the background
with ssh.run(["uv", "run", "python3", "-m", "http.server", "8080", "--bind", "127.0.0.1"], background=True) as http_server, \
ssh.tunnel(local_port=8888, remote_port=8080) as tunnel:
# Wait for the HTTP server to start
time.sleep(1)
print("HTTP Server:", http_server.stdout)
print("Making HTTP request")
response = requests.get("http://127.0.0.1:8888", timeout=10)
print("HTTP Response:", response.status_code)
print(response.text)
```
## Command Line Interface
The SDK also provides a command line interface to interact with the MorphCloud API.
You can use the CLI to create, delete, and manage runtime instances.
### Images
List available images:
```bash
morph image list [--json]
```
### Snapshots
```bash
# List all snapshots
morph snapshot list [--json]
# Create a new snapshot
morph snapshot create --image-id <id> --vcpus <n> --memory <mb> --disk-size <mb> [--digest <hash>]
# Delete a snapshot
morph snapshot delete <snapshot-id>
```
### Instances
```bash
# List all instances
morph instance list [--json]
# Start a new instance from snapshot
morph instance start <snapshot-id> [--json]
# Stop an instance
morph instance stop <instance-id>
# Get instance details
morph instance get <instance-id>
# Create snapshot from instance
morph instance snapshot <instance-id> [--json]
# Clone an instance
morph instance branch <instance-id> [--count <n>]
```
### Instance Management
```bash
# Execute command on instance
morph instance exec <instance-id> <command>
# SSH into instance
morph instance ssh <instance-id> [command]
# Port forwarding
morph instance port-forward <instance-id> <remote-port> [local-port]
# Expose HTTP service
morph instance expose-http <instance-id> <name> <port>
# Hide HTTP service
morph instance hide-http <instance-id> <name>
```
### Container Deployment
Deploy and run OCI containers:
```bash
morph instance crun [options] [command]
Options:
--image TEXT Container image (default: python:3.11-slim)
--expose-http TEXT HTTP service to expose (format: name:port)
--vcpus INTEGER Number of VCPUs (default: 1)
--memory INTEGER Memory in MB (default: 128)
--disk-size INTEGER Disk size in MB (default: 700)
--force-rebuild Force rebuild the container
--instance-id TEXT Use existing instance instead of creating new
--verbose Enable verbose logging (default: True)
--json Output in JSON format
```
### Interactive Chat
Start an interactive chat session with an instance:
**Note:** You'll need to set `ANTHROPIC_API_KEY` environment variable to use this command.
```bash
morph instance chat <instance-id> [instructions]
```
Raw data
{
"_id": null,
"home_page": null,
"name": "morphcloud",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "cli, cloud, morph, runtimes",
"author": null,
"author_email": "Morph Labs <jobs@morph.so>",
"download_url": "https://files.pythonhosted.org/packages/ec/04/6e233fe2ee221dcc46aa07344e09fcfd3e10f41c41c0ea5fce03fc478052/morphcloud-0.1.16.tar.gz",
"platform": null,
"description": "# MorphCloud Python SDK \n\n## Overview\n\nMorphCloud is a platform designed to spin up remote AI devboxes we call runtimes.\nIt provides a suite of code intelligence tools and a Python SDK to manage, create, delete, and interact with runtime instances.\n\n## Setup Guide\n\n### Prerequisites\n\nPython 3.11 or higher\n\nGo to [https://cloud.morph.so](https://cloud.morph.so/web/api-keys), log in with the provided credentials and create an API key.\n\nSet the API key as an environment variable `MORPH_API_KEY`.\n\n### Installation\n\n```\npip install morphcloud\n```\n\nExport the API key:\n\n```\nexport MORPH_API_KEY=\"your-api-key\"\n```\n\n## Python API\n\nThe SDK provides a Python API to interact with the MorphCloud API.\n\nThe following example creates a minimal vm snapshot, starts and instance then sets up a simple HTTP server and makes an HTTP request to it.\n\n```py\nimport time\nimport requests\nimport tempfile\nfrom morphcloud.api import MorphCloudClient\n\n# Connect to the MorphCloud API\n# The API key can be set through the client or as an environment variable MORPH_API_KEY\nclient = MorphCloudClient()\n\n# Create a snapshot with 1 vCPU, 128MB memory, 700MB disk size, and the image \"morphvm-minimal\"\nsnapshot = client.snapshots.create(vcpus=1, memory=128, disk_size=700, image_id=\"morphvm-minimal\")\n\n# Start an instance from the snapshot and open an SSH connection\nwith client.instances.start(snapshot_id=snapshot.id) as instance, instance.ssh() as ssh:\n # Install uv and python using the ssh connection\n ssh.run([\"curl -LsSf https://astral.sh/uv/install.sh | sh\"]).raise_on_error()\n ssh.run([\"echo 'source $HOME/.local/bin/env' >> $HOME/.bashrc\"]).raise_on_error()\n ssh.run([\"uv\", \"python\", \"install\"]).raise_on_error()\n\n # Create an index.html file locally and copy it to the instance\n with tempfile.NamedTemporaryFile(mode=\"w\") as f:\n f.writelines(\"<h1>Hello, World!</h1>\")\n f.flush()\n ssh.copy_to(f.name, \"index.html\")\n\n # Start an HTTP server on the instance with a tunnel to the local machine and run it in the background\n with ssh.run([\"uv\", \"run\", \"python3\", \"-m\", \"http.server\", \"8080\", \"--bind\", \"127.0.0.1\"], background=True) as http_server, \\\n ssh.tunnel(local_port=8888, remote_port=8080) as tunnel:\n\n # Wait for the HTTP server to start\n time.sleep(1)\n\n print(\"HTTP Server:\", http_server.stdout)\n\n print(\"Making HTTP request\")\n response = requests.get(\"http://127.0.0.1:8888\", timeout=10)\n print(\"HTTP Response:\", response.status_code)\n print(response.text)\n```\n\n## Command Line Interface\n\nThe SDK also provides a command line interface to interact with the MorphCloud API.\nYou can use the CLI to create, delete, and manage runtime instances.\n\n### Images\n\nList available images:\n```bash\nmorph image list [--json]\n```\n\n### Snapshots\n\n```bash\n# List all snapshots\nmorph snapshot list [--json]\n\n# Create a new snapshot\nmorph snapshot create --image-id <id> --vcpus <n> --memory <mb> --disk-size <mb> [--digest <hash>]\n\n# Delete a snapshot\nmorph snapshot delete <snapshot-id>\n```\n\n### Instances\n\n```bash\n# List all instances\nmorph instance list [--json]\n\n# Start a new instance from snapshot\nmorph instance start <snapshot-id> [--json]\n\n# Stop an instance\nmorph instance stop <instance-id>\n\n# Get instance details\nmorph instance get <instance-id>\n\n# Create snapshot from instance\nmorph instance snapshot <instance-id> [--json]\n\n# Clone an instance\nmorph instance branch <instance-id> [--count <n>]\n```\n\n### Instance Management\n\n```bash\n# Execute command on instance\nmorph instance exec <instance-id> <command>\n\n# SSH into instance\nmorph instance ssh <instance-id> [command]\n\n# Port forwarding\nmorph instance port-forward <instance-id> <remote-port> [local-port]\n\n# Expose HTTP service\nmorph instance expose-http <instance-id> <name> <port>\n\n# Hide HTTP service\nmorph instance hide-http <instance-id> <name>\n```\n\n### Container Deployment\n\nDeploy and run OCI containers:\n\n```bash\nmorph instance crun [options] [command]\n\nOptions:\n --image TEXT Container image (default: python:3.11-slim)\n --expose-http TEXT HTTP service to expose (format: name:port)\n --vcpus INTEGER Number of VCPUs (default: 1)\n --memory INTEGER Memory in MB (default: 128)\n --disk-size INTEGER Disk size in MB (default: 700)\n --force-rebuild Force rebuild the container\n --instance-id TEXT Use existing instance instead of creating new\n --verbose Enable verbose logging (default: True)\n --json Output in JSON format\n```\n\n### Interactive Chat\n\nStart an interactive chat session with an instance:\n\n**Note:** You'll need to set `ANTHROPIC_API_KEY` environment variable to use this command.\n\n```bash\nmorph instance chat <instance-id> [instructions]\n```\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A Python SDK and CLI tool for creating, managing, and interacting with Morph Cloud VMs.",
"version": "0.1.16",
"project_urls": null,
"split_keywords": [
"cli",
" cloud",
" morph",
" runtimes"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2def0311da7d82019f73841fcf59b7cca6fd0ea0bb8acfefe40ab0a2f9f91a82",
"md5": "2942466dca1e7d1db5aa393504346667",
"sha256": "9b81992abcc9d08a16216cfa5db790591f4d5522858c931f6b3b5548d56f47fd"
},
"downloads": -1,
"filename": "morphcloud-0.1.16-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2942466dca1e7d1db5aa393504346667",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 37515,
"upload_time": "2024-12-18T09:43:28",
"upload_time_iso_8601": "2024-12-18T09:43:28.769765Z",
"url": "https://files.pythonhosted.org/packages/2d/ef/0311da7d82019f73841fcf59b7cca6fd0ea0bb8acfefe40ab0a2f9f91a82/morphcloud-0.1.16-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ec046e233fe2ee221dcc46aa07344e09fcfd3e10f41c41c0ea5fce03fc478052",
"md5": "35ebbd9724a21d92e96cf357b7d99f3b",
"sha256": "daf7f611030f6efe5e6f7dc766b8996c578bf3f2781dbeeb598f840c706dad7d"
},
"downloads": -1,
"filename": "morphcloud-0.1.16.tar.gz",
"has_sig": false,
"md5_digest": "35ebbd9724a21d92e96cf357b7d99f3b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 70496,
"upload_time": "2024-12-18T09:43:29",
"upload_time_iso_8601": "2024-12-18T09:43:29.838141Z",
"url": "https://files.pythonhosted.org/packages/ec/04/6e233fe2ee221dcc46aa07344e09fcfd3e10f41c41c0ea5fce03fc478052/morphcloud-0.1.16.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-18 09:43:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "morphcloud"
}