- Code: https://github.com/SamEdwardes/demo-fastapi-penguins
- Deployment: https://colorado.rstudio.com/rsc/demo-fastapi-penguins/docs
Create a virtual environment.
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip wheel
pip install -r app/requirements.txt
Then run the app.
uvicorn app.main:app --reload
You could also call the API using curl
:
curl -X 'GET' \
'https://colorado.rstudio.com/rsc/demo-fastapi-penguins/penguins?sample_size=1' \
-H 'accept: application/json'
If the API is private you will need to authenticate using your API key.
curl -X 'GET' \
'https://colorado.rstudio.com/rsc/demo-fastapi-penguins/penguins?sample_size=1' \
-H 'accept: application/json' \
-H "Authorization: Key ${CONNECT_API_KEY}"
The app is automatically deployed to RStudio connect using git backed deployment. Make any changes to the code, then run the following:
rsconnect write-manifest fastapi \
--overwrite \
--python .venv/bin/python \
--entrypoint main:app \
app
⚠️ Remember to update the app/requirements.txt file if you add any new packages.
You can deploy the app using the rsconnect cli:
rsconnect deploy fastapi \
--python .venv/bin/python \
--entrypoint main:app \
--new \
app