{"id":19130371,"url":"https://github.com/pedrodeoliveira/fastapi-tdd-docker","last_synced_at":"2025-09-03T07:35:28.409Z","repository":{"id":41372657,"uuid":"289365146","full_name":"pedrodeoliveira/fastapi-tdd-docker","owner":"pedrodeoliveira","description":"A Python RESTful API with FastAPI and Docker","archived":false,"fork":false,"pushed_at":"2021-01-25T23:36:21.000Z","size":40,"stargazers_count":21,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-21T20:12:22.806Z","etag":null,"topics":["docker","fastapi","github-actions","heroku","postgresql","pytest","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pedrodeoliveira.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-21T21:08:22.000Z","updated_at":"2024-07-23T12:16:48.000Z","dependencies_parsed_at":"2022-07-30T08:08:07.641Z","dependency_job_id":null,"html_url":"https://github.com/pedrodeoliveira/fastapi-tdd-docker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pedrodeoliveira/fastapi-tdd-docker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrodeoliveira%2Ffastapi-tdd-docker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrodeoliveira%2Ffastapi-tdd-docker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrodeoliveira%2Ffastapi-tdd-docker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrodeoliveira%2Ffastapi-tdd-docker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pedrodeoliveira","download_url":"https://codeload.github.com/pedrodeoliveira/fastapi-tdd-docker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pedrodeoliveira%2Ffastapi-tdd-docker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273409505,"owners_count":25100444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","fastapi","github-actions","heroku","postgresql","pytest","python"],"created_at":"2024-11-09T06:10:28.212Z","updated_at":"2025-09-03T07:35:28.388Z","avatar_url":"https://github.com/pedrodeoliveira.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test-Driven Development with FastAPI and Docker\n\n![CI/CD status](https://github.com/pedrodeoliveira/fastapi-tdd-docker/workflows/CI/CD%20status/badge.svg)\n\nThis repository is based on the paid course with the same name from [testdriven.io](https://testdriven.io), with some \nminor custom modifications (original repo [here](https://github.com/testdrivenio/fastapi-tdd-docker)).\nThe project consists in the development of an asynchronous **text summarization API** \nfollowing Test-Driven Development (TDD) practices. The API follows RESTful design \nprinciples and enables the typical CRUD operations on **summaries**. \n\nThese summaries represent condensed descriptions of web pages, each *summary* resource \nwill have a `url` and the respective `summary`. This project uses the `newspaper3k` \nlibrary that provides both the web scraping and summarizing parts.\n\n## Technologies\n\nThe following technologies have been used:\n\n- **Python** API developed in Python which supports many popular web frameworks.\n- **FastAPI** a recent and trendy Python web framework supporting async out-of-the-box and\ndata validation based on *type hints*.\n- **Pytest** a Python test framework which makes it easy to write and run unit and integration\ntests.\n- **Tortoise ORM** a Python library used as an async Object Relational Mapper (ORM), allowing\nus to seamlessly interact with relational database from an async context.\n- **PostgresSQL** the relational database where the API's data will live.\n- **Docker** container platform used to quickly, easily and reliably deploy our web application\ninto production.\n- **GitHub Packages** where the Docker images will be stored.\n- **GitHub Actions** the CI/CD solution that automates the build, test and deployment of \nthe web app code to the production.\n- **Heroku** the PaaS solution for hosting our web app (in production).\n\n## API Endpoints\n\nThis API implements the following routes:\n\n| **Endpoint**     \t| **HTTP method**   | **CRUD method** \t| **Description**      \t|\n|-----------------\t|----------------  \t|---------------\t|----------------------\t|\n| `/summaries`     \t| GET           \t| READ        \t    | get all summaries    \t|\n| `/summaries/\u003cid\u003e`\t| GET         \t    | READ        \t    | get summary by id    \t|\n| `/summaries`     \t| POST        \t    | INSERT      \t    | add a new summary \t|\n| `/summaries/\u003cid\u003e`\t| DELETE      \t    | DELETE      \t    | delete summary by id \t|\n| `/summaries/\u003cid\u003e`\t| PUT         \t    | UPDATE      \t    | update summary by id \t|\n\n## Build the API image\n\nTo build, test and run this API we'll be using `docker-compose`. As such, the first step\nis to build the images defined in the `docker-compose.yml` file.\n\n```bash\n$ docker-compose build\n```\n\nThis will build two images:\n\n- `fastapi-tdd-docker_web` image with REST API.\n- `fastapi-tdd-docker_web-db` image with Postgres database.\n\n## Run the Containers\n \nTo run the containers previously built, execute the following:\n \n```bash\n$ docker-compose up -d\n```\n\nThis will launch two services named `web` (the API) and `web-db` (the underlying \ndatabase) in background. The `web` service will be running on port `8002` on localhost. \nWhereas the database will be exposed to the `web` service. To make sure the\napp is running correctly open [http://localhost:8002/ping](http://localhost:8002/ping) in \nyour web browser (and/or run `docker-compose logs -f` from the command line). \n\n## Create the Database\n\nThe database can be created by running the following command:\n\n```bash\n$ docker-compose exec web python app/db.py\n```\n\nOne can confirm that the database was properly created by accessing the database container\nand starting a psql console.\n\n```bash\n$ docker-compose exec web-db psql -U postgres\n```\n\nNext, one can connect to the `web_dev` database and list all the tables:\n\n```bash\n# \\c web_dev\n# \\dt\n```\n\n## Run the Tests\n\nThe tests can be executed with:\n\n```bash\n$ docker-compose exec web pytest\n```\n\nOr including a coverage check:\n\n```bash\n$ docker-compose exec web pytest --cov=\".\"\n```\n\n## Check for Code Quality\n\nAnother step to ensure the code contains the desired quality is to perform *linting*, that \nis, to check for stylistic or programming errors. The following command will run the \n`flake8` linter throughout the source code:\n\n```bash\n$ docker-compose exec web flake8 .\n```\n\nNext, we perform additional checks to verify, and possibly correct, the code formatting \n(using `black`) and the ordering and organization of import statements (using `isort`).\n\n```bash\n$ docker-compose exec web black . --check\n$ docker-compose exec web isort . --check-only\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrodeoliveira%2Ffastapi-tdd-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedrodeoliveira%2Ffastapi-tdd-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrodeoliveira%2Ffastapi-tdd-docker/lists"}