A production-ready RESTful API built with Flask, SQLAlchemy, and Marshmallow, based on the classic Chinook database. It exposes endpoints to browse artists, albums, and tracks with support for pagination, nested resources, summaries, and OpenAPI documentation.
- β RESTful endpoints (artists, albums, tracks)
- β SQLAlchemy ORM with SQLite (Chinook schema)
- β Marshmallow for schema validation and serialization
- β
Swagger UI (via Flasgger) available at
/apidocs/ - β Centralized error handling (404, 500, etc.)
- β Clean service-oriented architecture
- β
Auto-formatted with
black - β
100% unit test coverage with
pytest - β
Configurable via environment (
FLASK_CONFIG) - β
Dockerized and compatible with
Makefile
flask_api_chinook/
βββ app/
β βββ __init__.py # Application factory
β βββ run.py # Entrypoint for running the app
β βββ common/
β β βββ config.py # Configuration classes
β β βββ logging_config.py # Logging setup
β β βββ errors.py # Centralized error handling
β βββ models/ # SQLAlchemy models
β β βββ models.py
β βββ schemas/ # Marshmallow schemas
β β βββ albums_schema.py
β β βββ albums_summary_schema.py
β β βββ artists_schema.py
β β βββ tracks_schema.py
β βββ services/ # Business logic layer
β β βββ services.py
β βββ routes/ # Flask blueprints
β βββ __init__.py
β βββ artists.py
β βββ albums.py
βββ instance/
β βββ chinook.db # SQLite database (preloaded)
βββ tests/ # Pytest-based tests
β βββ test_albums.py
β βββ test_artists.py
β βββ test_errors.py
β βββ conftest.py
βββ docker-compose.yml
βββ Dockerfile
βββ Makefile
βββ requirements.txt
βββ requirements-dev.txt
βββ pytest.ini
βββ README.md
git clone https://github.com/martinp95/flask_api_chinook.git
cd flask_api_chinookmake upThis will build and run the app using docker-compose.
When it's running:
- β API Base: http://localhost:5000/artists
- β Swagger UI: http://localhost:5000/apidocs
Set the Flask configuration using the FLASK_CONFIG env var:
| Mode | Config Path |
|---|---|
| Development | app.common.config.DevelopmentConfig |
| Testing | app.common.config.TestingConfig |
| Production | app.common.config.ProductionConfig |
Default is Development if not set.
Returns paginated list of artists:
{
"artists": [
{ "ArtistId": 1, "Name": "AC/DC" },
{ "ArtistId": 2, "Name": "Accept" }
],
"page": 1,
"per_page": 2,
"total": 275
}Returns albums by artist:
[
{ "AlbumId": 1, "Title": "For Those About To Rock We Salute You" },
{ "AlbumId": 4, "Title": "Let There Be Rock" }
]Returns albums and their tracks:
{
"albums": [
{
"AlbumId": 1,
"Title": "For Those About To Rock We Salute You",
"tracks": [
{ "TrackId": 1, "Name": "Track A" },
{ "TrackId": 2, "Name": "Track B" }
]
}
],
"page": 1,
"per_page": 1,
"total": 347
}Returns all tracks from an album:
{
"album_id": 1,
"tracks": [
{ "TrackId": 1, "Name": "Track A" },
{ "TrackId": 2, "Name": "Track B" }
]
}Returns album summaries with artist and track count:
[
{
"AlbumId": 1,
"AlbumTitle": "For Those About To Rock",
"ArtistName": "AC/DC",
"TrackCount": 10
}
]make testmake coverageCoverage report is also available in htmlcov/index.html.
make run # Run the Flask app locally
make test # Run all tests with pytest
make coverage # Run coverage report
make format # Format code with black
make clean # Clean pyc/__pycache__
make up # Start docker container
make down # Stop docker containerInstall with:
pip install -r requirements.txt
pip install -r requirements-dev.txt # For testing & developmentAccessible without authentication at:
http://localhost:5000/apidocs/
Fully autogenerated via Flasgger.
This repository demonstrates a complete, production-ready Flask REST API with:
- Modular and scalable architecture
- Full Docker support for reproducible environments
- High test coverage with
pytestand GitHub Actions - Swagger UI documentation at
/apidocs/ - Error handling and logging centralized
- Clean and readable codebase with auto-formatting via
make format
All core functionality is covered by unit tests, with automated CI validating each push and pull request. This project serves as a solid foundation or reference for building robust backend services in Flask.
Developed by MartΓn PelΓ‘ez DΓaz
GitHub: @martinp95
Licensed under the MIT License.