Examples
web-backend
A FastAPI service over SQLite with one route, called once through its test client, and its recording.
A small FastAPI service over a SQLite database of customers, products and orders, with one route: GET /customers/{customer_id}/orders, the customer's orders each with its total (?names=1 adds the product names). A gold customer gets 10 percent off, a silver one 5. main.py builds orders.db and asks for the orders of customer 3 through fastapi.testclient. Files: store.py (schema, seed data, connect()), app.py (the app and its route), main.py (one request).
- Source:
ormaos-examples/use-cases/web-backend - Guide: Web backend
Run it#
python main.py$ python main.py
GET /customers/3/orders -> 200, 12 orders
/tmp/ormaos-docs-generate/venv/lib/python3.14/site-packages/fastapi/testclient.py:1: StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
from starlette.testclient import TestClient as TestClient # noqaRecorded#
ormaos run -- python main.py$ ormaos run -- python main.py
GET /customers/3/orders -> 200, 12 orders
/tmp/ormaos-docs-generate/venv/lib/python3.14/site-packages/fastapi/testclient.py:1: StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
from starlette.testclient import TestClient as TestClient # noqa
ormaos: r1 exit 0 in …: 1 Python process, 72 calls, 1 exception (1 swallowed), 111 io
ormaos: swallowed 1x KeyError at app.py:30, raised at app.py:29 [r1:e1]
ormaos: not collected: io: directory and file-system operations, at store.py:27 (once): a directory was listed, or a file or directory was made, renamed, changed or removed there; these are not recorded (+2 more)
ormaos: saved in .ormaos/r1, next: ormaos exceptions r1:e1 | ormaos tree r1:c1$ ormaos show
r1 exit 0 in …: 1 Python process, 72 calls, 1 exception (1 swallowed, 0 uncaught)
command: python main.py
code: git commit not read (the working directory is not inside a git repository)
swallowed 1x KeyError at app.py:30 in discount_for, raised at app.py:29 [r1:e1]
io: 111 events (sqlite 110, http 1)
io: 38x sqlite "INSERT INTO order_items VALUES (?, ?, ?)" from store.py:41 [r1:i10]
io: 24x sqlite "SELECT cents FROM products WHERE id = ?" from app.py:41 [r1:i53]
io: 19x sqlite "INSERT INTO orders VALUES (?, ?, ?)" from store.py:36 [r1:i9]
io: 12x sqlite "SELECT product_id, quantity FROM order_items WHERE order_id = ?" from app.py:35 [r1:i52]
io: 4x sqlite "INSERT INTO products VALUES (?, ?, ?)" from store.py:31 [r1:i8]
... 1 more lines of code repeated io: ormaos io r1
logs: 1 logging record (INFO 1), 1 dropped by the level
not collected: io: directory and file-system operations, at store.py:27 (once): a directory was listed, or a file or directory was made, renamed, changed or removed there; these are not recorded
not collected: io with no line of user code (3 events: 3 file): no frame of user code was waiting for them, so they are not recorded
not collected: logs with no line of user code: 1 logging records were asked for with no frame of user code waiting (library threads, the end of the interpreter): they are counted here and not recorded; the first loggers: asyncio
never recorded: values, and 20 more kinds of things (`ormaos show --full` lists them with the reason)
next: ormaos exceptions r1:e1 | ormaos tree r1:c1 | ormaos io r1 | ormaos io r1:i10 | ormaos logs r1