# Settings and files

Part of the [Ownbox SDK reference](https://www.ownbox.io/sdk/reference.md).

## m.setting

```python
m.setting(key, default=None)
```

Read a small value the machine saved.

A choice, a list, a date. Never raises.

**Needs in machine.yaml:** Nothing

**Returns:** What was saved under `key`, or `default`.

Example (inside a job):

```python
runs = m.setting("runs", default=0)
```

## m.save_setting

```python
m.save_setting(key, value)
```

Save a small value.

Up to 64 KB as JSON, and 200 settings in all. A settings field the owner fills on the machine's page is saved here too, under the field's key.

**Needs in machine.yaml:** Nothing

Example (inside a job):

```python
m.save_setting("runs", int(m.setting("runs", default=0) or 0) + 1)
```

## m.data_dir

```python
m.data_dir()
```

The machine's own folder, for anything larger than a setting.

Its SQLite file and its files. The only place it can write that outlives a restart.

**Needs in machine.yaml:** Nothing

**Returns:** A `pathlib.Path`.

Example (inside a job):

```python
import sqlite3

db = sqlite3.connect(m.data_dir() / "quotes.db")
db.execute("CREATE TABLE IF NOT EXISTS quotes (id TEXT PRIMARY KEY, sent_at TEXT)")
db.close()
```

