Skip to main content

styne-sdk

Python client for the Styne API: VMs and cloud browsers.

pip install styne-sdk
export STYNE_API_KEY=...

Python 3.11 to 3.13. The sync client (styne.Client, styne.Vm, styne.Browser) and the async client (styne.AsyncClient, styne.AsyncVm, styne.AsyncBrowser) have the same methods. Records the API returns (vm.info, snapshots, ports, checkpoints) are typed classes from styne.models.

Run a command in a VM

import styne

client = styne.Client()  # reads STYNE_API_KEY

with client.vms.create(size="small") as vm:  # the VM is deleted when the block ends
    result = vm.run("echo hello && uname -r")
    print(result.stdout, result.exit_code)
    result.check()  # raises CommandError on a non-zero exit

    vm.files.write("/work/app.py", "print('hi')")
    print(vm.run("python3 /work/app.py").stdout)
    for event in vm.stream("for i in 1 2 3; do echo $i; sleep 1; done"):
        print(event.type, event.data)

vm.run waits as long as the command runs unless you pass timeout= (seconds). A command is sent once and never retried.

Checkpoint, pause, fork and snapshot

vm = client.vms.create()
before = vm.checkpoints.create("before-migration")
vm.run("./migrate.sh")
vm.rewind(before)  # back to the checkpoint

vm.pause()  # state is kept, billing stops
vm.resume()
copies = vm.fork(count=3)  # three running copies of this VM
snap = vm.snapshot("ready")
other = client.snapshots.start(snap.id)
url = vm.ports.expose(8080, public=True).url

for copy in [*copies, other, vm]:
    copy.kill()
client.snapshots.delete(snap.id)

A cloud browser for Playwright

from playwright.sync_api import sync_playwright

with client.browsers.create() as browser, sync_playwright() as p:
    page = p.chromium.connect_over_cdp(browser.cdp_url).contexts[0].new_page()
    page.goto("https://example.com")
    print(page.title(), browser.live_view_url)
    control = browser.take_control("alice@example.com")  # names the person in the audit log; agent input pauses
    print(control.cdp_url)
    browser.give_back_control()

examples/ has runnable versions of the VM, fork and browser snippets.

Async

import asyncio
import styne


async def main() -> None:
    async with styne.AsyncClient() as client:
        async with await client.vms.create() as vm:
            print((await vm.run("date")).stdout)


asyncio.run(main())

Errors, retries and idempotency

Every error is a styne.StyneError:

  • styne.APIError (the API answered with an error) has status, code, origin, request_id, details, doc_url and retry_after. Subclasses: InvalidArgumentError, IdempotencyMismatchError, AuthenticationError, PaymentRequiredError, PlanRequiredError, PermissionDeniedError, NotFoundError, VmEndedError, ConflictError, QuotaExceededError, RateLimitError, LimitConcurrentError, CapacityError, CommandTimeoutError, ServerError.
  • styne.APIConnectionError (no answer arrived) and its subclass styne.APITimeoutError.
  • styne.CommandError from CommandResult.check().
try:
    client.vms.create()
except styne.LimitConcurrentError as err:
    print(err.details, err.request_id)

Reads and deletes, and the creates the API deduplicates by Idempotency-Key (VMs, browsers, forks, snapshots, checkpoints), are retried on network errors, 408, 429, 5xx and in-flight 409 answers, honouring Retry-After. Every other call, a command above all, is sent once. Client(max_retries=2, timeout=60) tunes both. http_client= takes your own httpx.Client (proxies, limits); the key and URL are still applied.

Development

pip install -e '.[dev]'
tools/generate.sh   # refresh src/styne/_generated from openapi.yaml
ruff check . && mypy src tests && pytest
STYNE_API_KEY=... pytest -m live

Apache-2.0.

Metadata

Release files for styne-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for styne-sdk 0.1.1
File Size Uploaded Provenance Actions
styne_sdk-0.1.1.tar.gz 55.7 kB Without provenance Details for styne_sdk-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for styne-sdk 0.1.1
File Interpreter ABI Platform Actions
styne_sdk-0.1.1-py3-none-any.whl Python 3 none any Details for styne_sdk-0.1.1-py3-none-any.whl

Total release size: 162.9 kB

Release files / styne_sdk-0.1.1.tar.gz

Download URL styne_sdk-0.1.1.tar.gz
Size 55.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b31d124e68000a60e2cbc1e996275a4d236e923c45970990b0adaa3f0203475b
BLAKE2b-256 checksum
How to use checksums
b8375ce594efb7f44e50bb1d1d2cfa7ae149f5da4336b6a6abe1e8130b44d2dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / styne_sdk-0.1.1-py3-none-any.whl

Download URL styne_sdk-0.1.1-py3-none-any.whl
Size 107.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02c374f2f87c70adad8c8ab326da28a5f56e7c72958ff3306dd3efa48990d3ed
BLAKE2b-256 checksum
How to use checksums
3573a30e8f3c76bc8d7742ea4dd11b4942800548d03e69d83510a84c9f580a78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for styne-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page