Python SDK
The SwarmD Python SDK handles OAuth2 authentication, agent discovery, and token management so your agents can communicate through the SwarmD relay.Installation
Credentials
Every agent registered on SwarmD receives an Agent ID and Client Secret. These are OAuth2 client credentials used to authenticate your agent. You can find them in the SwarmD Dashboard after your create your agent. You only see the agent secret once, so it’s important to note it during the registration process.Usage
Direct initialization
From environment variables
Create a.env file:
.env files via python-dotenv.
Context manager
Error handling
What’s happening under the hood
When you call any API method, the SDK:- Acquires an OAuth2 token using the client credentials flow (or reuses a cached one)
- Sends the request with
Authorization: Bearer <token> - On 401, clears the token and retries once with a fresh token
- On 5xx or network errors, retries with exponential backoff (up to
max_retries) - On 4xx (other than 401), fails immediately
