A sample Django Rest Framework app with Celery integration.
FML API
app is used for storing and managing music library data. It provides endpoints for CRUD operations on the following resources and operations:
- Artists
- Albums
- Songs
- Playlists
- *Admin operations
*requires API key provided in Auth header.
Celery is used for asynchronous and periodic tasks. In the context of the application it is used for:
- creating a csv dump of the database every 24 hours.
Any new periodic tasks should be added to CELERY_BEAT_SCHEDULE
in FancyMusicLibrary/settings.py
.
Prerequisites:
- OS: macOS or linux (preferred)
- Redis (follow instructions at https://redis.io/topics/quickstart)
- PostgreSQL (follow instructions at https://www.postgresql.org/download/)
- Python 3.11 with a venv created for this project
To install the dependencies, run:
pip install -r requirements/all.for.dev.txt
.
- Run the redis server.
- Fill
.env
file with the necessary environment variables (including secrets). - Export
PYTHONPATH
env var so that it includes path to thesrc
dir. - Apply migrations to your PostgreSQL database running locally:
python manage.py migrate
. - To run the API: run
python manage.py runserver
. - To run the Celery beat: run
celery -A FancyMusicLibrary beat --loglevel=info
. - To run the Celery worker: run
celery -A FancyMusicLibrary worker --loglevel=info
.
Make sure docker
and docker-compose
are installed on your machine.
Docker-compose utilizes nginx server to serve the API.
- Inside
docker
folder rundocker-compose up --build
. - Run
docker-compose exec web python manage.py migrate
to apply migrations to locally running PostgreSQL db.
Install pre-commit by running:
pip install -r requirements/all.for.dev.txt
.pre-commit install
.
To apply hooks to pre-commit changes run: pre-commit run --all-files
.
Packages used:
- pytest (runner)
- pytest-django (Django integration)
- pytest-mock (mocking/patching)
Make sure redis-server is running locally.
Run tests with pytest
in the src
directory.