# Library

Share code between functions with library modules — API clients, validation, business rules and helpers.

The **Library** holds code modules that every function of the same language can import. Write a helper once instead of copying it into every function.

## Use a module

```js JavaScript — lib/pricing.js
export function priceFor(items) {
  return items.reduce((sum, i) => sum + i.price * i.qty, 0);
}
```

```js JavaScript — function
import { priceFor } from './lib/pricing.js';

export async function handler(req) {
  return { status: 200, body: { total: priceFor(req.body.items) } };
}
```

```python Python
# lib/pricing.py
def price_for(items):
    return sum(i["price"] * i["qty"] for i in items)

# function
from lib.pricing import price_for
```

## What belongs in the library

- Clients for third-party APIs, with auth and retries.
- Validation and parsing.
- Business rules — pricing, permissions, formatting.
- Helpers around [storage](/storage).
- Constants shared by several functions.

Modules can import packages, the [Wisp SDK](/api/sdk-config) and each other. A module isn't callable over HTTP and has no handler.

## Changes rebuild every function

Editing a module rebuilds every function of that language in the draft. Test at least one function that uses it before publishing.
