The AgentMail Python library provides convenient access to the AgentMail APIs, an API-first email platform designed for AI agents. It allows programmatic creation and management of email inboxes, sending/receiving emails, and handling email-based workflows with webhooks and real-time events. The library is currently at version 0.4.15 and receives frequent updates, indicating an active development cadence.
pip install agentmailVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the AgentMail client using an API key from environment variables, create a new inbox (or use an existing one), and send a basic email. It includes basic error handling and highlights the common use of `python-dotenv` for API key management.
Store `AGENTMAIL_API_KEY` in your environment or a `.env` file and load it using `os.environ.get('AGENTMAIL_API_KEY')`.Implement specific `try...except ApiError as e:` blocks to inspect `e.status_code` and `e.body` for detailed error information.
Monitor for `ApiError` with `status_code == 429` and implement additional application-level retry logic with exponential backoff if the default SDK retries are insufficient for your use case.
When creating resources that require idempotency, pass a unique `client_id` parameter to the API call. The AgentMail API will use this ID to ensure the operation is processed only once.
If customizing the HTTP client for `AsyncAgentMail`, use `httpx.AsyncClient()` for `httpx_client` to maintain asynchronous behavior.
Install the package using 'pip install agentmail'.
Ensure the latest version of 'agentmail' is installed using 'pip install --upgrade agentmail'.
Initialize the 'AgentMail' client with the 'api_key' parameter: 'client = AgentMail(api_key="YOUR_API_KEY")'.
Reinstall the 'agentmail' package using 'pip install --force-reinstall agentmail'.
Verify and use a valid API key obtained from the AgentMail console.