Settings and files

3 entries

Markdown

m.setting

Read a small value the machine saved.

Signature
m.setting(key, default=None)
Example · Inside a job
runs = m.setting("runs", default=0)

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

Needs in machine.yaml
Nothing
Returns
What was saved under key, or default.

m.save_setting

Save a small value.

Signature
m.save_setting(key, value)
Example · Inside a job
m.save_setting("runs", int(m.setting("runs", default=0) or 0) + 1)

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

m.data_dir

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

Signature
m.data_dir()
Example · Inside a job
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()

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.