Metadata-Version: 2.4
Name: sealedwebtoken
Version: 1.0.0
Summary: Official Python SDK for Odysii Sealed Web Tokens (SWT)
Project-URL: Homepage, https://swt.odysii.in
Project-URL: Repository, https://github.com/snskar125/swt
Author: snskar125
License: ISC
Keywords: authentication,jwt,sealed-web-tokens,swt,tokens
Classifier: License :: OSI Approved :: ISC License (ISCL)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Security
Requires-Python: >=3.9
Provides-Extra: async
Requires-Dist: aiohttp>=3.9; extra == 'async'
Description-Content-Type: text/markdown

# sealedwebtoken

The official Python SDK for Odysii Sealed Web Tokens (SWT).

## Installation

```bash
# Sync client only (zero dependencies)
pip install sealedwebtoken

# With async support (installs aiohttp)
pip install sealedwebtoken[async]
```

## Usage

### Sync

```python
import time
import swt

secret = "your-super-secret-key"
payload = {"user_id": 123, "role": "admin"}

# 1. Sign a token (expiresAt is required, max 31 days)
expires_at = int(time.time()) + 3600  # 1 hour from now
resp = swt.sign(payload, secret=secret, expires_at=expires_at)
print("Token:", resp.token)
print("Expires at:", resp.expires_at)

# 2. Verify a token
v = swt.verify(resp.token, secret=secret)
if v.valid:
    print("Payload:", v.payload)

# 3. Revoke a token
swt.revoke(resp.token, secret=secret)
print("Token revoked")
```

### Async

```python
import asyncio, time
import swt

async def main():
    client = swt.AsyncSWTClient()
    expires_at = int(time.time()) + 3600

    resp = await client.sign({"user_id": 42}, secret="mysecret123", expires_at=expires_at)
    print("Token:", resp.token)

    v = await client.verify(resp.token, secret="mysecret123")
    if v.valid:
        print("Payload:", v.payload)

    await client.revoke(resp.token, secret="mysecret123")
    print("Token revoked")

asyncio.run(main())
```

### Using the class-based client

```python
import swt

# Create a reusable client
client = swt.SWTClient()
resp = client.sign({"user_id": 1}, secret="mysecret123", expires_at=...)
```

## API Reference

### `swt.sign(payload, *, secret, expires_at) → SignResponse`

- `payload` — `dict` to embed in the token (max 512 bytes serialised)
- `secret` — string, min 8 characters
- `expires_at` — Unix timestamp in seconds, **required**, max 31 days from now

### `swt.verify(token, *, secret=None) → VerifyResponse`

- `token` — the SWT token string
- `secret` — optional; if provided, validates the secret matches

### `swt.revoke(token, *, secret) → RevokeResponse`

- `token` — the SWT token string to revoke
- `secret` — the secret used when signing
