Package: mavedb
mavedb-apiAPI for MaveDB, the database of the database of Multiplexed Assays of Variant EffectUsing mavedb-apiUsing the library as an API client or validator for MaveDB data setsSimply install the package using PIP:pip install mavedbOr addmavedbto your Python project's dependencies.Building and running mavedb-apiPrerequisitesPython 3.9 or laterPIPbuildfor building distributions. This can be installed withpip install build.hatchfor building distributions. This can be installed withpip install hatch.Building distribution packagesTo build the source distribution and wheel, runpython -m buildThe build utility will look atpyproject.tomland invoke Hatchling to build the distributions.The distribution can be uploaded to PyPI usingtwine.For use as a server, this distribution includes an optional set of dependencies, which are only invoked if the package
is installed withpip install mavedb[server].Running the API server in Docker on production and test systemsFirst build the application's Docker image:docker build --tag mavedb-api/mavedb-api .Then start the application and its database:docker-compose -f docker-compose-prod.yml up -dOmit-d(daemon) if you want to run the application in your terminal session, for instance to see startup errors without having
to inspect the Docker container's log.To stop the application when it is running as a daemon, rundocker-compose -f docker-compose-prod.yml downdocker-compose-prod.ymlconfigures two containers: one for the API server and one for the PostgreSQL database. The
The database stores data in a Docker volume namedmavedb-data, which will persist after runningdocker-compose down.NotesThemavedb-apicontainer requires the following environment variables, which are configured indocker-compose-prod.yml:DB_HOSTDB_PORTDB_DATABASE_NAMEDB_USERNAMEDB_PASSWORDNCBI_API_KEYThe database username and password should be edited for production deployments.NCBI_API_KEYwill be removed in
the future.TODOMove these to an .env file.In the procedure given above, we do not push the Docker image to a repository like Docker Hub; we simply build the
image on the machine where it will be used. But to deploy the API server on the AWS-hosted test site, first tag the
image appropriately and push it to Elastic Container Repository. (These commands require )export ECRPASSWORD=$(aws ecr get-login-password --region us-west-2 --profile mavedb-test)
echo $ECRPASSWORD | docker login --username AWS --password-stdin {aws_account_id}.dkr.ecr.us-west-2.amazonaws.com
docker tag mavedb-api:latest {aws_account_id}.dkr.ecr.us-west-2.amazonaws.com/mavedb-api
docker push {aws_account_id}.dkr.ecr.us-west-2.amazonaws.com/mavedb-apiThese commands presuppose that you have theAWS CLIinstalled and have created a named
profile,mavedb-test, with your AWS credentials.With the Docker image pushed to ECR, you can now deploy the application.TODOAdd instructions if we want to
document this.Running the API server in Docker for developmentA similar procedure can be followed to run the API server in development mode on your local machine. There are a couple
of differences:Your local source code directory is mounted to the Docker container, instead of copying it into the container.The Uvicorn web server is started with a--reloadoption, so that code changes will cause the application to be
reloaded, and you will not have to restart the container.The API uses HTTP, whereas in production it uses encrypted communication via HTTPS.To start the Docker container for development, make sure that the mavedb-api directory is allowed to be shared with
Docker.  In Docker Desktop, this can be configured under Settings > Resources > File sharing.To start the application, rundocker-compose -f docker-compose-dev.yml up -dDocker integration can also be configured in IDEs like PyCharm.Running the API server directly for developmentSometimes you may want to run the API server outside of Docker. There are two ways to do this:Before using either of these methods, configure the environment variables described above.Run the server_main.py script. This script will create the FastAPI application, start up an instance of the Uvicorn,
and pass the application to it.export PYTHONPATH=${PYTHONPATH}:"`pwd`/src"
python src/mavedb/server_main.pyRun Uvicorn and pass it the application. This method supports code change auto-reloading.export PYTHONPATH=${PYTHONPATH}:"`pwd`/src"
uvicorn mavedb.server_main:app --reloadIf you use PyCharm, the first method can be used in a Python run configuration, but the second method supports PyCharm's
FastAPI run configuration.