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 configuration options during initialization:
stackmachine = StackMachine(
"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(
app_name="hello-stackmachine",
owner="stackmachine",
files={
"index.html": "<html><body><h1>Hello StackMachine</h1></body></html>",
},
on_upload_progress=lambda progress: print("Uploading", progress.percent * 100),
)
version = deployment.wait()
deployment = stackmachine.apps.autobuild(
app_name="hello-stackmachine",
owner="stackmachine",
files={
"index.html": "<html><body><h1>Hello StackMachine</h1></body></html>",
},
)
Files
Use this path only for manual package uploads:
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)
Volumes
volume = stackmachine.apps.volumes.create(
app="app_id",
mount_path="/data",
max_size_bytes=1_073_741_824,
)
volumes = stackmachine.apps.volumes.list(app="app_id", limit=25)
updated = stackmachine.apps.volumes.update(
volume.id,
mount_path="/uploads",
s3_enabled=True,
)
stackmachine.apps.volumes.delete(updated.id)
CDN Cache
cache = stackmachine.apps.cache.retrieve("app_id")
print(cache.enabled, cache.purged_at)
stackmachine.apps.cache.update("app_id", enabled=True)
stackmachine.apps.cache.purge("app_id")
Cron Jobs
cleanup = stackmachine.apps.cronjobs.create(
app="app_id",
name="cleanup",
schedule="0 2 * * *",
execute={
"command": "python cleanup.py --older-than '30 days'",
"env": {"LOG_LEVEL": "info"},
},
)
healthcheck = stackmachine.apps.cronjobs.create(
app="app_id",
name="healthcheck",
schedule="*/5 * * * *",
fetch={
"path": "/health",
"method": "GET",
"expect_status_codes": [200],
},
)
cron_jobs = stackmachine.apps.cronjobs.list(app="app_id", limit=25)
stackmachine.apps.cronjobs.update(cleanup.id, enabled=False)
stackmachine.apps.cronjobs.delete(healthcheck.id)
Execute cron jobs expose one shell-safe target.command string. The SDK uses
Python's POSIX shlex rules to split it into the API's command and argument
fields on writes and join those fields on reads. Environment variables are
represented as string dictionaries.
Git Connections
connection = stackmachine.apps.git.connect(
app="app_id",
installation_repo_id="github_installation_repo_id",
deploy_branch="main",
)
connection = stackmachine.apps.git.retrieve("app_id")
updated = stackmachine.apps.git.update(
"app_id",
deploy_branch="main",
deployment_status_events=True,
pull_request_comments=True,
)
stackmachine.apps.git.delete("app_id")
Usage Analytics
app_usage = stackmachine.usage.metrics(
app="app_id",
start="2026-06-01T00:00:00Z",
end="2026-06-30T00:00:00Z",
grouped_by="BY_DAY",
)
workspace_usage = stackmachine.usage.metrics(
owner="my-workspace",
start="2026-06-01T00:00:00Z",
end="2026-06-30T00:00:00Z",
)
print(app_usage.totals.requests.total_requests)
print(workspace_usage.totals.workloads.real_cpu_time_millis)
Databases
result = stackmachine.apps.databases.create(
app="app_id",
db_engine="POSTGRES",
name="primary",
)
database = result.database
password = result.password
databases = stackmachine.apps.databases.list(app="app_id", limit=25)
rotated = stackmachine.apps.databases.rotate_credentials(database.id)
stackmachine.apps.databases.delete(database.id)
Hosted DNS
Hosted DNS is exposed at stackmachine.dns. App domains remain under
stackmachine.apps.domains.
domain = stackmachine.dns.domains.create(
name="example.com",
owner="owner_id",
import_records=True,
)
domains = stackmachine.dns.domains.list(owner="owner_id", limit=25)
domain = stackmachine.dns.domains.retrieve_by_name("example.com")
record = stackmachine.dns.records.create(
domain=domain.id,
kind="A",
name="@",
value="192.0.2.1",
ttl=300,
)
record = stackmachine.dns.records.update(
record.id,
domain=domain.id,
kind="A",
name="@",
value="192.0.2.2",
ttl=300,
)
stackmachine.dns.records.delete(record.id)
stackmachine.dns.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...",
)
Emails
app_sent = stackmachine.emails.sent.list(app="app_id", limit=25)
owner_received = stackmachine.emails.received.list(owner="owner_id", limit=25)
sent_from_app = (
stackmachine.apps.retrieve(app_sent.data[0].app_id)
if app_sent.data and app_sent.data[0].app_id
else None
)
message = stackmachine.emails.send(
app="app_id",
to=["user@example.com"],
subject="Hello from StackMachine",
text_body="Plain text body",
html_body="<p>HTML body</p>",
)
raw_message = stackmachine.emails.send(
app="app_id",
to=["user@example.com"],
subject="Raw MIME from StackMachine",
raw_message=(
b"From: app@example.com\r\n"
b"To: user@example.com\r\n"
b"Subject: Raw MIME from StackMachine\r\n\r\n"
b"Plain text body"
),
)
Request Options
Most methods accept request_options for per-request configuration:
from stackmachine import RequestOptions
app = stackmachine.apps.retrieve(
"app_id",
request_options=RequestOptions(
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
Metadata
Release files for stackmachine 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stackmachine-0.6.0.tar.gz | 60.9 kB | Without provenance | Details for stackmachine-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stackmachine-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for stackmachine-0.6.0-py3-none-any.whl |
Total release size: 123.6 kB
Release files / stackmachine-0.6.0.tar.gz
| Download URL | stackmachine-0.6.0.tar.gz |
|---|---|
| Size | 60.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3abb368b6f1bc884a0cab1de51bbbfe933e161074253d5cdcf72755c3e379f18
|
|
BLAKE2b-256 checksum How to use checksums |
05aba40e77aacfafc0d483c98842cddf1bfbebe2fc2365a03a1395abd08750a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}
|
Release files / stackmachine-0.6.0-py3-none-any.whl
| Download URL | stackmachine-0.6.0-py3-none-any.whl |
|---|---|
| Size | 62.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e93c511b0b23a1acdd6ec0a35d88657aa3169166a5bbd9b0a56deb2852b810d
|
|
BLAKE2b-256 checksum How to use checksums |
4810a36c046058d21175a76c531395c210a639f940e314d919ca5bb78441a5cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.30 {"installer":{"name":"uv","version":"0.11.30","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}
|
Security for stackmachine 0.6.0
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.