The server needs to connect to a running database. The environment variable DATABASE_URL can be used to specify how the server should connect to the database. This Documentation explains how it is constructed.
A local development database using Docker can be created by placing a sql dump of the production database in the root folder of this project and calling it pad-2.sql. With that, you can run docker-compose up -d db which starts a mysql/mariadb database with the username root and password P@ssw0rd. To use this database with the app you can set the environment varible as such export DATABASE_URL=mysql+pymysql://root:P%40ssw0rd@127.0.0.1/paper-analytical-devices. Note that the @ of the password has changed to %40 in the export statement. The DATABASE_URL is required to be URL encoded.
# Initialize empty python virtual environment
python3 -m venv .venv The latest macOS defaults to python 3.9 for it's system python. By using homebrew we can install python 3.10 and use it for the virtual environment with the following commands:
brew install python@3.10
$(brew --prefix)/opt/python@3.10/libexec/bin/python3 -m venv .venvThe following commands activate a python virtual environment and install the package and its dependencies.
# Activate virtual environment
source .venv/bin/activate
# Install project requirements
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Install project as editable requirement
pip install -e . The following will activate the virtual environment and start a local development server which will watch for changes and reload itself.
# Activate virtual environment
source .venv/bin/activate
# Run server
python -m uvicorn server.main:app --reloadThe following commands use PDM to automate the management of the environment.
# Install project requirements
pdm sync
# Run server
pdm run server