Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

server4agent-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

server4agent-0.1.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

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

Hashes for server4agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1cde2b2e34bcc9ed8876cae3c42fba59c849398f476cf7dd216006f487fd5046
MD5 114163f40e8f245bbffd16a1e2bde8dc
BLAKE2b-256 4a912aa2d5d07722e6046e0401b4deb809438b7e9014b40d1f860d9c31580fd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for server4agent-0.1.0.tar.gz:

Publisher: publish-sdk-python.yml on michalakmarcinth/Server4Agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for server4agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1fab46f6bb1efb92218179b89c4fc17e23fd45c35d3031c0a5bea0d5f028ad0
MD5 403fa1c350495c72a53eb665f161a433
BLAKE2b-256 871bc6620d2b5454c4830c847f43ea8ee26fb8b707c74fae9d576b7ddaf1f115

See more details on using hashes here.

Provenance

The following attestation bundles were made for server4agent-0.1.0-py3-none-any.whl:

Publisher: publish-sdk-python.yml on michalakmarcinth/Server4Agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page