The repository or configuration that created this release differ from a previous release. View details.
impulse-compute
The Python SDK for ImpulseCompute: sandboxes (each a microVM of its own), the commands they run, their files and the
ports they expose. Python 3.9 and later, sync (Compute) and async (AsyncCompute).
pip install impulse-compute
Quickstart
from impulse_compute import Compute
compute = Compute() # the key from COMPUTE_API_KEY
sbx = compute.sandboxes.create(template="node", ttl="30m")
try:
r = sbx.commands.run("node -e 'console.log(6 * 7)'")
print(r.stdout) # 42
# A path is absolute, or relative to the user's home (where commands run by default).
sbx.files.write("hello.txt", "hi\n")
print(sbx.files.read_text("hello.txt")) # hi
finally:
sbx.destroy()
The async client is the same, awaited:
from impulse_compute import AsyncCompute
async with AsyncCompute() as compute:
sbx = await compute.sandboxes.create(template="base")
r = await sbx.commands.run("uname -a")
await sbx.destroy()
A sandbox made without a firewall policy reaches no network at all: make it with one that allows what it needs
(firewall_policy).
The client
Compute(...) takes:
api_key: the API key, elseCOMPUTE_API_KEY;base_url: the API's address, elseCOMPUTE_API_URL, elsehttps://api.impulse.host/compute/v1(Impulse Hosting's, which opens with its beta; a hosting provider running ImpulseCompute has an address of its own);timeout: how long a call waits for its answer, in seconds (60 by default);max_retries: how many times a call that failed for a passing reason is tried again (2 by default);http_client,headers: an httpx client of your own, and headers for every call.
Close it with compute.close(), or use it as a context manager.
Calls are retried when no answer came (a connection refused or reset, a timeout), on 429, 502, 503 and 504
unless the API marks the error not retryable (a quota reached is not), and on any error it marks retryable. A retry
waits 0.5 s doubling (with jitter, up to 8 s), or as long as Retry-After says when that is a minute or less; a longer
wait is left to you, the error's retry_after saying how long. Every call that changes something carries an Idempotency-Key, the same on each of its retries,
so a retry never applies a change twice; pass idempotency_key where a helper takes one to make a change once across
your own retries too.
Sandboxes
sbx = compute.sandboxes.create(
template="base", # or node, deno, or a template of yours
name="build-42",
ttl="1h", # or seconds, or a timedelta
idle_suspend="10m", # False never suspends it
vcpu=2,
memory_mb=2048,
env={"APP_ENV": "production"},
secrets=["DATABASE_URL"],
firewall_policy="open",
labels={"team": "data"},
)
again = compute.sandboxes.get("build-42")
for s in compute.sandboxes.list(label="team=data"):
print(s.id, s.state, s.expires_at)
sbx.suspend() # memory and disk saved, memory released
sbx.resume()
sbx.extend("2h")
sbx.destroy()
Commands
# One call that waits: a string runs under /bin/sh -c, a list as it is.
r = sbx.commands.run(["python3", "-c", "print('hi')"], cwd="/srv", timeout=60)
r.exit_code, r.stdout, r.stderr, r.truncated
# Output as it arrives, and input.
sbx.commands.run("pytest", on_stdout=print, on_stderr=print)
sbx.commands.run("wc -c", stdin="hello")
# A non-zero exit is the result's to say; check makes it a CommandExitError.
sbx.commands.run("make", check=True)
# Started, then written to and read as it runs.
sh = sbx.commands.start("bash", stdin=True, tty={"rows": 40, "cols": 120})
sh.send_stdin("ls\nexit\n")
for ev in sh:
if ev.type == "stdout":
print(ev.data.decode(), end="")
result = sh.wait()
# One that runs on until it is signalled.
server = sbx.commands.start("python3 -m http.server 8080", on_stdout=print)
server.kill("INT")
server.wait()
A command's output is read once. A stream cut short (a connection lost, the sandbox suspended) is resumed after the
last record read; output missed meanwhile makes the result truncated. A result keeps up to 1 MiB of each stream;
the callbacks and the events see all of it. Reading a command's output resumes its sandbox if it was suspended, as any
call that reaches the sandbox does; disconnect() stops reading (the command runs on), and a later read resumes.
Files
sbx.files.write("/srv/data.json", json.dumps(data)) # text, bytes, a binary file or an iterator of bytes
data = sbx.files.read("/srv/out.bin")
text = sbx.files.read_text("/srv/out.txt")
for chunk in sbx.files.read_stream("/var/log/app.log"):
...
listing = sbx.files.list("/srv") # entries, sorted by name
info = sbx.files.stat("/srv/data.json")
sbx.files.exists("/srv/missing") # False
sbx.files.mkdir("/srv/a/b") # its missing parents too
sbx.files.rename("/srv/a", "/srv/c")
sbx.files.remove("/srv/c", recursive=True)
A file is written whole: a reader never sees half of it. Text and bytes carry their SHA-256, so the sandbox refuses a
body changed on the way. A refusal by the sandbox (a path not found, permission denied) is a ComputeError whose
path_reason() says why.
Ports
import httpx
app = sbx.commands.start("python3 -m http.server 8080")
preview = sbx.ports.expose(8080) # token-gated
# The app may take a moment to listen: until it does, the preview answers an error.
httpx.get(preview.url, headers=preview.headers()) # Impulse-Preview-Token
public = sbx.ports.expose(3000, public=True) # anyone with the URL: for a browser or an iframe
rotated = sbx.ports.rotate_token(8080, token_ttl="1h")
sbx.ports.unexpose(8080)
A private port's access token is in the answer that minted it only. When that answer is lost and a retry is told the token was already issued, the SDK rotates the token and returns the new one.
Templates and operations
tpl = compute.templates.build("py-data", image="python:3.12-slim")
sbx = compute.sandboxes.create(template="py-data")
# A call that starts work returns an Operation; wait for it.
op = compute.api.restart_service("api")
compute.operations.wait(op) # OperationFailedError, OperationTimeoutError
Cloaked secrets
A secret set with a cloak reaches your sandboxes and services as a placeholder. The egress proxy outside the VM
puts the value in the named request headers (Authorization unless you say otherwise) of HTTPS requests to the hosts
you named, and nowhere else.
compute.api.set_env_var("OPENAI_API_KEY", {"value": "sk-...", "secret": True, "cloak": {"hosts": ["api.openai.com"]}})
sbx = compute.sandboxes.create(template="node", secrets=["OPENAI_API_KEY"], firewall_policy="open")
# In the sandbox, OPENAI_API_KEY is impulse_cloaked_...; a request to api.openai.com carries the key.
The workload trusts the proxy through a certificate authority given to it at its start (SSL_CERT_FILE,
REQUESTS_CA_BUNDLE, NODE_EXTRA_CA_CERTS and the like are set for you). A value a host echoes in a response (as it
was sent, as JSON writes it, or percent-encoded) is turned back into the placeholder; one echoed in another form
(base64, a part of it) would still show the workload the value: name only the hosts the secret is for, and cloak a
random key.
Scoped sandboxes
A sandbox can be granted a prefix of one of your per-workload storage bindings, read-only unless you ask for
read_write (the API key needs compute:manage as well as compute:sandbox), and can act as one of your Impulse
Auth users with the access token your Auth service issued that user. It holds no standing key: the AWS SDKs inside it
fetch short-lived keys from the machine that runs it, and it reads the token at IMPULSE_ACT_AS_TOKEN_URI.
sbx = compute.sandboxes.create(
template="node",
ttl="1h", # at least as long as the token lasts
grant={"binding": "agent-data", "prefix": "runs/42/"},
act_as={"auth_binding": "users", "user_access_token": user_access_token},
)
sbx.grant # {"binding", "prefix", "access", "generation"}
sbx.act_as # {"auth_binding", "user_id", "expires_at"}, never the token
sbx.replace_act_as(fresh_token) # the same user, before the token ends
sbx.drop_act_as()
The token is the user's whole credential while it lasts: anything in the sandbox can read it. Require reauthentication for password changes in every project whose tokens you hand to a sandbox.
Everything else
compute.api has one method per operation of the API, with its types, for what the helpers do not cover: services,
deployments, environment variables, firewall policies and logs.
Errors
ComputeError: the API answered with an error. It has thestatus, thecode(resource_not_found,quota_exceeded, …), thedetail, therequest_idto quote to support, and the rest of the problem.ComputeConnectionError: no answer, after the call's retries.OperationFailedError,OperationTimeoutError,CommandExitErrorandDisconnectedError.
All of them are ImpulseComputeErrors.
Licence
MIT.
Metadata
Release files for impulse-compute 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Change of provenance
The repository or configuration that created these release files differ from that of a previous release.
We recommend inspecting the repository and configuration before proceeding. View details.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| impulse_compute-0.1.1.tar.gz | 96.8 kB | With provenance | Details for impulse_compute-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| impulse_compute-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for impulse_compute-0.1.1-py3-none-any.whl |
Total release size: 180.8 kB
Release files / impulse_compute-0.1.1.tar.gz
Change of provenance
This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.
We recommend inspecting the repository and configuration before proceeding. View details.
| Download URL | impulse_compute-0.1.1.tar.gz |
|---|---|
| Size | 96.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54033a77f3da82a4dfe6d0d7e4d53e0e059132a2974dcf24b5c945e990af712e
|
|
BLAKE2b-256 checksum How to use checksums |
0577f1dd717fd607617eb3ffbd16066081ebb5e7c0012c1a58fe020b2b92030c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / impulse_compute-0.1.1-py3-none-any.whl
Change of provenance
This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.
We recommend inspecting the repository and configuration before proceeding. View details.
| Download URL | impulse_compute-0.1.1-py3-none-any.whl |
|---|---|
| Size | 84.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b43006b2c6f81f2a72bf19aea4c935491c51a78d0a8de987eea1adb4768733d
|
|
BLAKE2b-256 checksum How to use checksums |
c8735b03cfc71909e48e9e414cb22aa7b72df62af63951607823eef926c7185d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for impulse-compute 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.
Change of provenance
The repository and configuration that created this release differ from a previous release.
While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.
Repository
Attestation for impulse_compute-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA 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.