OpenArtifacts

openartifacts.sh / templates / api-sqlite

JSON API on SQLite

Python 3.11, standard library · size small · 3 files, 17.4 kB

A small JSON CRUD API over one items table, in Python with nothing but the standard library, so there is no install step and it boots in about a second. Each item has a name, a free-form data object and timestamps. The data survives sleeps, restarts and redeploys.

Deploy it

One call publishes it as-is and boots it. It needs no environment variables. Files you send with the call replace the template's files of the same name, and fields you send override its oa.json. It is billed like any service.

With curl

# once: an account and its token
curl -sX POST "https://openartifacts.sh/v1/signup?ref=templates"
# the template, published and booted
curl -sX POST https://openartifacts.sh/v1/publish \
  -H "Authorization: Bearer $OA_TOKEN" \
  -F type=service -F template=api-sqlite -F slug=my-api

From an MCP client

publish_artifact {"type": "service", "template": "api-sqlite",
                  "slug": "my-api"}

With the CLI

npx @openartifacts/cli signup --ref templates   # once
npx @openartifacts/cli deploy --template api-sqlite --slug my-api
# or edit first: the files, here, then a normal deploy
npx @openartifacts/cli init api-sqlite
npx @openartifacts/cli deploy ./api-sqlite --slug my-api

Then: Create an item: curl -X POST <url>/items -H 'content-type: application/json' -d '{"name":"first"}', then curl <url>/items. Set API_KEY (oa env set my-api API_KEY=...) to protect writes.

Call it

curl -s -X POST <url>/items -H 'content-type: application/json' \
  -d '{"name":"first","data":{"color":"blue"}}'          # 201 {"id":1,...}
curl -s <url>/items                                       # newest first; ?limit=50&offset=0&q=fir
curl -s <url>/items/1
curl -s -X PATCH <url>/items/1 -H 'content-type: application/json' -d '{"data":{"color":"red"}}'
curl -s -X DELETE <url>/items/1                           # 204
curl -s <url>/                                            # counts, routes, where the data is

Errors are JSON {"code": "...", "message": "..."} with a 4xx status.

Environment

VariableRequiredWhat it does
API_KEYnoWhen set, POST, PATCH, PUT and DELETE need Authorization: Bearer <API_KEY>. Reads stay public; protect them in require_key() if they should not be.

Set it with oa env set <slug> API_KEY=... or PUT /v1/artifacts/<slug>/env {"env":{"API_KEY":"..."}}.

Where the data lives, and how durable it is

/data is object storage mounted as a directory: it keeps whole files, but a database file opened directly on it would be slow and could be corrupted by a container stopped mid-write. So the live database is on the container's local disk (~/api.sqlite), and /data holds snapshots of it:

What that means: a hard crash can lose the writes of the last 2 seconds (FLUSH_AFTER_S), and only one process may write, which is this one. It suits a small app's data, up to tens of megabytes; each snapshot rewrites the whole file, and /data is capped at 1 GB. It is not a database server.

Extend it

What it costs

Prices for small, the size this template needs (current prices on openartifacts.sh):

Starting it needs an hour of awake time in credit ($0.03), and an account runs one service per $1 of balance.

Files

Every file, as JSON you can edit and publish: GET /v1/templates/api-sqlite.


← all templates · openartifacts.sh · docs.md · skill.md