Skip to main content

Python SDK for StackMachine.

Project description

StackMachine Python SDK

Python SDK for StackMachine. It mirrors the JavaScript SDK surface with a Pythonic sync client and a native async client.

Installation

uv add stackmachine

Usage

from stackmachine import StackMachine

with StackMachine("sk_stackmachine_...") as stackmachine:
    app = stackmachine.apps.retrieve_by_name("my-app")
    print(app.url)
from stackmachine import AsyncStackMachine

async with AsyncStackMachine("sk_stackmachine_...") as stackmachine:
    app = await stackmachine.apps.retrieve_by_name("my-app")
    print(app.url)

Clients

StackMachine exposes sync methods. AsyncStackMachine exposes the same resource tree with awaitable methods.

from stackmachine import AsyncStackMachine, StackMachine

stackmachine = StackMachine("sk_stackmachine_...")
async_stackmachine = AsyncStackMachine("sk_stackmachine_...")

Both clients accept JavaScript-style aliases during initialization:

stackmachine = StackMachine.init(
    {
        "token": "sk_stackmachine_...",
        "apiUrl": "https://api.stackmachine.com/graphql",
        "maxNetworkRetries": 2,
    }
)

Apps

apps = stackmachine.apps.list(limit=10)

for app in apps:
    print(app.id, app.name)

app = stackmachine.apps.retrieve("app_id")
app = stackmachine.apps.retrieve_by_name("my-app")
apps = stackmachine.apps.retrieve_many(["app_1", "app_2"])
stackmachine.apps.delete("app_id")

Async lists can either be awaited for the first page or iterated directly:

apps = async_stackmachine.apps.list(limit=10)
first_page = await apps

async for app in apps:
    print(app.name)

Deployments

deployment = stackmachine.deployments.create(
    {
        "file": "https://example.com/app.zip",
        "name": "my-app",
    }
)

version = deployment.wait()
deployment = stackmachine.apps.autobuild(
    {
        "file": "https://example.com/app.zip",
        "name": "my-app",
    }
)

Files

from stackmachine import create_zip

zip_bytes = create_zip({"index.html": "<h1>Hello</h1>"})
url = stackmachine.files.upload(zip_bytes)

Domains

domain = stackmachine.apps.domains.create(
    app="app_id",
    hostname="example.com",
)

is_verified = stackmachine.apps.domains.verify(domain.id)
stackmachine.apps.domains.delete(domain.id)

SSH

server = stackmachine.apps.ssh.retrieve("app_id")
server = stackmachine.apps.ssh.update("app_id", enabled=True)
token = stackmachine.apps.ssh.tokens.create(app="app_id")

users = stackmachine.apps.ssh.users.list(app="app_id")
user = stackmachine.apps.ssh.users.retrieve("ssh_user_id")
password = stackmachine.apps.ssh.users.passwords.rotate("ssh_user_id")

key = stackmachine.apps.ssh.users.authorized_keys.create(
    user="ssh_user_id",
    public_key="ssh-ed25519 AAAA...",
)

Request Options

Most methods accept request_options for per-request configuration:

app = stackmachine.apps.retrieve(
    "app_id",
    request_options={
        "api_key": "sk_stackmachine_other",
        "timeout": 30,
        "idempotency_key": "deploy-123",
    },
)

Development

cd python
uv sync --dev
uv run ruff check src examples tests
uv run mypy
uv run pytest
uv build --no-sources

Manual Publish

Use this path only for manual package uploads:

cd python
uv sync --dev
uv build --no-sources
uv publish

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

stackmachine-0.3.1.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

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

stackmachine-0.3.1-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file stackmachine-0.3.1.tar.gz.

File metadata

  • Download URL: stackmachine-0.3.1.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for stackmachine-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0702167c3238de2084610c521ffa223c0c7d9b3435a011f52c6e75b06969a470
MD5 1c83e5d7425527630dd517f6a0300032
BLAKE2b-256 70a0add373f6d81c5d834b88db55759e541db47090791c0a2dbcb6edaa90cd98

See more details on using hashes here.

File details

Details for the file stackmachine-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: stackmachine-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for stackmachine-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 189a111c175337623f86101097f742521b4c30a9ac9a9a1b927ff7e1b6e88f17
MD5 36c313e00c6f9baa5fddfa4530a614a8
BLAKE2b-256 ab414b37f86fa372bc99f9875396971066d42d609b5bf18dba4d6364a025bb8d

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