Metadata-Version: 2.4
Name: levelops
Version: 0.1.0
Summary: LevelOps Python SDK — SLI event ingestion
Project-URL: Homepage, https://levelops.io
Project-URL: Repository, https://github.com/levelops/sdk-python
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28

# LevelOps Python SDK

Ingest SLI events into LevelOps from any Python application.

## Installation

```bash
pip install levelops
```

## Quickstart

```python
from levelops import LevelOpsClient

client = LevelOpsClient(api_key="<tenant_key>", sli_id="<uuid>")
client.record(fields={"result": "ok", "latency_ms": 120})
client.flush()
```

## Usage

### Direct record

```python
# Auto-generated event_id (UUID v4)
client.record(
    fields={"result": "ok", "latency_ms": 120},
    dimensions={"service": "api", "region": "eu"},
)

# Explicit event_id for idempotent retries
client.record(fields={"result": "ok"}, event_id="my-trace-id")
```

### Context manager (auto latency measurement)

```python
# event_id auto-generated
with client.measure(dimensions={"service": "api"}) as ctx:
    # ... business logic ...
    ctx.set_result("ok")  # or "error"

# Explicit event_id
with client.measure(dimensions={"service": "api"}, event_id="trace-id") as ctx:
    ctx.set_result("ok")
```

## Configuration

| Parameter | Default | Description |
|---|---|---|
| `api_key` | — | Tenant API key (required) |
| `sli_id` | — | Target SLI UUID (required) |
| `base_url` | `https://api.levelops.io` | API base URL |
| `batch_size` | `100` | Flush after N events |
| `flush_interval` | `1.0` | Flush every N seconds |

## Behaviour

- `event_id` auto-generated (UUID v4) per `record()` and per `measure()` exit. Override via `event_id=` parameter for idempotent retries.
- `timestamp` auto-set to UTC now if not provided.
- Thread-safe internal buffer flushed in background thread.
- Retries on HTTP 429 respecting `Retry-After` header (max 3 attempts, exponential backoff).
- `flush()` registered via `atexit` automatically.

