diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index fbe0e20..82d5a32 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -12,6 +12,20 @@ $ProjectFileDir$ + postgresql + true + Kube Eng :: PostgreSQL + org.postgresql.Driver + jdbc:postgresql://localhost:5432/postgres + + + + + + + $ProjectFileDir$ + + postgresql true Kube Eng :: PostgreSQL diff --git a/.idea/misc.xml b/.idea/misc.xml index aaa3def..be83902 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/mrmat-python-api-fastapi.iml b/.idea/mrmat-python-api-fastapi.iml index 674ba84..24ec1fd 100644 --- a/.idea/mrmat-python-api-fastapi.iml +++ b/.idea/mrmat-python-api-fastapi.iml @@ -7,7 +7,7 @@ - + diff --git a/README.md b/README.md index 99e2157..79ee8df 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,56 @@ [![Build](https://github.com/MrMatOrg/mrmat-python-api-fastapi/actions/workflows/build.yml/badge.svg)](https://github.com/MrMatOrg/mrmat-python-api-fastapi/actions/workflows/build.yml) +Boilerplate (and playground) for a code-first Python FastAPI API. -Boilerplate (and playground) for a code-first Python FastAPI API, with all the bells and whistles we've come to expect. +## How to build this +Create a virtual environment, then: + +```shell +(venv) $ pip install -r requirements.txt +(venv) $ python python -m build -n --wheel +``` + +If you intend to run the testsuite or work on the code, then also install the requirements from `requirements.dev.txt`. You can run the testsuite using + +```shell +(venv) $ PYTHONPATH=src pytest tests +``` + +The resulting wheel is installable and knows its runtime dependencies. Any locally produced wheel will have version 0.0.0.dev0. This is intentional to distinguish local versions from those that are produced as releases in GitHub. You can override this behaviour by setting the `MRMAT_VERSION` environment variable to the desired version. + +You can produce a container image and associated Helm chart using the provided Makefile: + +```shell +$ make container + +# Optionally install the produced container image in the current Kubernetes context +$ make helm-install +``` + +## How to run this + +To run a local development instance straight from the code: + +```shell +$ fastapi dev src/mrmat_python_api_fastapi/app.py +``` + +To run from an installed wheel: + +```shell +$ uvicorn --host 0.0.0.0 --port 8000 mrmat_python_api_fastapi.app:app +``` + +Or you can just start the container image or Helm chart. Both are declared in `var/container` and `var/helm` respectively and used by the top-level Makefile. + +## How to configure this + +When you do not explicitly configure anything the app will use an ephemeral in-memory SQLite database. You can change this to PostgreSQL by: + +* overriding the `config.db_url` variable of the Helm chart, or +* setting the `APP_CONFIG_DB_URL` environment variable, or +* creating a config file in JSON setting `db_url` + +The app will pick up the config file from the path set in the `APP_CONFIG` environment variable, if it is set. Note that the `APP_CONFIG_DB_URL` environment variable overrides the setting in the configuration file. diff --git a/requirements.txt b/requirements.txt index e4b4554..000d248 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # # Runtime requirements -fastapi==0.115.11 # MIT +fastapi[standard]==0.115.11 # MIT sqlalchemy[asyncio]==2.0.40 # MIT uvicorn==0.34.0 # BSD 3-Clause pydantic==2.10.6 # MIT