Python client for the Server4Agent REST API — sync + async, typed, with retries.
Project description
server4agent
Python client for the Server4Agent REST API — sync and async, fully typed, with automatic retries.
This SDK is for the code around your agent — your backend, a script, a notebook, a webhook receiver. If your agent itself does tool-calling, point it at the MCP server directly; it doesn't need this package.
Install
pip install server4agent
Requires Python 3.9+. Depends only on httpx.
Quickstart
from server4agent import Server4Agent
client = Server4Agent() # reads SERVER4AGENT_API_KEY from the environment
# create() returns a handle you can act on directly
server = client.servers.create(tier="small")
# kick off a build and block until it's live
build = server.builds.start("a FastAPI todo API with a web UI").wait()
print(build.url)
# run a command right on the server
print(server.exec("ls -la"))
api_key can also be passed explicitly: Server4Agent(api_key="sk_live_...").
Use it as a context manager to close the connection pool:
with Server4Agent() as client:
...
Async
The async client mirrors the sync one method-for-method:
import asyncio
from server4agent import AsyncServer4Agent
async def main():
async with AsyncServer4Agent() as client:
server = await client.servers.create(tier="small")
task = await server.tasks.create("Scrape today's HN front page to JSON.")
await task.wait()
print(task.status, task.result)
asyncio.run(main())
Handles
create() and get() return rich handles — data records you can also act on:
server = client.servers.get("srv_abc")
server.tasks.create("...") # sub-resources are scoped to the server
server.files.write("app.py", "...")
server.deploy()
server.refresh() # re-fetch in place
project = client.projects.get("prj_xyz")
project.update(visibility="public")
task.wait() / build.wait() poll until a terminal state; both accept
poll_interval and timeout (seconds).
Errors
Every failure is a subclass of Server4AgentError, so you can catch broadly or
narrowly:
from server4agent import NotFoundError, RateLimitError, APIStatusError
try:
client.servers.get("srv_missing")
except NotFoundError:
... # 404
except RateLimitError as e:
... # 429 (already retried; quote e.request_id to support)
except APIStatusError as e:
print(e.status, e.code, e.message, e.request_id)
Retryable failures (429, 5xx, network blips) are retried automatically with exponential backoff. Tune it per client:
Server4Agent(timeout=30.0, max_retries=4)
Verifying webhooks
import os
from server4agent import verify_webhook_signature
# request.data must be the raw body — parse it as JSON only after verifying.
ok = verify_webhook_signature(
secret=os.environ["SERVER4AGENT_WEBHOOK_SECRET"],
body=request.data.decode("utf-8"),
header=request.headers.get("Server4Agent-Signature"),
)
if not ok:
return "invalid signature", 401
API surface
servers, projects, templates, tasks, builds, files, keys,
webhooks — see the REST API docs for
the endpoints each method wraps.
Server-side only: this SDK holds your sk_live_ key. Never embed it in a
notebook or script you share.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file server4agent-0.1.0.tar.gz.
File metadata
- Download URL: server4agent-0.1.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cde2b2e34bcc9ed8876cae3c42fba59c849398f476cf7dd216006f487fd5046
|
|
| MD5 |
114163f40e8f245bbffd16a1e2bde8dc
|
|
| BLAKE2b-256 |
4a912aa2d5d07722e6046e0401b4deb809438b7e9014b40d1f860d9c31580fd9
|
Provenance
The following attestation bundles were made for server4agent-0.1.0.tar.gz:
Publisher:
publish-sdk-python.yml on michalakmarcinth/Server4Agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
server4agent-0.1.0.tar.gz -
Subject digest:
1cde2b2e34bcc9ed8876cae3c42fba59c849398f476cf7dd216006f487fd5046 - Sigstore transparency entry: 2169854234
- Sigstore integration time:
-
Permalink:
michalakmarcinth/Server4Agent@5124a18dc4cf81e6bc431f80e3b46b28f283a271 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/michalakmarcinth
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-python.yml@5124a18dc4cf81e6bc431f80e3b46b28f283a271 -
Trigger Event:
push
-
Statement type:
File details
Details for the file server4agent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: server4agent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1fab46f6bb1efb92218179b89c4fc17e23fd45c35d3031c0a5bea0d5f028ad0
|
|
| MD5 |
403fa1c350495c72a53eb665f161a433
|
|
| BLAKE2b-256 |
871bc6620d2b5454c4830c847f43ea8ee26fb8b707c74fae9d576b7ddaf1f115
|
Provenance
The following attestation bundles were made for server4agent-0.1.0-py3-none-any.whl:
Publisher:
publish-sdk-python.yml on michalakmarcinth/Server4Agent
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
server4agent-0.1.0-py3-none-any.whl -
Subject digest:
d1fab46f6bb1efb92218179b89c4fc17e23fd45c35d3031c0a5bea0d5f028ad0 - Sigstore transparency entry: 2169854303
- Sigstore integration time:
-
Permalink:
michalakmarcinth/Server4Agent@5124a18dc4cf81e6bc431f80e3b46b28f283a271 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/michalakmarcinth
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-python.yml@5124a18dc4cf81e6bc431f80e3b46b28f283a271 -
Trigger Event:
push
-
Statement type: