> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.nozle.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Margin Queries

> Query margin intelligence data with the Python SDK

The margin client is available as `nozle.margin`. All methods accept optional query params such as `from` and `to` date strings.

Python reserves `from` as a keyword, so pass date filters with dictionary expansion when you need the exact query parameter name:

```python theme={null}
summary = nozle.margin.summary(**{"from": "2024-01-01", "to": "2024-01-31"})
```

## Summary

```python theme={null}
summary = nozle.margin.summary()
```

## By Customer

```python theme={null}
by_customer = nozle.margin.by_customer(**{"from": "2024-01-01", "to": "2024-01-31"})
```

## By Metric

```python theme={null}
by_metric = nozle.margin.by_metric()
```

## By Plan

```python theme={null}
by_plan = nozle.margin.by_plan()
```

## By Model

```python theme={null}
by_model = nozle.margin.by_model()
```

## Trend

```python theme={null}
trend = nozle.margin.trend(
    granularity="day",  # "hour" | "day" | "week" | "month"
    **{"from": "2024-01-01", "to": "2024-01-31"},
)
```

## Parameters

**Margin query params:**

* `from` (string, optional) -- Start date (ISO 8601)
* `to` (string, optional) -- End date (ISO 8601)

**trend() only:**

* `granularity` (`"hour"` | `"day"` | `"week"` | `"month"`, default: `"day"`)

<Info>
  All margin endpoints require a secret key (`sk_`). These are the same endpoints exposed at `GET /api/v1/margin/*` on the Nozle API.
</Info>
