Each experiment should be runnable as a single file, which allows convenient debugging from within vscode:
python experiments/FILENAME.py
When making frequent changes to the file and you want to immediately see the changes, you can run:
uvicorn experiments.FILENAME:app --reload
Create a virtual environment, activate, then:
pip install -r requirements.txt -e .Use pip-tools (pip install pip-tools)
pip-compile --quiet --upgrade to upgrade lock file
App:
importuvicornfromfastapiimportFastAPIapp=FastAPI()
# experiment path operators here@app.get("/hello")asyncdefhello():
return"hello"if__name__=="__main__":
uvicorn.run(app, host="localhost", port=8000)Test file:
fromfastapi.testclientimportTestClientfromexperiments.FILENAMEimportappclient=TestClient(app)
# TEST path operators heredeftest_hello():
resp=client.get("/hello")
assertresp.status_code==200assertresp.json() =="hello"To install and ensure it's working, run:
pre-commit install
pre-commit run --all-files