Browse documentation

Documentation overview

Tutorial

Reference

Project

Installation & quick start

Pick a Python, make a virtualenv, and install the parts you need. Your dependency tree is allowed to have sunlight reaching the bottom.

Requirements

Wred requires Python 3.11 or newer and orjson. It is an ASGI application framework; an ASGI server runs it. The optional server extra installs weft-server, whose executable is weft.

Wred is packaged as a single Python module. There is no project generator, settings module, or Wred CLI. You can spend the time saved choosing a name for your app. That should comfortably consume the afternoon.

Create an isolated environment

Terminal
mkdir hello-wred
cd hello-wred
python -m venv .venv
. .venv/bin/activate
python -m pip install 'wred[server]'

Commands assume a POSIX shell and a python command pointing to Python 3.11+. Use python3 if that is how your system names it. In Windows PowerShell, activate with .venv\Scripts\Activate.ps1.

A virtualenv also avoids modifying an externally managed system Python. See the Python virtualenv guide and pip install reference.

Save an app and run it

app.py
from wred import App

app = App()


@app.route('/')
async def hello(request):
    return {'hello': 'world'}
Terminal
weft app:app

Leave that process running. In a second terminal:

Terminal
curl -sS http://127.0.0.1:8000/
# {"hello":"world"}

app:app means the app object in app.py. Continue with Your first API for routes and validation.

Choose your dependencies

InstallWhat it adds
python -m pip install wredWred and orjson. Bring an ASGI server yourself.
python -m pip install "wred[server]"Wred, orjson, and the Weft server.
python -m pip install starletteThe optional middleware, routing, and response classes used in several chapters.
python -m pip install itsdangerousNeeded for the Starlette signed-cookie session example.
python -m pip install pymongo servestaticThe notebook example’s database client and static-file wrapper.

These examples are separate application choices. Installing Starlette does not transform Wred’s request into a Starlette request, despite the excellent opportunities for confusion.

Use another ASGI server

You can install another ASGI server alongside the base package. For example, with Uvicorn:

Terminal
python -m pip install wred uvicorn
uvicorn app:app --host 127.0.0.1 --port 8000 --lifespan off

The bare Wred app handles HTTP only, so this command disables Uvicorn’s lifespan handling. The notebook wrapper implements lifespan and should run with it enabled. See your server’s own options for workers, reload, TLS, and forwarding.

Work from a checkout

Terminal
git clone https://gitman.io/git/patx/wred
cd wred
python -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[server]' pymongo servestatic

Editable installation points Python at your checkout. The notebook is in example_app/; installing the Wred package alone does not install that application. Follow Run the notebook for MongoDB and startup.

Check what you installed

Terminal
python -m pip show wred
python -c 'import wred; print(wred.__file__)'

The second command helps detect a local wred.py shadowing the installed module. Python imports the file it finds, not the file you had strong feelings about. See release notes and upgrading for the 0.9 server-extra change.