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
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
from wred import App
app = App()
@app.route('/')
async def hello(request):
return {'hello': 'world'}weft app:appLeave that process running. In a second 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
| Install | What it adds |
|---|---|
python -m pip install wred | Wred and orjson. Bring an ASGI server yourself. |
python -m pip install "wred[server]" | Wred, orjson, and the Weft server. |
python -m pip install starlette | The optional middleware, routing, and response classes used in several chapters. |
python -m pip install itsdangerous | Needed for the Starlette signed-cookie session example. |
python -m pip install pymongo servestatic | The 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:
python -m pip install wred uvicorn
uvicorn app:app --host 127.0.0.1 --port 8000 --lifespan offThe 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
git clone https://gitman.io/git/patx/wred
cd wred
python -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[server]' pymongo servestaticEditable 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
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.
