Skip to content

Quick start

import { Aside, Steps } from ‘@astrojs/starlight/components’;

  1. Install the framework and CLI

    Terminal window
    pip install "dexpot[cli]"
  2. Define an application

    Save this as main.py:

    import msgspec
    from dexpot import Dex
    class ItemIn(msgspec.Struct):
    name: str
    price: float
    class ItemOut(msgspec.Struct):
    id: int
    name: str
    price: float
    app = Dex()
    @app.get("/items/{item_id}", response=ItemOut)
    def get_item(item_id: int) -> ItemOut:
    return ItemOut(id=item_id, name=f"item-{item_id}", price=9.99)
    @app.post("/items", body=ItemIn, response=ItemOut)
    def create_item(item: ItemIn) -> tuple[int, ItemOut]:
    return 201, ItemOut(id=1, name=item.name, price=item.price)
  3. Serve it

    Terminal window
    dexpot serve main:app --host 127.0.0.1 --port 8000
  4. Call the real HTTP surface

    Terminal window
    curl -s http://127.0.0.1:8000/items/7
    curl -s -X POST http://127.0.0.1:8000/items \
    -H 'Content-Type: application/json' \
    -d '{"name":"keyboard","price":79.0}'

    The responses are JSON:

    {"id":7,"name":"item-7","price":9.99}
    {"id":1,"name":"keyboard","price":79.0}

You can also run the file directly:

if __name__ == "__main__":
app.serve(host="127.0.0.1", port=8000)

Continue with the route contract or see the runnable examples.