Metadata-Version: 2.4
Name: drin
Version: 0.1.0
Summary: Official Python SDK for the Drin transactional email API.
Author: Drin
License: MIT License
        
        Copyright (c) 2026 Drin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://drin.run
Project-URL: Documentation, https://docs.drin.run
Project-URL: Repository, https://github.com/ATOM00blue/drin
Project-URL: Issues, https://github.com/ATOM00blue/drin/issues
Keywords: drin,email,transactional-email,email-api,smtp,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# drin

Official **Python** SDK for the [Drin](https://drin.run) transactional email
API. Zero dependencies (standard library only), typed, Python 3.8+.

## Install

```sh
pip install drin
```

## Quick start

```python
from drin import DrinClient

drin = DrinClient(api_key="drin_...")  # or os.environ["DRIN_API_KEY"]

res = drin.emails.send({
    "from": {"email": "you@send.drin.run", "name": "Acme"},
    "to": [{"email": "user@example.com"}],
    "subject": "Welcome",
    "html": "<h1>Welcome</h1>",
    "text": "Welcome",
})
print(res["id"], res["status"])
```

The client defaults to `https://api.drin.run`; override with `base_url`.
Request bodies are plain dicts whose keys match the REST API; responses are
parsed JSON.

### Tenant-wide keys

A tenant-wide key must name the sender (its `externalId`):

```python
drin = DrinClient(api_key, sender="customer_42")
# or per request:
drin.emails.send(body, sender="customer_42")
```

### Idempotency

```python
drin.emails.send(body, idempotency_key="order-1234")  # honored 24h, per sender
```

### Pagination

Every list endpoint returns `{"data": [...], "nextCursor": ...}`. Use
`paginate(...)` to walk every page lazily:

```python
for message in drin.emails.paginate({"status": "delivered"}):
    print(message["id"])
```

### Typed errors

```python
from drin import DrinRateLimitError, DrinSuppressedError, DrinError

try:
    drin.emails.send(body)
except DrinRateLimitError as e:
    time.sleep(e.retry_after or 1)
except DrinSuppressedError:
    ...  # all recipients suppressed
except DrinError as e:
    print(e.type, e.status, e.code)
```

### Webhook verification

Verify the `Drin-Signature` header on inbound webhooks. Pass the **raw** request
body. Pure local check — no network call.

```python
from drin import verify_webhook, DrinWebhookVerificationError

# e.g. in a Flask/Django/FastAPI handler:
raw_body = request.get_data(as_text=True)        # the exact bytes received
signature = request.headers["Drin-Signature"]

try:
    result = verify_webhook(raw_body, signature, signing_secret, tolerance_seconds=300)
    event = result.payload  # trusted only AFTER verification
except DrinWebhookVerificationError:
    abort(400)
```

## Resources

`drin.emails` · `drin.domains` · `drin.inboxes` · `drin.threads` ·
`drin.inbound` · `drin.webhooks` · `drin.suppressions` · `drin.api_keys` ·
`drin.metrics` · `drin.templates` · `drin.contacts` · `drin.forms` — one method
per `/v1` endpoint.

A first-party TypeScript SDK is also available: `npm install @drin/sdk`.

## License

MIT
