{"id":29904851,"url":"https://github.com/chrnmaxim/fastapi_template","last_synced_at":"2026-05-15T21:33:39.684Z","repository":{"id":306052087,"uuid":"1024239261","full_name":"chrnmaxim/fastapi_template","owner":"chrnmaxim","description":"Template repository to quick start a new FastAPI project","archived":false,"fork":false,"pushed_at":"2025-10-02T05:49:20.000Z","size":102,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-02T07:22:31.587Z","etag":null,"topics":["fastapi","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrnmaxim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-22T11:47:03.000Z","updated_at":"2025-09-16T12:45:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"3eeea35b-58fe-44e5-86ef-ea5871c14987","html_url":"https://github.com/chrnmaxim/fastapi_template","commit_stats":null,"previous_names":["chrnmaxim/fastapi_template"],"tags_count":3,"template":true,"template_full_name":null,"purl":"pkg:github/chrnmaxim/fastapi_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnmaxim%2Ffastapi_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnmaxim%2Ffastapi_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnmaxim%2Ffastapi_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnmaxim%2Ffastapi_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrnmaxim","download_url":"https://codeload.github.com/chrnmaxim/fastapi_template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnmaxim%2Ffastapi_template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33080777,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["fastapi","sqlalchemy"],"created_at":"2025-08-01T18:18:32.850Z","updated_at":"2026-05-15T21:33:39.678Z","avatar_url":"https://github.com/chrnmaxim.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI Template\n\n[![Static Badge](https://img.shields.io/badge/python-3670A0?style=for-the-badge\u0026logo=python\u0026logoColor=ffdd54)](https://www.python.org)\n[![Static Badge](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge\u0026logo=fastapi)](https://fastapi.tiangolo.com/)\n[![Static Badge](https://img.shields.io/badge/-Swagger-%23Clojure?style=for-the-badge\u0026logo=swagger\u0026logoColor=white)](https://swagger.io)\n[![Static Badge](https://img.shields.io/badge/postgresql-4169e1?style=for-the-badge\u0026logo=postgresql\u0026logoColor=white)](https://www.postgresql.org)\n[![Static Badge](https://img.shields.io/badge/-SQLAlchemy-ffd54?style=for-the-badge\u0026logo=sqlalchemy\u0026logoColor=white)](https://www.sqlalchemy.org/)\n[![Static Badge](https://img.shields.io/badge/docker-257bd6?style=for-the-badge\u0026logo=docker\u0026logoColor=white)](https://www.docker.com/)\n\n### This is a template repository to quickly start a new FastAPI project.\n\n## Key features:\n* Configured SwaggerUI, doc URLs and homepage in `src.main.app` (fastapi.FastAPI instance).\n* Configured SQLAlchemy Session and Engine with [AsyncAdaptedQueuePool](https://docs.sqlalchemy.org/en/20/core/pooling.html#sqlalchemy.pool.AsyncAdaptedQueuePool) as `poolclass`, `echo` mode and `application_name` for proper monitoring connections from the app to a database or a connection pooler.\n* Configured [pytest](https://docs.pytest.org/en/stable/) for integration tests in Docker with independent PostgreSQL database.\n* Configured [alembic](https://alembic.sqlalchemy.org/en/latest/) for database migrations.\n* `BaseRepository` class as the main interface for basic CRUD operations with DB models.\n* `Docker` files for tests and local app start.\n* `Nginx` configuration includes optimized timeouts, connection limits.\n* `Makefile` with commands for convenient usage.\n* CI workflow in GitHub Actions that starts with each commit into open PR into `develop` or `main` branches.\n\n## Optimization key points\n\n### SQLAlchemy\n* SQLAlchemy Connection Pooling with [AsyncAdaptedQueuePool](https://docs.sqlalchemy.org/en/20/core/pooling.html#sqlalchemy.pool.AsyncAdaptedQueuePool) allows maintaining a connection to the database.\n\u003e [!NOTE]\n\u003e `POOL_SIZE` and `MAX_OVERFLOW` environment variables should be set taking `uvicorn --workers N` into account.\n* `src.dependencies.get_session` provides an AsyncGenerator of an [AsyncSession](https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.html#sqlalchemy.ext.asyncio.AsyncSession) instance with a transaction that will be automatically committed or rolled back in case of any exception upon exiting the context manager.\n\u003e [!NOTE]\n\u003e The DB connection is checked out from the pool at the first `AsyncSession.execute` call and remains so until exiting the context manager.\n\n### FastAPI\n* [ORJSONResponse](https://fastapi.tiangolo.com/advanced/custom-response/#orjsonresponse) as\n`default_response_class` in FastAPI configuration which uses the high-performance [orjson](https://github.com/ijl/orjson) library to serialize data to JSON.\n* [Middlewares](https://fastapi.tiangolo.com/tutorial/middleware/) are disabled, since usually the app runs behind a reverse proxy.\n* [src.healthcheck.router.healthcheck](src/healthcheck/router.py) returns [ORJSONResponse](https://fastapi.tiangolo.com/advanced/custom-response/#orjsonresponse)\ndirectly instead of the pydantic model [src.healthcheck.schemas.HealthCheckSchema](src/healthcheck/schemas.py) to avoid overcomplicated (_in some cases_) validation and serialization to an object compatible with JSON by [jsonable_encoder](https://fastapi.tiangolo.com/tutorial/encoder/).\n\n### Uvicorn\nWhen running uvicorn in a production/stage environment behind a reverse proxy, the startup command is:\n```bash\nuvicorn src.main:app --host 0.0.0.0 --port 8000 --workers $UVICORN_WORKERS --loop uvloop --proxy-headers --no-access-log\n```\n* `--workers $UVICORN_WORKERS` - Set the number of workers according to the number of vCPUs on the server (as a startup option).\n* `--loop uvloop` - Set the event loop implementation to [uvloop](https://github.com/MagicStack/uvloop) explicitly (uvloop makes asyncio 2-4x faster).\n* `--proxy-headers` - Enable proxy headers.\n* `--no-access-log` - Disable uvicorn access log.\n\n\u003e [!NOTE]\n\u003e If uvicorn and a reverse proxy are running on the same server, it is more beneficial to establish a connection via a UNIX domain socket using the `--uds \u003cpath\u003e` option (see `docker-compose-prod.yml` and `nginx/nginx.conf` for examples).\n\n## Use as Template\n\n1. Create a repository from this template by clicking the [**Use this template**] button.\n\n\u003e [!NOTE]\n\u003e For more information about creating a repository from a template, refer to the [GitHub docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).\n\n2. Clone the created repository.\n\n3. Navigate to the root directory of the template.\n\n4. Install [uv](https://docs.astral.sh/uv/getting-started/installation/).\n\n5. Install dependencies, including dependencies from the dev group.\n```bash\nuv sync --extra dev\n```\n\n5. Create `.env` based on `.env.example`:\n\n```bash\ncp -r src/.env.example src/.env`\n```\n\n6. Start App with PostgreSQL in Docker containers and apply [alembic](https://alembic.sqlalchemy.org/en/latest/) migrations:\n```bash\nmake start_dev\n```\n\n7. API docs:\n* Swagger UI: http://127.0.0.1:8000/docs\n* ReDoc: http://127.0.0.1:8000/redoc\n\n8. Stop and delete containers:\n```bash\nmake stop_dev\n```\n\n9. Delete containers including volumes:\n```bash\nmake remove_dev\n```\n\n## About Tests\nThe template has already configured [pytest](https://docs.pytest.org/en/stable/) with necessary fixtures for integration testing of endpoints in Docker with an independent PostgreSQL database. See example in `tests/integration/healthcheck_router_test.py`.\n\nAt the start of the test session, [alembic](https://alembic.sqlalchemy.org/en/latest/) migrations are applied to the database.\n\n1. The tests are run from an independent PostgreSQL database using the command `make test`.\n\n2. After running the tests, you can view the code coverage report in the `htmlcov/index.html` file.\n\n\u003e [!NOTE]\n\u003e Tests are run in GitHub Actions with each commit to an open Pull Request in the `develop` or `main` branch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrnmaxim%2Ffastapi_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrnmaxim%2Ffastapi_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrnmaxim%2Ffastapi_template/lists"}