Skip to content

Runnable examples

The repository ships three examples that progress across the current public surface. Clone the repository and prepare its development environment:

Terminal window
git clone https://github.com/tugrulguner/dexpot.git
cd dexpot
uv sync --all-extras

examples/minimal.py demonstrates a typed integer path capture and msgspec response.

Terminal window
uv run python examples/minimal.py
curl -s http://127.0.0.1:8000/items/7
{"id":7,"name":"item-7","price":7.0}

examples/typed_crud.py demonstrates typed JSON bodies, compiled response encoders, status/payload returns, and thread-safe shared application state.

Terminal window
uv run python examples/typed_crud.py
curl -s -X POST http://127.0.0.1:8000/items \
-H 'Content-Type: application/json' \
-d '{"name":"keyboard","price":79.0}'

The lock in this example belongs to the application. It protects the mutable dictionary when handlers execute concurrently.

The browser-local playground below computes request/response examples from bounded inputs and session-only state. It follows the example’s starter item and response statuses/bodies; it is not a Python runtime or benchmark.

BROWSER-LOCAL CONTRACT NO SERVER REQUESTS

Use the actual typed CRUD example as a guide, then run a bounded request locally.

examples/typed_crud.py · create_itemPYTHON · SYNC
@app.post("/items", body=ItemIn, response=Item)
def create_item(item: ItemIn) -> tuple[int, Item]:
    global _next_id
    with _lock:
        created = Item(id=_next_id, name=item.name, price=item.price)
        _items[_next_id] = created
        _next_id += 1
    return 201, created
Open complete example ↗
REQUEST BUILDERPOST /items

— Browser-local processing only. Excludes Dexpot Python/server and network latency.

Local contract preview, not a Python server. No network calls. Starts with the example item; maximum 20 live items. Editing clears the last result. Only Run executes. State changes persist if result presentation fails; use an explicit follow-up operation (such as GET) to inspect state—there is no automatic rollback.

Request

Awaiting run()

Computed response

No response yet.

examples/bounded_api.py customizes HttpLimits and exercises 413, 422, and 405 responses plus typed Request injection.

Terminal window
uv run python examples/bounded_api.py
curl -s http://127.0.0.1:8000/health
curl -s http://127.0.0.1:8000/context

The test suite launches every example as a subprocess and validates its public HTTP behavior. Set DEXPOT_EXAMPLE_PORT when port 8000 is occupied.

Read the complete examples guide and source files in the repository.