This a simple python web service that uses the Fastapi framework to create a RESTful API as well as a webserver. This is meant to be used as a template for future projects.The project includes a fully dockerised environment with a docker-compose file to run the project. The project also includes postgresql database and a redis database. There is RQ worker support for asyncronous tasks. The included Minio server is used for file storage. The frontend is through the Jinja2 templating engine. It also includes Nginx and certbot for SSL support.
- Fastapi
- Jinja2
- Postgresql
- Redis
- Celery
- Minio
- Nginx
- Certbot
- Support for private python packages from private repositories
- Ruff
- Github actions for CI/CD
- Makefile for easy setup
- VS Code Debugger support through debugpy
- Airflow
- Multi Database
-
Install Docker and Docker-compose 2.Copy the .env-copy file to .env and fill in the variables
-
If the docker requires access to a private repository you need to load your ssh key to your ssh-agent using
ssh-add
command.eval "$(ssh-agent -s)" ssh-add ~/.ssh/<your-ssh-key> #set the path to your ssh key
-
Build the docker compose file
docker-compose build
- Run the docker compose file
docker-compose up
- The webserver should be running on localhost on the port defined in the .env file
- Create a bucket in the minio server with the name defined in the .env file
- The project uses alemic to manage the database. To create the database run the following command
alemic upgrade head
-
Install Docker and Docker-compose
-
Copy the .env-copy file to .env and fill in the variables 3.If the docker requires access to a private repository you need to load your ssh key to your ssh-agent using
ssh-add
command.eval "$(ssh-agent -s)" ssh-add ~/.ssh/<your-ssh-key> #set the path to your ssh key
-
Run the makefile
make init
- The webserver should be running on localhost on the port defined in the .env file
The project uses poetry to manage the python dependencies.
Poetry
(version equal to1.7.0
) Installation GuidePython 3.10
Docker
(Optional)docker-compose
(Optional)
poetry add package-name=version-number
- Dev dependencies can be added using
--group dev
flag.
poetry remove package-name
poetry lock
- This will update
poetry.lock
file with latest versions of all dependencies. - This should be done before committing changes to
pyproject.toml
file.
- This will update
poetry update
- This will update all dependencies to latest version.
- This will also update
poetry.lock
file.
poetry update package-name
- This will update
package-name
to latest version. - This will also update
poetry.lock
file.
- This will update
poetry add <package-name@latest> --group dev
- This will update
package-name
fordev
group as there is no straight forward way yot update dev dependencies to latest version. - Remember to pin dependency in this case.
- This will also update
poetry.lock
file.
- This will update
This is used for running lint rules before committing changes to the repo. pre-commit
command should be installed as
part of installing dependencies. To check if it is working properly, run pre-commit --version
, you should see 3.5.0
or newer version.
- To install git commit hooks, run
pre-commit install
. And you're done. - For more information, refer here
To create a new migration run the following command
alembic revision --autogenerate -m "migration message"
To apply the migration run the following command
alembic upgrade head
To downgrade the migration run the following command
alembic downgrade -1
- Install the python extension for VS Code.
- Use the included
launch.json
file to run the debugger. - Use the custom docker compose file to run the debugger.
docker-compose -f docker-compose.debug.yml up
- Set breakpoints in the code and run the debugger vs code(Wait for debugpy to be installed).
- The debugger should be running on port 5678.
Comment out the debugpy
start-debug.sh
file and run the docker compose file above.
To run nginx and certbot run the following command:
docker-compose --profile nginx up
-
Modify configuration in
nginx/app.conf
,init_cert.sh
with the appropriate config/credentials. -
Run the init script(Ensure that you have made the appropriate dns mapping for the server at your domain provider):
./init_cert.sh