Skip to main content

Python SDK and CLI for Middleman ML Training Platform

Project description

Middleman Python SDK

Python SDK and CLI for the Middleman ML Training Platform.

Installation

pip install middleman-ml

Quick Start

CLI Usage

Configure your API key:

middleman auth
# Enter your API key when prompted

Or set the environment variable:

export MIDDLEMAN_API_KEY=mdlm_your_api_key_here

Create a training job:

middleman jobs create /scripts/train.py /data/dataset \
  --name "My Training Run" \
  --gpu a100 \
  --gpu-count 2 \
  --framework pytorch \
  --max-hours 8

Monitor your job:

middleman jobs watch <job-id>

Check your balance:

middleman billing balance

Python SDK Usage

from middleman import MiddlemanClient

# Initialize client
client = MiddlemanClient(api_key="mdlm_...")

# Create a job
job = client.create_job(
    name="ResNet Training",
    script_path="/scripts/train.py",
    input_data_path="/data/imagenet",
    gpu_type="a100",
    gpu_count=4,
    framework="pytorch",
    max_runtime_hours=24,
)

print(f"Job {job.id} created, queue position: {job.queue_position}")

# Wait for completion
result = client.wait_for_job(job.id)
print(f"Job finished with status: {result.status}")

# Check balance
balance = client.get_balance()
print(f"Available credits: {balance.available}")

CLI Commands

Authentication

middleman auth [API_KEY]     # Configure API key
middleman whoami             # Show account info

Jobs

middleman jobs list          # List jobs
middleman jobs create        # Create a job
middleman jobs status <id>   # Get job details
middleman jobs cancel <id>   # Cancel a job
middleman jobs pause <id>    # Pause a running job
middleman jobs resume <id>   # Resume a paused job
middleman jobs logs <id>     # View job logs
middleman jobs watch <id>    # Watch until completion

Billing

middleman billing balance    # Show credit balance
middleman billing packages   # Show credit packages
middleman billing history    # Transaction history

Data

middleman data upload <file>          # Upload a file
middleman data download-url <job-id>  # Get download URL

API Keys

middleman keys list           # List API keys
middleman keys create <name>  # Create new key
middleman keys revoke <id>    # Revoke a key

SDK Reference

MiddlemanClient

from middleman import MiddlemanClient

client = MiddlemanClient(
    api_key="mdlm_...",           # Or use MIDDLEMAN_API_KEY env var
    base_url="https://...",       # Optional, defaults to production
    timeout=30.0,                 # Request timeout in seconds
)

Jobs API

# List jobs
jobs, total = client.list_jobs(status="running", limit=20)

# Get job details
job = client.get_job("job-uuid")

# Create job
response = client.create_job(
    script_path="/scripts/train.py",
    input_data_path="/data/dataset",
    name="My Job",
    gpu_type="a100",      # t4, v100, a100
    gpu_count=1,          # 1-8
    framework="pytorch",  # pytorch, tensorflow, jax
    requirements_file="/scripts/requirements.txt",
    checkpoint_frequency=10,
    max_runtime_hours=4,
    environment_variables={"WANDB_API_KEY": "..."},
)

# Control jobs
client.cancel_job("job-uuid")
client.pause_job("job-uuid")
client.resume_job("job-uuid")

# Wait for completion
final_job = client.wait_for_job("job-uuid", timeout=3600)

# Stream status updates
for job in client.stream_job_status("job-uuid"):
    print(f"Epoch {job.current_epoch}, Loss: {job.current_loss}")
    if job.is_terminal:
        break

# Get logs
logs = client.get_job_logs("job-uuid")

Billing API

# Get balance
balance = client.get_balance()
print(f"Available: {balance.available} credits")

# List packages
packages = client.get_packages()

# Transaction history
transactions, total = client.get_transactions(limit=50)

Data API

# Upload a file
blob_path = client.upload_file("/local/path/data.zip", job_id="job-uuid")

# Get download URL
download = client.get_download_url("job-uuid", path="outputs/model.pt")
print(download.download_url)

API Keys

# List keys
keys = client.list_api_keys()

# Create key
key_info, full_key = client.create_api_key(
    name="CI/CD Pipeline",
    scopes=["read", "write"],
    expires_in_days=90,
)
print(f"Key: {full_key}")  # Only shown once!

# Revoke key
client.revoke_api_key("key-uuid")

GPU Types and Pricing

GPU Type VRAM Credits/Hour
T4 16GB 10
V100 32GB 25
A100 80GB 50

Environment Variables

  • MIDDLEMAN_API_KEY - Your API key
  • MIDDLEMAN_API_URL - Custom API URL (optional)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

middleman_ml-0.1.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

middleman_ml-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file middleman_ml-0.1.0.tar.gz.

File metadata

  • Download URL: middleman_ml-0.1.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for middleman_ml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8920757215db94f43fcd39fb352efe5b9561b63d5cd93cf6b8530e5e4981e2d2
MD5 deace8e30dc62e667a51c6305e0e4569
BLAKE2b-256 10c6dfb885d2329163b35e9362451d759a7f670fa9d58c3c225b346d4d429cee

See more details on using hashes here.

File details

Details for the file middleman_ml-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: middleman_ml-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for middleman_ml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 934db5679438d9275f599ae38803e71b0410980d19a05d346df0a4806075b0b0
MD5 ea61edc2d7e5948ccd7f9876f5ac3c82
BLAKE2b-256 21c49eee1fa8bc42007cdf769ea2835a4f05ad60fe6cfa6c323ae5e4a45d90b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page