stackshift 1.3.1__tar.gz → 1.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stackshift-1.8.0/PKG-INFO +716 -0
- stackshift-1.8.0/README.md +704 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/pyproject.toml +7 -1
- stackshift-1.8.0/stackshift/__init__.py +150 -0
- stackshift-1.8.0/stackshift/agents.py +98 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/client.py +35 -2
- stackshift-1.8.0/stackshift/computers.py +902 -0
- stackshift-1.8.0/stackshift/computers_adapters.py +353 -0
- stackshift-1.8.0/stackshift/computers_transfer.py +557 -0
- stackshift-1.8.0/stackshift/databases.py +226 -0
- stackshift-1.8.0/stackshift/hosted_agents.py +78 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail.py +6 -0
- stackshift-1.8.0/stackshift/mail_agent_inboxes.py +199 -0
- stackshift-1.8.0/stackshift/mail_agreements.py +158 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_events_webhooks.py +5 -1
- stackshift-1.8.0/stackshift/mail_inbox_webhooks.py +89 -0
- stackshift-1.8.0/stackshift/mail_team_inboxes.py +148 -0
- stackshift-1.8.0/stackshift/partner.py +251 -0
- stackshift-1.8.0/stackshift/teams.py +331 -0
- stackshift-1.8.0/stackshift.egg-info/PKG-INFO +716 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift.egg-info/SOURCES.txt +24 -1
- stackshift-1.8.0/tests/test_agents.py +129 -0
- stackshift-1.8.0/tests/test_computers.py +616 -0
- stackshift-1.8.0/tests/test_computers_adapters.py +98 -0
- stackshift-1.8.0/tests/test_computers_controls.py +202 -0
- stackshift-1.8.0/tests/test_computers_routes.py +218 -0
- stackshift-1.8.0/tests/test_databases.py +441 -0
- stackshift-1.8.0/tests/test_hosted_agents.py +116 -0
- stackshift-1.8.0/tests/test_mail_agent_inboxes.py +203 -0
- stackshift-1.8.0/tests/test_mail_agreements.py +153 -0
- stackshift-1.8.0/tests/test_mail_inbox_webhooks.py +81 -0
- stackshift-1.8.0/tests/test_mail_team_inboxes.py +114 -0
- stackshift-1.8.0/tests/test_partner.py +159 -0
- stackshift-1.8.0/tests/test_teams.py +123 -0
- stackshift-1.3.1/PKG-INFO +0 -349
- stackshift-1.3.1/README.md +0 -341
- stackshift-1.3.1/stackshift/__init__.py +0 -70
- stackshift-1.3.1/stackshift/partner.py +0 -93
- stackshift-1.3.1/stackshift.egg-info/PKG-INFO +0 -349
- stackshift-1.3.1/tests/test_partner.py +0 -82
- {stackshift-1.3.1 → stackshift-1.8.0}/setup.cfg +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/ai_credits.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/assets.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/assets_dam.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/assets_media.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/assets_platform.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/assets_video.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/assets_workflows.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_advanced.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_billing.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_brands.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_campaigns.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_exports.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_mailboxes.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_marketing.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_migration.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_reputation.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_streams.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/mail_tracking.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/projects.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/support_action_manifest.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/support_action_receiver.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/support_action_sqlite.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/support_action_types.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/support_actions.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift/workload_security.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift.egg-info/dependency_links.txt +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift.egg-info/requires.txt +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/stackshift.egg-info/top_level.txt +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_ai_credits.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_assets_media.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_assets_platform.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_assets_workflows.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_advanced.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_diagnostics.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_events_webhooks.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_exports.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_mailboxes.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_platform.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_simulation.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_subscribers.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_mail_tracking.py +0 -0
- {stackshift-1.3.1 → stackshift-1.8.0}/tests/test_support_actions.py +0 -0
|
@@ -0,0 +1,716 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stackshift
|
|
3
|
+
Version: 1.8.0
|
|
4
|
+
Summary: Official Python SDK for StackShift.
|
|
5
|
+
Author-email: StackShift <support@stackshift.cloud>
|
|
6
|
+
Project-URL: Homepage, https://stackshift.cloud
|
|
7
|
+
Project-URL: Documentation, https://docs.stackshift.cloud
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: requests>=2.31
|
|
12
|
+
|
|
13
|
+
# StackShift Python SDK
|
|
14
|
+
|
|
15
|
+
Official Python SDK for StackShift.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install stackshift
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Computers
|
|
24
|
+
|
|
25
|
+
Cloud computers any agent can drive. Use a computers key as `api_key`.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
computer = stackshift.computers.create(project_id, "agent-desktop", vcpus=4, memory_gb=8)
|
|
29
|
+
computer.exec("npm install && npm test", cwd="/workspace/app")
|
|
30
|
+
computer.files.write("notes.txt", "hello")
|
|
31
|
+
port = computer.ports.publish(3000, "public")
|
|
32
|
+
computer.click(640, 360, screenshot=True)
|
|
33
|
+
computer.type("hello")
|
|
34
|
+
copies = computer.fork(count=3)
|
|
35
|
+
answer = computer.ask_owner("Send the invoice?")
|
|
36
|
+
computer.pause("memory")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`computer.cdp_url()` returns a WebSocket URL for `playwright.chromium.connect_over_cdp(url)`. `live_url()`, `view_link()` and `terminal_url()` return the other session URLs, and `events()` streams state changes and steps.
|
|
40
|
+
|
|
41
|
+
Move files and folders with `computer.files`. Files under 8 MiB go in one request; larger files move in parallel 64 MiB signed parts with checksums, retries and a final sha256 check.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
computer.files.upload("./model.bin", "models/model.bin", concurrency=4)
|
|
45
|
+
computer.files.download("results/out.csv", "./out.csv")
|
|
46
|
+
computer.files.upload_dir("./app", "app", exclude=["node_modules", "*.log"])
|
|
47
|
+
computer.files.download_dir("app/dist", "./dist")
|
|
48
|
+
computer.files.mkdir("app/tmp", parents=True)
|
|
49
|
+
computer.files.remove("app/tmp", recursive=True)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`upload_dir` skips `.gitignore`d files in a git folder unless you pass `include_ignored=True`, and keeps modes, symlinks and modification times.
|
|
53
|
+
|
|
54
|
+
Pick `vcpus` and `memory_gb` from the template's sizes (`templates()` lists them), for example 2 vCPU / 8 GB or 4 vCPU / 16 GB. `region` picks where it starts; `computers.regions(project_id)` lists the regions open now.
|
|
55
|
+
|
|
56
|
+
Tell people what an agent is doing. The dashboard shows the task and next step beside the screen, and `ask_owner` carries the next step on its card.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
computer.set_task(task="Book the flight", next_step="Open the airline site")
|
|
60
|
+
computer.click(640, 360, task="Book the flight", next_step="Pick a seat")
|
|
61
|
+
computer.ask_owner("Pay $240?", next_step="Send the receipt")
|
|
62
|
+
computer.clear_task()
|
|
63
|
+
info = computer.refresh()
|
|
64
|
+
print(info.get("region_name"), info.get("task"), info.get("next_step"), info.get("fork_duration_ms"))
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Read the machine without waking it or adding a step:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
system = computer.system()
|
|
71
|
+
print(system["os_name"], system["kernel"], system["services"], system["listening"], system.get("pauses_at"))
|
|
72
|
+
windows = computer.list_windows()["windows"]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`internet={"mode": "none"}` blocks all outbound access (`open` and `allowlist` are the others). Approvals carry `next_step`, `notified_at` and `notified_channels`.
|
|
76
|
+
|
|
77
|
+
The paying account's spending limit, defaults for new computers and notification choices:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
settings = stackshift.computers.settings(project_id)
|
|
81
|
+
stackshift.computers.save_settings(
|
|
82
|
+
project_id,
|
|
83
|
+
spend_cap={"amount_minor": 500_000, "currency": "NGN"},
|
|
84
|
+
default_approvals=True,
|
|
85
|
+
notifications={"email": True, "push": True},
|
|
86
|
+
)
|
|
87
|
+
stackshift.computers.save_settings(project_id, spend_cap=None)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Import a Docker image as a snapshot and follow it:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
result = stackshift.computers.import_image(
|
|
94
|
+
project_id, "node:22", "node-22",
|
|
95
|
+
internet={"mode": "allowlist", "allowed_domains": ["registry.npmjs.org"]},
|
|
96
|
+
idle_policy={"pause_after_seconds": 600, "mode": "disk"}, access={"keys": True}, logins=["github"], delete_after_seconds=604800,
|
|
97
|
+
)
|
|
98
|
+
progress = stackshift.computers.setup(result["computer"]["id"])
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Run a setup on a computer, or ask for one when you create it. Send exactly one of a script, a `devcontainer.json` already on the computer, or a repository to clone:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
computer.start_setup({"script": {"content": "npm ci", "cwd": "/workspace/app"}})
|
|
105
|
+
computer.start_setup({"devcontainer": {"workspace_folder": "/workspace/app"}})
|
|
106
|
+
computer.start_setup({"source": {"repository": "acme/app", "directory": "/workspace/app", "token": github_token}})
|
|
107
|
+
progress = computer.setup()
|
|
108
|
+
|
|
109
|
+
stackshift.computers.create(
|
|
110
|
+
project_id, "coding", source={"repository": "acme/app", "token": github_token},
|
|
111
|
+
setup={"devcontainer": {"workspace_folder": "/workspace/app"}},
|
|
112
|
+
max_run_seconds=3600, archive_after_seconds=7200, delete_after_seconds=86400,
|
|
113
|
+
)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Run GitHub Actions jobs on computers with `computers.ci`:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
labels = stackshift.computers.ci.labels(project_id)
|
|
120
|
+
overview = stackshift.computers.ci.overview(project_id)
|
|
121
|
+
jobs = stackshift.computers.ci.jobs(project_id, limit=20)
|
|
122
|
+
link = stackshift.computers.ci.connect(project_id, installation_id)
|
|
123
|
+
stackshift.computers.ci.disconnect(link["id"])
|
|
124
|
+
circle = stackshift.computers.ci.connect_circleci(project_id, "acme/stackshift", "small", api_token)
|
|
125
|
+
stackshift.computers.ci.disconnect_circleci(circle["id"])
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Runner labels include `stackshift-small`, `stackshift-small-mem` (2 vCPU / 8 GB), `stackshift-medium`, `stackshift-medium-mem` (4 vCPU / 16 GB), `stackshift-large` and `stackshift-xlarge`.
|
|
129
|
+
|
|
130
|
+
Deleting a computer or a snapshot sends `X-StackShift-Confirm-Delete` with its id; the server answers 428 `confirmation_required` without it. Pass `confirm="name"` to send the name instead.
|
|
131
|
+
|
|
132
|
+
Run commands with live output and input:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
for event in computer.exec_stream("npm test", cwd="/workspace/app"):
|
|
136
|
+
print(event["event"], event["data"])
|
|
137
|
+
result = computer.exec("cat", stdin="hello", stdin_open=False)
|
|
138
|
+
computer.send_stdin(command_id, "yes\n", close=True)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`exec_stream` yields `start`, `stdout`, `stderr`, `exit` and `error` events as `{"event", "data"}`. Background jobs and past commands:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
computer.history(limit=20)
|
|
145
|
+
computer.command()
|
|
146
|
+
computer.jobs()
|
|
147
|
+
computer.job_logs(job_id, offset=0)
|
|
148
|
+
for chunk in computer.follow_job_logs(job_id):
|
|
149
|
+
print(chunk["event"], chunk["data"])
|
|
150
|
+
computer.wait_job(job_id, timeout_seconds=30)
|
|
151
|
+
computer.kill_job(job_id, "KILL")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Keep a computer awake while work runs, and read its limits and metrics:
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
computer.put_activity_lease("lint", 120)
|
|
158
|
+
computer.activity_leases()
|
|
159
|
+
computer.release_activity_lease("lint")
|
|
160
|
+
computer.limits()
|
|
161
|
+
computer.metrics(since="2026-11-10T00:00:00Z")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
SSH access without a long-lived key:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
computer.create_ssh_token(ttl_seconds=3600)
|
|
168
|
+
computer.revoke_ssh_tokens()
|
|
169
|
+
stackshift.computers.ssh_certificate(computer.id, public_key)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Drive the coding agent that runs on the computer:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
conversation = computer.prompt_agent("fix the failing tests", provider="claude")
|
|
176
|
+
for event in computer.follow_agent_events(conversation["id"]):
|
|
177
|
+
print(event["kind"], event.get("text"))
|
|
178
|
+
computer.steer_agent(conversation["id"], "run the linter too")
|
|
179
|
+
computer.interrupt_agent(conversation["id"])
|
|
180
|
+
computer.agent_conversations()
|
|
181
|
+
computer.agent_events(conversation["id"], after_seq=10, limit=50)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`computers.keys.create(project_id, name, scopes=["computers:read"])` limits a key to `computers:read`, `computers:write`, `computers:use` or `computers:delete`. A stuck large upload resumes with `computers.resume_upload(computer_id, transfer_id, upload_id, part_md5)`.
|
|
185
|
+
|
|
186
|
+
An agent can get its own key without any existing key. The functions below send no `Authorization` header:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
registration = register_computer_agent("agent@host", ["computers:use"])
|
|
190
|
+
print(registration["verification_uri_complete"], registration["user_code"])
|
|
191
|
+
issued = wait_for_computer_agent_key(registration)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`wait_for_computer_agent_key` polls at the registration's `interval`, adds 5 seconds on `slow_down`, keeps going on `authorization_pending`, raises `StackShiftAPIError` on any other code and `ComputerWaitError` when `expires_in` passes. `exchange_computer_agent_claim(claim_token)` makes one attempt. The owner reviews the request with `computers.agent_claim(code)` and answers with `computers.decide_agent_claim(code, True, scopes=[...], project_id=project_id)`.
|
|
195
|
+
|
|
196
|
+
Prices include data out per GB (`egress_gb`, and `data_out` lines in `usage`). `computers.public_pricing()` returns the naira and dollar rates, the free plan's allowance and each plan's running limit without needing a computer or project. `computer_public_pricing()` does the same with no client and no key, for example on a pricing page: `computer_public_pricing(base_url=None, session=None)` sends no `Authorization` header.
|
|
197
|
+
|
|
198
|
+
Errors are `StackShiftAPIError` with a `code`: `COMPUTER_LIMIT_EXCEEDED` (`limit_exceeded`, 429) over your limits or free hours, `COMPUTER_CAPACITY_BUSY` (`capacity_busy`, 429) the free share is busy so retry later, and `COMPUTER_SPEND_CAP_REACHED` (`spend_cap_reached`, 402) the account's spending limit is reached.
|
|
199
|
+
|
|
200
|
+
`AnthropicComputerAdapter`, `OpenAIComputerAdapter`, `GeminiComputerAdapter` and `FunctionComputerAdapter` turn each provider's computer-use actions into computer actions and return the screenshot in the provider's reply shape, for example `AnthropicComputerAdapter(computer, max_width=1280).tool_result(tool_use_id, tool_input)`.
|
|
201
|
+
|
|
202
|
+
## Partner platforms
|
|
203
|
+
|
|
204
|
+
Staff-enabled partner accounts buy domains for merchants from their StackShift wallet. Use an API token with the `partner:manage` scope (and `mail:manage` to run campaigns) on your server:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
domain = stackshift.partner.purchase_domain(
|
|
208
|
+
domain="merchantshop.com",
|
|
209
|
+
years=1,
|
|
210
|
+
merchant_ref="m_123",
|
|
211
|
+
registrant={"first_name": "Ada", "last_name": "Obi", "email": "ada@merchantshop.com", "phone": "+2348012345678", "address": "1 Marina", "city": "Lagos", "state": "Lagos", "postal_code": "101001", "country": "NG"},
|
|
212
|
+
brand={"name": "Merchant Shop", "postalAddress": "1 Marina, Lagos, Nigeria"},
|
|
213
|
+
replies={"mode": "forward", "forwardTo": "ada@gmail.com"},
|
|
214
|
+
idempotency_key="order-m_123-1",
|
|
215
|
+
)
|
|
216
|
+
status = stackshift.partner.get_domain(domain["id"])
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`partner` also exposes `overview`, `update_settings`, `list_domains` (with `q`, `attention` and `website` to find the merchants that need you), `connect_domain` and `transfer_in_domain` / `transfer_in_connected_domain` / `switch_transfer_nameservers` for domains the merchant already owns, `set_website`, `remove_website`, `check_website` and `list_website_projects` for the storefront, `list_mailboxes`, `create_mailbox`, `update_mailbox`, `create_mailbox_password_link`, `pause_mailbox`, `resume_mailbox`, `remove_mailbox`, `create_alias`, `update_alias` and `remove_alias` for merchant mailboxes, `start_mail_migration`, `get_mail_migration`, `switch_mail_migration`, `cancel_mail_migration`, `retry_mail_migration`, `retry_mail_migration_account` and `skip_mail_migration_account` for moving old email in, `retry_domain`, `get_diagnosis`, `restore_dns`, `transfer_out`, `resume_brand`, `get_complaints`, `list_complaint_sources`, `suppress_never_opened`, `undo_suppression`, `usage`, `list_requests` and `create_request`. `transfer_out` needs the `partner:transfer` scope (or `*`); `partner:manage` alone is refused. Purchases are capped at 30 per minute and, per partner, at 25 domains in a rolling 24 hours (429 `daily_purchase_limit`; staff can raise it). Validation errors are 400, state conflicts are 409. The `brand` and `replies` dictionaries use API camelCase keys.
|
|
220
|
+
|
|
221
|
+
## Connected agents
|
|
222
|
+
|
|
223
|
+
An agent that holds a connection credential (issued by the owner, not an account API key) can use the same API the MCP tools and the CLI use:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
stackshift = StackShift(api_key=os.environ["STACKSHIFT_CONNECTION_CREDENTIAL"])
|
|
227
|
+
before = stackshift.agents.connections.identity().get("before_each_change")
|
|
228
|
+
operation = stackshift.agents.connections.operations.propose(
|
|
229
|
+
action="deployment.restart", resource_id=project_id, configuration={},
|
|
230
|
+
reason="Restart after the config fix", idempotency_key="restart-shop-1",
|
|
231
|
+
)
|
|
232
|
+
waited = stackshift.agents.connections.operations.wait(operation["id"])
|
|
233
|
+
while not waited["settled"]:
|
|
234
|
+
waited = stackshift.agents.connections.operations.wait(operation["id"])
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`agents.connections` has `identity`, `resources`, `capabilities`, `plan`, `task_facts(objective_id)`, `history` and `lower_level(level=..., expected_version=...)`; `agents.connections.operations` has `list`, `propose`, `get`, `wait` and `approval`. `propose` needs an `idempotency_key`: keep it and send the same one to retry. `wait` returns `settled: False` when the owner has not decided yet; call it again instead of proposing again. `approval(id)` says whether the owner has decided, with `review_url` for the owner. `lower_level` only makes the connection stricter; raising a level raises `StackShiftAPIError` with `code` `session_required`.
|
|
238
|
+
|
|
239
|
+
## Manage the agents you run on StackShift
|
|
240
|
+
|
|
241
|
+
`hosted_agents` manages agents that run on StackShift from your own code or a script. It is separate from `agents`, which is for agents that hold a connection credential.
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
stackshift = StackShift(api_key=os.environ["STACKSHIFT_API_KEY"])
|
|
245
|
+
agent = stackshift.hosted_agents.create(
|
|
246
|
+
{"name": "Supplies agent", "source": {"template": "inbox-helper", "language": "python"}, "level": "ask_every_time"},
|
|
247
|
+
idempotency_key="supplies-agent-1",
|
|
248
|
+
)
|
|
249
|
+
stackshift.hosted_agents.secrets.set(agent["id"], "SHOP_API_KEY", os.environ["SHOP_API_KEY"])
|
|
250
|
+
stackshift.hosted_agents.budget.set(agent["id"], {"ai_credits_per_month": 200000, "compute_per_day": {"NGN": "5000000"}})
|
|
251
|
+
stackshift.hosted_agents.deploy(agent["id"], branch="main")
|
|
252
|
+
runs = stackshift.hosted_agents.runs(agent["id"], limit=10)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
`hosted_agents` has `list`, `get`, `create`, `deploy`, `rollback(id, version)`, `stop(id, reason=None)`, `start`, `delete`, `runs`, `run`, `spend(id, days=None)` and `logs(id, offset=None)`, plus `secrets.set`, `secrets.unset` and `budget.set`. `create` needs an `idempotency_key`: keep it and send the same one to retry. Money amounts are in minor units (kobo or cents). To write the agent itself, use `stackshift-agent`.
|
|
256
|
+
|
|
257
|
+
## Databases: Branches and Sleep when idle
|
|
258
|
+
|
|
259
|
+
Branches give you a copy of a database for a test run, a preview or a pull request. `with_branch` makes one, waits until it is ready and always deletes it when the block ends:
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
with stackshift.databases.branches.with_branch(database_id) as branch:
|
|
263
|
+
run_migrations_and_tests(branch["url"])
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
If the block raises, that error is the one you get back (a failed cleanup is attached as `cleanup_error`); a slow create is waited out before the Branch is deleted (`cleanup_timeout`, default 10 minutes). `branch["url"]` is the shared (pooled) connection string; pass `direct=True` for the direct one. `databases.branches` also has `list`, `create`, `get`, `update`, `delete`, `reset`, `retry` (a failed Branch), `promote`, `operation`, `wait_for_operation`, `url`, `options` (what a new Branch can start from), `changes` and `resume_scheduled_jobs`. `list` also returns your plan `allowance`. `create`, `reset`, `retry`, `promote` and `delete` return an operation; `wait_for_operation` polls it until it succeeds or fails. `reset`, `retry`, `promote` and `delete` send an `Idempotency-Key` (a new one for each call if you do not pass `idempotency_key`). Deleting with `cascade=True` also needs `confirm_name` (the Branch's name), or a `ValueError` is raised before the call is sent. `promote` accepts the parent's name or, when the parent is a Branch, its short name. `databases.sleep`, `databases.wake`, `databases.billing`, `databases.branch_usage`, `databases.pay_branch_usage`, `databases.scheduled_jobs`, `databases.wake_events`, `databases.move_to_instant_branches` and `databases.instant_branches_move` cover Sleep when idle and the move to instant Branches. Refusals raise `StackShiftAPIError` with `code` set to values such as `plan_limit`, `no_capacity`, `outside_window`, `too_large` and `payment_required`. On a Dedicated database, `create` and `retry` first raise `price_confirmation_required` with the price in `error.details["quote"]`; send the same call again with `confirm_charge_minor=error.details["quote"]["charge_minor"]`. `create` also takes `instance_class` to pick the size of a Dedicated Branch, and a Dedicated Branch carries its `cost`. A `plan_limit` error carries `limit`, `current` and `upgrade_url` in `details`.
|
|
267
|
+
|
|
268
|
+
## AI credits
|
|
269
|
+
|
|
270
|
+
AI credits are account-scoped. Use the shared client to inspect usage, start a top-up, or select managed billing versus your own provider key:
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from stackshift import StackShift
|
|
274
|
+
|
|
275
|
+
stackshift = StackShift()
|
|
276
|
+
balance = stackshift.ai_credits.balance()
|
|
277
|
+
usage = stackshift.ai_credits.usage(product="assets", limit=25)
|
|
278
|
+
quote = stackshift.ai_credits.quote(1_000, "USD")
|
|
279
|
+
checkout = stackshift.ai_credits.checkout(
|
|
280
|
+
quote["id"],
|
|
281
|
+
"unique-checkout-id",
|
|
282
|
+
"paystack",
|
|
283
|
+
)
|
|
284
|
+
stackshift.ai_credits.set_funding("assets", "managed")
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Keep account API keys and checkout creation on your server.
|
|
288
|
+
|
|
289
|
+
## Send email
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
from stackshift import StackShift
|
|
293
|
+
|
|
294
|
+
stackshift = StackShift()
|
|
295
|
+
|
|
296
|
+
message = stackshift.mail.send(
|
|
297
|
+
from_="StackShift <noreply@mail.stackshift.cloud>",
|
|
298
|
+
to="ada@example.com",
|
|
299
|
+
subject="Welcome",
|
|
300
|
+
text="Welcome to StackShift.",
|
|
301
|
+
idempotency_key="welcome:user_123",
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
print(message["id"], message["status"], message["idempotencyStatus"])
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Inspect message status:
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
messages = stackshift.mail.messages.list(status="mta_accepted", limit=20)
|
|
311
|
+
detail = stackshift.mail.messages.get(messages["data"][0]["id"])
|
|
312
|
+
attempts = stackshift.mail.messages.attempts(detail["id"])
|
|
313
|
+
logs = stackshift.mail.messages.logs(detail["id"])
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
`mta_accepted` means the message was accepted by StackShift's outbound MTA. It does not mean recipient-MX acceptance, inbox placement, opens, clicks, or spam placement. Recipient records later transition independently to `delayed`, `delivered`, `bounced`, `failed`, `suppressed`, or `complained`.
|
|
317
|
+
|
|
318
|
+
## Events and webhooks
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
events = stackshift.mail.events.list(
|
|
322
|
+
type="mail.message.bounced",
|
|
323
|
+
message_id="msg_123",
|
|
324
|
+
limit=20,
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
event = stackshift.mail.events.get("evt_123")
|
|
328
|
+
timeline = stackshift.mail.messages.timeline("msg_123")
|
|
329
|
+
|
|
330
|
+
webhook = stackshift.mail.webhooks.create(
|
|
331
|
+
url="https://example.com/stackshift-mail",
|
|
332
|
+
event_types=["mail.message.bounced", "mail.otp.verified"],
|
|
333
|
+
)
|
|
334
|
+
print(webhook["id"], webhook["secret"]) # Secret is only returned on create/rotate.
|
|
335
|
+
|
|
336
|
+
deliveries = stackshift.mail.webhooks.deliveries(webhook["id"], status="failed")
|
|
337
|
+
retried = stackshift.mail.webhooks.retry_delivery(deliveries["data"][0]["id"])
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Verify a webhook signature before processing the payload:
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
valid = stackshift.mail.webhooks.verify_signature(
|
|
344
|
+
raw_body=request.get_data(),
|
|
345
|
+
signature_header=request.headers.get("StackShift-Signature"),
|
|
346
|
+
timestamp_header=request.headers.get("StackShift-Timestamp"),
|
|
347
|
+
secret=os.environ["STACKSHIFT_WEBHOOK_SECRET"],
|
|
348
|
+
)
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Webhook handlers should be idempotent. StackShift retries non-2xx responses. Delivery events do not include full email bodies or OTP codes by default.
|
|
352
|
+
|
|
353
|
+
## Mailboxes
|
|
354
|
+
|
|
355
|
+
Host real mailboxes on your own domain. The mailbox owner gets an invitation by email and sets their own password.
|
|
356
|
+
|
|
357
|
+
```python
|
|
358
|
+
domain = stackshift.mail.mailbox_domains.create("acme.com")
|
|
359
|
+
print(domain["records"])
|
|
360
|
+
stackshift.mail.mailbox_domains.verify(domain["id"])
|
|
361
|
+
|
|
362
|
+
mailbox = stackshift.mail.mailboxes.create(
|
|
363
|
+
domain_id=domain["id"],
|
|
364
|
+
local_part="ada",
|
|
365
|
+
owner_email="ada@personal.example",
|
|
366
|
+
plan="basic",
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
stackshift.mail.aliases.create(mailbox_id=mailbox["id"], local_part="sales", send_as=True)
|
|
370
|
+
stackshift.mail.routes.create(
|
|
371
|
+
domain_id=domain["id"],
|
|
372
|
+
pattern="orders-*",
|
|
373
|
+
targets=[{"kind": "app", "webhookUrl": "https://app.example.com/inbound"}],
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
devices = stackshift.mail.mailboxes.list_devices(mailbox["id"])
|
|
377
|
+
stackshift.mail.mailboxes.suspend(mailbox["id"])
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
`stackshift.mail.groups` manages team addresses, and `stackshift.mail.mailbox_imports` copies mail from Google, Microsoft or any IMAP server.
|
|
381
|
+
|
|
382
|
+
## Give your agent an email address in one call
|
|
383
|
+
|
|
384
|
+
Agent inboxes are real addresses on StackShift's shared domain. Create one, let your agent sign up somewhere, wait for the verification code and delete the inbox when the job is done.
|
|
385
|
+
|
|
386
|
+
```python
|
|
387
|
+
inbox = stackshift.mail.agent_inboxes.create(
|
|
388
|
+
prefix="signup",
|
|
389
|
+
labels={"job": "onboarding-42"},
|
|
390
|
+
job_id="onboarding-42",
|
|
391
|
+
expires_in=3600,
|
|
392
|
+
idempotency_key="onboarding-42-inbox",
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
sign_up_somewhere(inbox["address"])
|
|
396
|
+
|
|
397
|
+
message = stackshift.mail.agent_inboxes.wait_for_message(
|
|
398
|
+
inbox["id"],
|
|
399
|
+
sender="paystack.com",
|
|
400
|
+
timeout=120,
|
|
401
|
+
since=inbox["createdAt"],
|
|
402
|
+
)
|
|
403
|
+
if message:
|
|
404
|
+
print(message["codes"][0], message["links"])
|
|
405
|
+
|
|
406
|
+
stackshift.mail.agent_inboxes.finish_job("onboarding-42")
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
`wait_for_message` calls the server wait endpoint in turns of up to 50 seconds until a message arrives or `timeout` (seconds, default 30) is used up, and returns `None` on timeout. Pass `since` (usually `inbox["createdAt"]`) so a message that arrived before you started waiting is found. `delete_many` takes `ids`, `job_id` or `labels`; `finish_job(job_id)` is the same as `delete_many(job_id=...)`. `create_batch` makes up to 100 inboxes at once.
|
|
410
|
+
|
|
411
|
+
Read mail with `agent_inboxes.messages.list`, `messages.latest(sender=..., subject=...)` and `messages.get`. Find inboxes with `agent_inboxes.list(labels=..., job_id=..., q=..., domain=..., limit=..., cursor=...)`, change them with `update`, remove one with `delete`, and check what your account may do with `limits()` and `pricing()`.
|
|
412
|
+
|
|
413
|
+
Sending never hides an approval. `send` returns `status` as `sent`, `waiting_approval` or `draft`, plus `pendingReplyId` and `reasons` when a person has to approve first:
|
|
414
|
+
|
|
415
|
+
```python
|
|
416
|
+
result = stackshift.mail.agent_inboxes.send(
|
|
417
|
+
inbox["id"],
|
|
418
|
+
to=["ada@example.com"],
|
|
419
|
+
subject="Re: your question",
|
|
420
|
+
text="Thanks, here is the answer.",
|
|
421
|
+
reply_to_message_id=message["id"],
|
|
422
|
+
)
|
|
423
|
+
if result["status"] == "waiting_approval":
|
|
424
|
+
print("Waiting for a person to approve", result["pendingReplyId"], result["reasons"])
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Team inboxes
|
|
428
|
+
|
|
429
|
+
Team inboxes are shared mailboxes your people and agents work together. Use the mailbox id:
|
|
430
|
+
|
|
431
|
+
```python
|
|
432
|
+
page = stackshift.mail.team_inboxes.conversations.list(mailbox_id, status="open", assignee="nobody")
|
|
433
|
+
thread = page["conversations"][0]
|
|
434
|
+
stackshift.mail.team_inboxes.conversations.assign(mailbox_id, thread["threadId"], worker_id=worker_id, expected_revision=thread["revision"])
|
|
435
|
+
stackshift.mail.team_inboxes.conversations.add_note(mailbox_id, thread["threadId"], body="Checked the logs, restarting the app.")
|
|
436
|
+
|
|
437
|
+
waiting = stackshift.mail.team_inboxes.pending_replies.list(mailbox_id)["pendingReplies"]
|
|
438
|
+
stackshift.mail.team_inboxes.pending_replies.send(mailbox_id, waiting[0]["id"])
|
|
439
|
+
|
|
440
|
+
activity = stackshift.mail.team_inboxes.activity.wait(mailbox_id, after=cursor, timeout=30)
|
|
441
|
+
cursor = activity["next"]
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
`conversations.reply(mailbox_id, thread_id, draft_email_id=...)` sends a draft you prepared as the inbox, `conversations.set_status` takes `status` and `expected_revision`, `settings.get(mailbox_id)` reads the inbox settings, and `people(mailbox_id)` returns `{"people": [...], "workers": [...]}`: the people (`userId`, `name`, `email`) and workers you can assign conversations to. `activity.wait` checks for new activity after your cursor every 2 seconds (`interval`) until something happens or `timeout` seconds pass. Refusals raise `StackShiftAPIError` with `code` set to values such as `reply_locked`, `revision_conflict`, `reply_already_decided`, `send_in_progress` (409, a send for the same conversation is already running; wait for it to finish) and `mail_allowance_reached`.
|
|
445
|
+
|
|
446
|
+
To get inbox events at your own endpoint, create a webhook with `mailbox_id` and the `mailbox.conversation.*` events you want, and check it with `stackshift.mail.webhooks.test(webhook_id)`, which returns `{"deliveryId": ..., "eventId": ...}` once the test event is queued (202).
|
|
447
|
+
|
|
448
|
+
### Inbox webhooks
|
|
449
|
+
|
|
450
|
+
Inbox events (`mailbox.conversation.*`, `mailbox.agent_inbox.*`, `mailbox.sending.*`) use the same `StackShift-Signature` header as Mail webhooks:
|
|
451
|
+
|
|
452
|
+
```python
|
|
453
|
+
from stackshift import verify_inbox_webhook
|
|
454
|
+
|
|
455
|
+
raw_body = request.get_data()
|
|
456
|
+
if not verify_inbox_webhook(raw_body, request.headers.get("StackShift-Signature"), os.environ["STACKSHIFT_WEBHOOK_SECRET"]):
|
|
457
|
+
return "Invalid signature", 400
|
|
458
|
+
event = json.loads(raw_body)
|
|
459
|
+
if event["type"] == "mailbox.conversation.received":
|
|
460
|
+
print(event["data"]["conversation"]["subject"])
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
Signatures older than five minutes are refused. Handlers should be idempotent. `InboxWebhookEvent` and the `INBOX_*_EVENT_TYPES` lists describe the payloads.
|
|
464
|
+
|
|
465
|
+
## Agent agreements
|
|
466
|
+
|
|
467
|
+
Agent inboxes can ask for quotes, quote, offer times, and accept or decline offers. Every agreement ends in a record you can check from anywhere.
|
|
468
|
+
|
|
469
|
+
```python
|
|
470
|
+
threads = stackshift.mail.agreements.list(inbox_id=inbox["id"], state="waiting_for_you")
|
|
471
|
+
|
|
472
|
+
sent = stackshift.mail.agreements.propose(
|
|
473
|
+
inbox["id"],
|
|
474
|
+
type="ask_quote",
|
|
475
|
+
to="orders@mills.example",
|
|
476
|
+
items=[{"description": "Flour", "quantity": "200", "unit": "kg"}],
|
|
477
|
+
wanted_by="2026-11-10",
|
|
478
|
+
idempotency_key="flour-nov-1",
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
change = stackshift.mail.agreements.wait_for_change(sent["threadId"])
|
|
482
|
+
stackshift.mail.agreements.accept(sent["threadId"], "OFFER_ID", idempotency_key="flour-accept-1")
|
|
483
|
+
|
|
484
|
+
record = stackshift.mail.agreements.record(sent["threadId"])
|
|
485
|
+
print(stackshift.mail.agreements.check(record)["summary"])
|
|
486
|
+
print(stackshift.mail.agreements.limits.get(inbox["id"])["usedToday"])
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Whether an agent may send on its own depends on the limits the owner sets for the inbox. Anything outside them waits for the owner's approval. Limits are changed in the dashboard.
|
|
490
|
+
|
|
491
|
+
## Send a template
|
|
492
|
+
|
|
493
|
+
Templates are rendered by StackShift servers. The Python SDK only calls the REST API.
|
|
494
|
+
|
|
495
|
+
```python
|
|
496
|
+
stackshift.mail.templates.create(
|
|
497
|
+
name="Welcome Email",
|
|
498
|
+
slug="welcome-email",
|
|
499
|
+
subject="Welcome, {{name}}",
|
|
500
|
+
text="Welcome, {{name}}",
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
preview = stackshift.mail.templates.preview(
|
|
504
|
+
"welcome-email",
|
|
505
|
+
data={"name": "Ada"},
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
message = stackshift.mail.send_template(
|
|
509
|
+
template="welcome-email",
|
|
510
|
+
to="ada@example.com",
|
|
511
|
+
from_="Acme <noreply@acme.com>",
|
|
512
|
+
data={"name": "Ada"},
|
|
513
|
+
idempotency_key="welcome:user_123",
|
|
514
|
+
)
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
Missing variables fail before a message is queued. Template sends use the same sender-domain, suppression, idempotency, Durable Jobs, and Postfix handoff pipeline as `mail.send`.
|
|
518
|
+
|
|
519
|
+
## Bounces and suppressions
|
|
520
|
+
|
|
521
|
+
```python
|
|
522
|
+
suppressions = stackshift.mail.suppressions.list()
|
|
523
|
+
|
|
524
|
+
manual = stackshift.mail.suppressions.create(
|
|
525
|
+
email="bad@example.com",
|
|
526
|
+
reason="manual",
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
stackshift.mail.suppressions.delete(manual["id"])
|
|
530
|
+
|
|
531
|
+
bounces = stackshift.mail.bounces.list(type="hard")
|
|
532
|
+
message_bounces = stackshift.mail.messages.bounces("msg_123")
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
Hard bounces are automatically suppressed by the backend. Suppressions are workspace scoped and checked before a message is queued.
|
|
536
|
+
|
|
537
|
+
## Verify a sending domain
|
|
538
|
+
|
|
539
|
+
```python
|
|
540
|
+
domain = stackshift.mail.domains.create("acme.com")
|
|
541
|
+
print(domain["records"])
|
|
542
|
+
|
|
543
|
+
stackshift.mail.domains.verify(domain["id"])
|
|
544
|
+
|
|
545
|
+
message = stackshift.mail.send(
|
|
546
|
+
from_="Acme <noreply@acme.com>",
|
|
547
|
+
to="user@example.com",
|
|
548
|
+
subject="Welcome",
|
|
549
|
+
html="<h1>Welcome</h1>",
|
|
550
|
+
text="Welcome",
|
|
551
|
+
)
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
Add the returned SPF, DKIM, and return-path DNS records before verification. DMARC is recommended unless your environment sets `MAIL_DMARC_REQUIRED=true`. DNS propagation can take time.
|
|
555
|
+
|
|
556
|
+
## Upload an asset
|
|
557
|
+
|
|
558
|
+
```python
|
|
559
|
+
from stackshift import StackShift
|
|
560
|
+
|
|
561
|
+
stackshift = StackShift()
|
|
562
|
+
|
|
563
|
+
asset = stackshift.assets.upload(
|
|
564
|
+
"avatar.png",
|
|
565
|
+
folder="avatars",
|
|
566
|
+
visibility="public",
|
|
567
|
+
metadata={"user_id": "user_123"},
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
print(asset["url"])
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
You do not pass a deployed StackShift project ID. The API key identifies the StackShift account, and StackShift resolves the default asset space internally.
|
|
574
|
+
|
|
575
|
+
## Private asset URL
|
|
576
|
+
|
|
577
|
+
```python
|
|
578
|
+
signed = stackshift.assets.signed_url(
|
|
579
|
+
asset["id"],
|
|
580
|
+
expires_in="10m",
|
|
581
|
+
max_downloads=1,
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
print(signed["url"])
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
## Image transformations
|
|
588
|
+
|
|
589
|
+
Use built-in presets or create your own named transformations.
|
|
590
|
+
|
|
591
|
+
```python
|
|
592
|
+
from stackshift import StackShift, asset_transform_options, get_asset_transform_preset
|
|
593
|
+
|
|
594
|
+
stackshift = StackShift()
|
|
595
|
+
hero = get_asset_transform_preset("hero")
|
|
596
|
+
hero_options = asset_transform_options(hero)
|
|
597
|
+
|
|
598
|
+
stackshift.assets.create_transformation(hero["name"], **hero_options)
|
|
599
|
+
|
|
600
|
+
named = stackshift.assets.named_url("asset_123", hero["name"])
|
|
601
|
+
signed = stackshift.assets.signed_transform_url("asset_123", **hero_options, expiresIn="10m")
|
|
602
|
+
|
|
603
|
+
stackshift.assets.delete_transformation("old-preset")
|
|
604
|
+
print(named, signed["url"])
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
## Direct browser uploads
|
|
608
|
+
|
|
609
|
+
Create the upload session on your Python backend:
|
|
610
|
+
|
|
611
|
+
```python
|
|
612
|
+
upload = stackshift.assets.signed_upload_url(
|
|
613
|
+
bucket="avatars",
|
|
614
|
+
key="users/user_123.png",
|
|
615
|
+
visibility="public",
|
|
616
|
+
expiresIn="10m",
|
|
617
|
+
maxBytes=5_000_000,
|
|
618
|
+
)
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
Then upload the browser `File` to `upload["url"]` from your frontend. Do not expose your StackShift API key to browser code.
|
|
622
|
+
|
|
623
|
+
The SDK only talks to the StackShift REST API. Storage placement, replication, disks, and repair are StackShift internals.
|
|
624
|
+
|
|
625
|
+
### Campaign drafts and engagement
|
|
626
|
+
|
|
627
|
+
`mail.campaigns.create(content={...})` accepts a private campaign content snapshot; template/version inputs still work. Save the complete draft with `update(id, revision=revision, **draft)` (draft keys use API camelCase). `preview`, `test`, `send(id, revision=revision)`, and `schedule(id, send_at, revision=revision)` protect the reviewed content. Stale revisions return 409.
|
|
628
|
+
|
|
629
|
+
Send methods accept `tracking={"opens": False, "clicks": True}`. Omitted fields inherit workspace defaults. `mail.tracking` exposes `settings`, `update_settings`, `message`, `campaign`, and branded-domain methods. Deployment capability flags control availability. Opens are approximate; detailed activity expires after 90 days. OTPs and tests never track.
|
|
630
|
+
|
|
631
|
+
### Isolated testing, brands, migration, and spending
|
|
632
|
+
|
|
633
|
+
Use a `sspat_test_` credential and `simulation={"scenario": "delayed"}` for a 60-second simulated delay. Delivered, bounced, and complained outcomes are also supported. Test resources are isolated; no real email is delivered.
|
|
634
|
+
|
|
635
|
+
```python
|
|
636
|
+
brand = client.mail.brands.create(name="Product", editable_fields=["company"])
|
|
637
|
+
audience = client.mail.audiences.create(brand_id=brand["id"], name="Product news")
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
Audience creation requires an explicit `brand_id`. Shared profile fields belong to the brand; consent stays per audience. `mail.automations`, `mail.forms`, and `mail.segments` expose create/list methods; their input dictionaries use API camelCase keys.
|
|
641
|
+
|
|
642
|
+
`mail.migration` supports public DNS audits/plans and authenticated checklists. `mail.billing.summary()` and `mail.campaigns.estimate(id)` expose allowance and credit. Pass `approved_max_kobo=0` (or another approved maximum) alongside `revision` when sending/scheduling campaigns. Billing remains inactive until a rate card is explicitly published and activated; funding and spending opt-in are separate owner-only dashboard actions.
|
|
643
|
+
|
|
644
|
+
## Native video, governed DAM and product rendering
|
|
645
|
+
|
|
646
|
+
Use the space-scoped DAM and video clients for collaborators, metadata schemas, bucket governance, reviewed publications, picker capabilities, model preparation, product rendering, galleries, version-pinned encoding, captions and playback sessions.
|
|
647
|
+
|
|
648
|
+
```python
|
|
649
|
+
dam = sdk.assets.dam.for_space(space_id)
|
|
650
|
+
video = sdk.assets.video.for_space(space_id)
|
|
651
|
+
schema = dam.create_metadata_schema({"name": "Products", "fields": [{
|
|
652
|
+
"key": "product_name", "label": "Product name", "type": "text", "required": True,
|
|
653
|
+
}]})
|
|
654
|
+
published = dam.publish_metadata_schema(schema["id"], schema["revision"])
|
|
655
|
+
workspace = video.workspace(asset_id)
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
Mutations carry the supplied revision in `If-Match`. Model preparation and rendering carry an idempotency key; render submission also carries the accepted maximum units. Playback renewal and events authenticate with the session credential, not the account key. Keep these clients on your backend and return grants with `Cache-Control: private, no-store`.
|
|
659
|
+
|
|
660
|
+
See the [Assets SDK guide](https://docs.stackshift.cloud/assets/sdk-media-workflows) and its linked feature guides for complete language examples, inputs, permissions, review transitions and browser callbacks.
|
|
661
|
+
|
|
662
|
+
## Assets storage and Cloudinary migration
|
|
663
|
+
|
|
664
|
+
`sdk.assets.platform.for_space(space_id)` exposes `connections`, `storage`, and `migrations`. Use a verified Cloudinary connection, run a dry migration first, inspect its report, then start the transfer with the same folder prefix and conflict policy.
|
|
665
|
+
|
|
666
|
+
```python
|
|
667
|
+
platform = sdk.assets.platform.for_space(space_id)
|
|
668
|
+
preview = platform.migrations.start({"source_connection_id": connection_id,
|
|
669
|
+
"destination_bucket_id": bucket_id, "source_prefix": "campaigns/2026", "dry_run": True})
|
|
670
|
+
report = platform.migrations.report(preview["id"])
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
## Support action receivers (unreleased)
|
|
674
|
+
|
|
675
|
+
`ActionManifest`, `ActionDescriptor`, installation consent types and `validate_action_catalog` describe `stackshift.support.app/v2`. V1 remains actionless. Registered writes require idempotency, a reconciliation endpoint and a registered read verifier; installations explicitly select `action_operations`. These SDK helpers perform no registration or network calls.
|
|
676
|
+
|
|
677
|
+
Use `receive_action(raw_bytes, headers, store=..., execute=..., reconcile=..., verification=...)`. Verification requires `key_id`, `secret` (the installation action secret, not webhook secret), `installation_id`, `actions`, and a trusted `expected_customer_external_id`. Do not derive that expectation from unverified request JSON. Each synchronous handler returns `(state, result_dict, optional_safe_error_code)`. Success output is checked against the registered flat schema. Receipt helpers `encode_receipt`, `sign_action`, and `verify_receipt` are also exported.
|
|
678
|
+
|
|
679
|
+
`SQLiteActionStore('/absolute/path/claims.sqlite')` uses standard-library sqlite3, WAL and FULL synchronization. Never use an in-memory database for restart safety. The runnable stdin receiver in `examples/support_action_receiver.py` intentionally returns `demo_not_implemented`; replace its handlers with authorized customer-bound business transactions. Set `ACTION_KEY_ID`, `ACTION_SECRET`, `ACTION_INSTALLATION_ID`, and trusted `EXPECTED_CUSTOMER_EXTERNAL_ID`:
|
|
680
|
+
|
|
681
|
+
```sh
|
|
682
|
+
PYTHONPATH=. python examples/support_action_receiver.py /absolute/path/claims.sqlite headers.json actions.json < body.json
|
|
683
|
+
.venv/bin/python -m unittest discover -s tests -p test_support_actions.py -v
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
Send the returned `body` unchanged with `headers`. Execution retries retain exact original bytes and request ID with fresh delivery IDs. A handler error is stored as unknown; running/unknown work is never dispatched again. Reconciliation is a separate handler with empty arguments and the original target request ID, and must query actual downstream state. Accepted results remain replayable; there is no asynchronous callback endpoint yet. Disk claims do not make remote side effects atomic: use downstream idempotency or one transactional business/receipt store, and preserve uncertain claims for reconciliation/human review. This is a single-host SQLite example; distributed receivers need a shared durable store.
|
|
687
|
+
|
|
688
|
+
See `../support-actions-conformance/README.md` for exact signatures and adapter requirements. Seven action tests pass, including shared vectors, two-connection concurrency, restart and fenced completion. The existing virtualenv is required here because system Python lacks the SDK's declared `requests` dependency. No live installation/provider qualification was performed; unreleased.
|
|
689
|
+
|
|
690
|
+
## Computer teams
|
|
691
|
+
|
|
692
|
+
A team is several computers working one job together, each running an agent (`claude-code`, `codex`, `gemini`, `opencode` or `custom`), with a shared folder, a private network and a message board. Use a computers key, a personal API token or a dashboard session as `api_key`.
|
|
693
|
+
|
|
694
|
+
```python
|
|
695
|
+
team = stackshift.computers.teams.create(
|
|
696
|
+
project_id,
|
|
697
|
+
"checkout-fix",
|
|
698
|
+
"Refunds fail on partial orders. Claude fixes, Codex reviews, Gemini proves it with tests.",
|
|
699
|
+
[
|
|
700
|
+
{"name": "claude-fixer", "agent": "claude-code", "role": "Writes the fix"},
|
|
701
|
+
{"name": "codex-reviewer", "agent": "codex"},
|
|
702
|
+
{"name": "gemini-tests", "agent": "gemini"},
|
|
703
|
+
],
|
|
704
|
+
repository={"repository": "github.com/northwind/api", "revision": "main"},
|
|
705
|
+
stop_rule="done",
|
|
706
|
+
spend_limit={"amount_minor": 2000000, "currency": "NGN"},
|
|
707
|
+
)
|
|
708
|
+
stackshift.teams.send(team["id"], "Start with the partial refund path.", to="claude-fixer")
|
|
709
|
+
page = stackshift.teams.wait_for_messages(team["id"], after_seq=0, timeout=60)
|
|
710
|
+
for message in stackshift.teams.stream_messages(team["id"], after_seq=page["next_seq"]):
|
|
711
|
+
print(message["from"]["name"], message["text"])
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
`create` and `add_member` send an `Idempotency-Key` (pass `idempotency_key=` to reuse one). `update` takes `job`, `stop_rule`, `spend_limit` (`None` clears it) and `ask_before_acting`. `pause` and `resume` act on every member. `delete` sends the `X-StackShift-Confirm-Delete` header with the team id (pass `confirm=` to send the name) and deletes every member computer and the shared folder. `remove_member(team_id, member_id, keep_computer=True)` keeps the member's computer.
|
|
715
|
+
|
|
716
|
+
`list_messages(team_id, after_seq=, limit=, wait=)` long-polls for up to 25 seconds with `wait`. `wait_for_messages` keeps polling until a message arrives or `timeout` passes and returns the page, with empty `items` on timeout. `stream_messages` yields each message from the server-sent event stream, skips pings and reconnects from the last `seq`. `files(team_id, "/shared")`, `network(team_id)` and `activity(team_id)` read the shared folder, the member addresses and what each member is doing. The response shapes are `TypedDict`s in `stackshift.teams`.
|