Skip to main content

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.

Metadata

Release files for server4agent 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for server4agent 0.1.0
File Size Uploaded
server4agent-0.1.0.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for server4agent 0.1.0
File Interpreter ABI Platform
server4agent-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.9 kB

Release files / server4agent-0.1.0.tar.gz

Download URL server4agent-0.1.0.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1cde2b2e34bcc9ed8876cae3c42fba59c849398f476cf7dd216006f487fd5046
BLAKE2b-256 checksum
How to use checksums
4a912aa2d5d07722e6046e0401b4deb809438b7e9014b40d1f860d9c31580fd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 14, 2026.

Transparency log

Release files / server4agent-0.1.0-py3-none-any.whl

Download URL server4agent-0.1.0-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1fab46f6bb1efb92218179b89c4fc17e23fd45c35d3031c0a5bea0d5f028ad0
BLAKE2b-256 checksum
How to use checksums
871bc6620d2b5454c4830c847f43ea8ee26fb8b707c74fae9d576b7ddaf1f115
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page