Libraries
Client libraries
Official libraries for JavaScript, Python, PHP and Go: install, configure and what they handle for you.
The libraries#
There is a small, dependency-light client for each of four languages. They wrap the developer API (/v1), nothing else. The dashboard's own routes are not covered.
| Language | Package | Needs |
|---|---|---|
| JavaScript and TypeScript | @cirrus-mail/cirrus | Node 18 or newer; no dependencies; ships its own types |
| Python | cirrus-mail (import cirrus) | Python 3.9 or newer; standard library only |
| PHP | cirrus-mail/cirrus-php | PHP 8.1 or newer, with ext-curl and ext-json |
| Go | github.com/cirrus-mail/cirrus-go | Go 1.21 or newer; standard library only |
# Nothing to install: curl talks to the API directly.
export CIRRUS_API_KEY="cirrus_test_..."Set up a client#
You give a client your API key once. Do not write the key in your code: read it from the environment, as below. The Python library can do that for you with Cirrus.from_env(), which reads CIRRUS_API_KEY and, if set, CIRRUS_BASE_URL.
export CIRRUS_API_KEY="cirrus_test_..." # the key you copied in step 1Options#
Every library takes the same four settings. The baseUrl is the host only; the library adds /v1. Use it to point at a local copy of the API such as http://localhost:8090.
const cirrus = new Cirrus({
apiKey: process.env.CIRRUS_API_KEY!,
baseUrl: "http://localhost:8090", // the host only; the library adds /v1
timeoutMs: 10_000, // per attempt, default 30000
maxRetries: 4, // default 2; 0 turns retries off
});What each library can do#
| Operation | JavaScript | Python | PHP | Go | Endpoint |
|---|---|---|---|---|---|
| Send | emails.send | emails.send | emails->send | Emails.Send | POST /v1/emails |
| Send a batch | emails.sendBatch | emails.send_batch | emails->sendBatch | Emails.SendBatch | POST /v1/emails/batch |
| Get an email | emails.get | emails.get | emails->get | Emails.Get | GET /v1/emails/{id} |
| List events | events.list | events.list | events->list | Events.List | GET /v1/events |
| Every event | events.iterate | events.iter | events->iterate | Events.Iter | pages for you |
| Usage | usage.get | usage.get | usage->get | Usage.Get | GET /v1/usage |
| Register a domain | domains.create | domains.create | domains->create | Domains.Create | POST /v1/domains |
| Get a domain | domains.get | domains.get | domains->get | Domains.Get | GET /v1/domains/{id} |
| DNS records | domains.dns | domains.dns | domains->dns | Domains.DNS | GET /v1/domains/{id}/dns |
| Register a webhook | webhooks.create | webhooks.create | webhooks->create | Webhooks.Create | POST /v1/webhooks |
| Verify a webhook | verifyWebhook | verify_webhook | WebhookSignature::verify | VerifyWebhook | no request |
The API has no calls to list domains or webhooks, so the libraries have none either. All four also have a call that signs a payload, for testing your receiver.
What they do for you#
- Idempotency. Sends always carry an
Idempotency-Key: yours or a random one, reused on every retry. See Idempotency and retries. - Retries. Up to two repeats by default, with exponential backoff and jitter, on 429, and on 5xx and network failures for reads and sends. Registering a domain or a webhook is not repeated after a server error or a lost connection, because the API cannot de-duplicate it.
- Errors. A class or type for each status, with the code, message, request ID, field details and retry wait. See Errors.
- Pagination. An iterator that follows the cursor for you. See Pagination.
- Webhook verification. One call that checks the signature in constant time and the five-minute window. See Webhooks and signatures.
- Safety. The key is held privately and never appears in an error message, a printed client or a dump. Redirects are not followed.
Known gaps#
- The JavaScript and Go request types do not have
template_idandtemplate_datayet. See Send a template. - None of the four
Usagemodels has thecredit_balancefield yet. Call the API directly if you need it. - Responses are read with the API's own snake_case names in JavaScript; Python, PHP and Go use their own naming (
dns_records,dnsRecords,DNSRecords).
Another language? The API is plain JSON over HTTPS: see the API reference.