# estimate

> What something would cost a month before you make it: an app, its database and bucket, a repo, live editing.

Each charge comes back on its own line with the unit it's billed by, the unit price NoClick charges for it (what
the service costs NoClick, nothing added), the quantity a month and the dollars, priced for your account's plan.
Leave usage out and a modest default is assumed, and the line says so. Nothing is made or charged by asking.

```python
est = noclick.estimate([
    {"kind": "project", "runtime": "edge", "usage": {"requests": 100_000}},
    {"kind": "database", "engine": "sqlite"},
    {"kind": "bucket"},
])
print(f"${est.monthly_usd:.2f} a month")
```

## noclick.estimate

```python
noclick.estimate(items, *, user=..., client=None) -> Estimate
```

What `items` would cost a month, before you make any of them. Each item is a dict naming its `kind`
(`project`, `durable_objects`, `database`, `bucket`, `repo` or `live_editing`), its options (a
project's `runtime`, `region` and `framework`, a database's `engine`), an optional `name` of your own,
and the `usage` you expect a month by name (`noclick.Estimate.kinds()` lists each kind's). Usage you leave
out is assumed from the kind's defaults, and so is an option you leave out whose default changes a price (an
edge app's `framework` picks its build machine); every line a default decided says so (`assumed`). Prices
are what each service costs NoClick, nothing added, priced for your account's plan. Needs the `usage` scope;
nothing is made, held or charged.

Parameters:

- `items` (`Sequence[Mapping[str, Any]]`, required)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `Estimate` An `Estimate`: `monthly_usd`, every charge in `lines` (its `unit`, `unit_usd`, `quantity` and
`usd`), the `items` each with its own total, and your `plan` with the usage it includes a month.
A kind, option or usage it can't price raises `noclick.InvalidRequest` naming the field.

Usage:

A small site on the edge with a SQLite database and a bucket, at 100,000 requests a month:

```python
est = noclick.estimate([
    {"kind": "project", "runtime": "edge", "usage": {"requests": 100_000}},
    {"kind": "database", "engine": "sqlite"},
    {"kind": "bucket"},
])
print(f"${est.monthly_usd:.2f} a month")
for line in est.lines:
    note = " (assumed)" if line.assumed else ""
    print(f"{line.kind} {line.charge}: {line.quantity:g} {line.unit} x ${line.unit_usd:g} = "
          f"${line.usd:.4f}{note}")
```

A Postgres database awake 200 hours a month, at its smallest size:

```python
est = noclick.estimate([{"kind": "database", "engine": "postgres",
                         "usage": {"active_hours": 200, "compute_units": 0.25, "storage_gb": 2}}])
```

## noclick.Estimate

```python
class Estimate
```

What the items would cost a month: a usage-based estimate, priced for your account's plan.

| Attribute | Type | Description |
| --- | --- | --- |
| `monthly_usd` | `float` |  |
| `estimated` | `bool` | Always true: these charges are by usage, so what's charged is what's used. |
| `items` | `list[EstimateItem]` |  |
| `lines` | `list[EstimateLine]` | Every item's lines, in order. |
| `plan` | `dict[str, Any] | None` | Your account's plan, as `GET /v1/status` names it (None for a key acting for one of your users). |
| `included_usd_per_month` | `float | None` | The usage the plan includes a month, in dollars, which every charge to the account draws from (None without a plan). `plan` says whether a day's share of it is capped too. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

### Estimate.kinds

```python
noclick.Estimate.kinds(*, region=None, user=..., client=None) -> list[EstimateKind]
```

What `noclick.estimate` takes: each kind and variant, the usage it's priced by with the default assumed
for any you leave out, and each charge's unit price. A container app's prices depend on its `region`
(default: where a new app of yours would go). Needs the `usage` scope.

Parameters:

- `region` (`str | None`, default `None`)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `list[EstimateKind]` Each `EstimateKind`: its `kind` and `options` (a project's `runtime`, a database's `engine`),
its `usage` fields with their defaults, and its `prices`.

Usage:

```python
for kind in noclick.Estimate.kinds():
    print(kind.kind, kind.options, [(u.name, u.default) for u in kind.usage])
    for price in kind.prices:
        print(f"  {price.charge}: ${price.unit_usd} per {price.unit}")
```

## noclick.EstimateItem

```python
class EstimateItem
```

One thing you asked about, priced: its options, the usage it was priced at, and its lines.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `str` |  |
| `label` | `str` | For people, e.g. `App on the edge`. |
| `name` | `str | None` |  |
| `options` | `dict[str, Any]` | What it was priced as: a project's `runtime`, `region` and `framework`, a database's `engine`. |
| `usage` | `dict[str, float]` | Every usage it was priced at, by name: what you gave and the defaults for the rest. |
| `assumed` | `list[str]` | The usage names you left out, and the options you left out whose default changes a price. |
| `monthly_usd` | `float` |  |
| `lines` | `list[EstimateLine]` |  |
| `not_included` | `list[str]` | What its meters also charge that no usage here prices (an app's calls to AI, say), in words. |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.EstimateLine

```python
class EstimateLine
```

One charge of an estimate: what is billed, by which unit, at what price, and how much of it a month.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `str` | The kind of the item it's for: `project`, `durable_objects`, `database`, `bucket`, `repo` or `live_editing`. |
| `item` | `str | None` | The `name` you gave the item, if any. |
| `charge` | `str` | Which charge it is, e.g. `front_door`, `rows_written` or `storage`. |
| `description` | `str` | What it charges for, in words. |
| `unit` | `str` | The unit it's billed by, e.g. `million requests` or `GB-month`. |
| `unit_usd` | `float` | The price of one `unit`, in US dollars. |
| `quantity` | `float` | How many units a month. |
| `usd` | `float` | What it would cost your account a month, in US dollars. |
| `assumed` | `bool` | Whether a default decided it: its `quantity` came from usage you left out, or its price from an option you left out (an edge app's `framework`, a container's `region`). |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.EstimateKind

```python
class EstimateKind
```

Something an estimate takes: the usage it's priced by and the charges it makes.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `str` | What `kind` an item names; a project and a database come in variants (`options`). |
| `label` | `str` |  |
| `description` | `str` |  |
| `options` | `dict[str, Any]` | What this variant is priced as: a project's `runtime` and `region`, a database's `engine`. |
| `usage` | `list[EstimateUsageField]` |  |
| `prices` | `list[EstimatePrice]` |  |
| `not_included` | `list[str]` |  |
| `raw` | `dict[str, Any]` | The response JSON exactly as the API sent it. |

## noclick.EstimateUsageField

```python
class EstimateUsageField
```

A usage a kind takes: what it counts, and the default assumed when you leave it out.

| Attribute | Type | Description |
| --- | --- | --- |
| `name` | `str` |  |
| `unit` | `str` |  |
| `description` | `str` |  |
| `default` | `float` |  |
| `most` | `float | None` | The most it can be (a share is at most 1), else None. |

## noclick.EstimatePrice

```python
class EstimatePrice
```

A charge a kind makes, at its unit price.

| Attribute | Type | Description |
| --- | --- | --- |
| `charge` | `str` |  |
| `description` | `str` |  |
| `unit` | `str` |  |
| `unit_usd` | `float` |  |
| `usage_fields` | `list[str]` | The usage names its quantity comes from. |
