Mags SDK - Execute scripts on Magpie's instant VM infrastructure
Project description
Mags Python SDK
Execute scripts on Magpie's instant VM infrastructure from Python.
Install
pip install magpie-mags
Quick Start
from mags import Mags
m = Mags(api_token="your-token")
# Run a script and wait for the result
result = m.run_and_wait("echo 'Hello from a VM!'")
print(result["status"]) # "completed"
print(result["exit_code"]) # 0
for log in result["logs"]:
print(log["message"])
Authentication
Pass api_token directly, or set one of these environment variables:
export MAGS_API_TOKEN="your-token"
# or
export MAGS_TOKEN="your-token"
Usage
Run a Script
# Fire-and-forget
job = m.run("apt install -y ffmpeg && ffmpeg -version")
print(job["request_id"])
# Run and wait for completion
result = m.run_and_wait(
"python3 -c 'print(sum(range(100)))'",
timeout=30,
)
Persistent Workspaces
# First run: creates the workspace
m.run_and_wait(
"pip install pandas && echo 'setup done'",
workspace_id="my-project",
persistent=True,
)
# Second run: reuses the workspace (pandas is already installed)
m.run_and_wait(
"python3 -c 'import pandas; print(pandas.__version__)'",
workspace_id="my-project",
)
Enable URL / SSH Access
job = m.run("python3 -m http.server 8080", persistent=True)
# HTTP access
access = m.enable_access(job["request_id"], port=8080)
print(access["url"])
# SSH access
ssh = m.enable_access(job["request_id"], port=22)
print(f"ssh root@{ssh['ssh_host']} -p {ssh['ssh_port']}")
Upload Files
file_ids = m.upload_files(["data.csv", "config.json"])
result = m.run_and_wait(
"ls /uploads && wc -l /uploads/data.csv",
file_ids=file_ids,
)
Cron Jobs
cron = m.cron_create(
name="nightly-backup",
cron_expression="0 0 * * *",
script="tar czf /workspace/backup.tar.gz /data",
workspace_id="backups",
)
jobs = m.cron_list()
m.cron_update(cron["id"], enabled=False)
m.cron_delete(cron["id"])
Check Usage
usage = m.usage(window_days=7)
print(f"Jobs: {usage['total_jobs']}, VM seconds: {usage['vm_seconds']:.0f}")
API Reference
| Method | Description |
|---|---|
run(script, **opts) |
Submit a job (returns immediately) |
run_and_wait(script, **opts) |
Submit and block until done |
status(request_id) |
Get job status |
logs(request_id) |
Get job logs |
list_jobs(page, page_size) |
List recent jobs |
update_job(request_id, startup_command) |
Update job config |
enable_access(request_id, port) |
Enable URL or SSH access |
usage(window_days) |
Get usage summary |
upload_file(path) |
Upload a file, returns file ID |
upload_files(paths) |
Upload multiple files |
cron_create(**opts) |
Create a cron job |
cron_list() |
List cron jobs |
cron_get(id) |
Get a cron job |
cron_update(id, **updates) |
Update a cron job |
cron_delete(id) |
Delete a cron job |
Links
- Website: mags.run
- Node.js SDK:
npm install @magpiecloud/mags - CLI:
go installor download from releases
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
magpie_mags-1.2.0.tar.gz
(7.1 kB
view details)
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 magpie_mags-1.2.0.tar.gz.
File metadata
- Download URL: magpie_mags-1.2.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e080149ca9fa94daabfcd3abf20bcb22d94cc00882f70ab90d1b049b9860be6b
|
|
| MD5 |
cf8716a9d25c2937e977bdb56df99969
|
|
| BLAKE2b-256 |
1472dd5c21aeec360bad8d2e59c28f504b2b38c56cff5ff7818b5f167d0962d4
|
File details
Details for the file magpie_mags-1.2.0-py3-none-any.whl.
File metadata
- Download URL: magpie_mags-1.2.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15c204a7692f41d585ca40f75bbe86758457c9f95d3a0e0d4986cf6632baa601
|
|
| MD5 |
c358a91eb5767bbdcad57b61b3a1f037
|
|
| BLAKE2b-256 |
5788ed9bf44f90aaa1a514b4f9a81db4bead5bf9dbab1648dca51a2b226a8961
|