API for fetching data from CFDE Chemical Database (CFChemDb).
- Docker
- Docker Compose
- Copy
app/.env.exampletoapp/.env - Edit the
app/.envcredentials to point to thecfchemdatabase - Run
docker compose --env-file ./app/.env -f docker-compose.dev.yml up --build
The API should now be accessible from localhost:8000
If one finds they need to update dependencies (requirements.txt), the following steps can be followed:
- If a new package is required, add it to
requirements.in - Setup and activate a Python (v3.14) virtual environment. For example, with conda use:
conda create -n cfchem-api python=3.14 && conda activate cfchem-api - Install pip-tools:
pip install pip-tools - Compile new requirements:
pip-compile --upgrade- Make sure you are in the
app/directory:cd app/
- Make sure you are in the
- (Optional) Test the update locally in your environment:
pip-sync
Note: If you need to update the Python version, make sure to adjust the steps above accordingly and to update the Python image in Dockerfile.
This project uses pre-commit hooks to automatically format Python code with Black before each commit. This ensures consistent code style across the project.
Setup (one-time):
-
Setup and activate a Python (v3.14) virtual environment if you haven't already:
conda create -n cfchem-api python=3.14 && conda activate cfchem-api -
Install dependencies:
pip install -r app/requirements.txt
-
Install the pre-commit hooks:
pre-commit install
Usage:
Once installed, the hooks will run automatically on git commit. If Black reformats any files, the commit will be aborted and you'll need to:
- Review the changes Black made
- Stage the reformatted files:
git add <files> - Commit again:
git commit
Manual formatting:
You can also run Black manually on all files:
black .Or run all pre-commit hooks manually without committing:
pre-commit run --all-filesConfiguration:
- Pre-commit hooks are configured in .pre-commit-config.yaml
- A full set of Swagger documentation can be found at http://localhost:8000/apidocs
- Pull latest changes (for compose file mainly):
git pull- Copy .env.prod.example to
.env:
cp .env.prod.example .env-
Modify
.env -
(If significant changes to compose file):
docker compose -f docker-compose.prod.yml down
-
Pull latest images and run:
docker compose -f docker-compose.prod.yml pull docker compose -f docker-compose.prod.yml up -d --remove-orphans
-
Verify deployment:
docker compose -f docker-compose.prod.yml ps docker compose -f docker-compose.prod.yml logs api
-
(One-time setup) If not done so already, modify your /etc/apache2/sites-available/ files to include the following lines
# cfchem
ProxyPass /cfchem/api http://localhost:<APP_PORT>/api
ProxyPassReverse /cfchem/api http://localhost:<APP_PORT>/api
ProxyPass /cfchem/apidocs/ http://localhost:<APP_PORT>/apidocs/
ProxyPassReverse /cfchem/apidocs/ http://localhost:<APP_PORT>/apidocs/
ProxyPass /cfchem/flasgger_static/ http://localhost:<APP_PORT>/cfchem/flasgger_static/
ProxyPassReverse /cfchem/flasgger_static/ http://localhost:<APP_PORT>/cfchem/flasgger_static/
# Static directory aliases (e.g., SPA UI builds)
# cfchem
Alias /cfchem /var/www/cfchem/
<Directory /var/www/cfchem/>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
# SPA fallback: if the file/dir doesn't exist, serve index.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]
</Directory>
Then reload apache:
sudo apache2ctl configtest # make sure syntax ok
sudo systemctl reload apache2
curl -I https://chiltepin.health.unm.edu/cfchem/apidocs/ # should give HTTP/1.1 200