Skip to content
CirrusDocs

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.

The client libraries
LanguagePackageNeeds
JavaScript and TypeScript@cirrus-mail/cirrusNode 18 or newer; no dependencies; ships its own types
Pythoncirrus-mail (import cirrus)Python 3.9 or newer; standard library only
PHPcirrus-mail/cirrus-phpPHP 8.1 or newer, with ext-curl and ext-json
Gogithub.com/cirrus-mail/cirrus-goGo 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 1

Options#

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#

Calls and the endpoints behind them
OperationJavaScriptPythonPHPGoEndpoint
Sendemails.sendemails.sendemails->sendEmails.SendPOST /v1/emails
Send a batchemails.sendBatchemails.send_batchemails->sendBatchEmails.SendBatchPOST /v1/emails/batch
Get an emailemails.getemails.getemails->getEmails.GetGET /v1/emails/{id}
List eventsevents.listevents.listevents->listEvents.ListGET /v1/events
Every eventevents.iterateevents.iterevents->iterateEvents.Iterpages for you
Usageusage.getusage.getusage->getUsage.GetGET /v1/usage
Register a domaindomains.createdomains.createdomains->createDomains.CreatePOST /v1/domains
Get a domaindomains.getdomains.getdomains->getDomains.GetGET /v1/domains/{id}
DNS recordsdomains.dnsdomains.dnsdomains->dnsDomains.DNSGET /v1/domains/{id}/dns
Register a webhookwebhooks.createwebhooks.createwebhooks->createWebhooks.CreatePOST /v1/webhooks
Verify a webhookverifyWebhookverify_webhookWebhookSignature::verifyVerifyWebhookno 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_id and template_data yet. See Send a template.
  • None of the four Usage models has the credit_balance field 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.