{"id":14064980,"url":"https://github.com/zhanymkanov/fastapi_production_template","last_synced_at":"2025-10-18T16:17:54.633Z","repository":{"id":65359736,"uuid":"585608448","full_name":"zhanymkanov/fastapi_production_template","owner":"zhanymkanov","description":"FastAPI Template with Docker, Postgres","archived":false,"fork":false,"pushed_at":"2025-01-06T16:30:12.000Z","size":105,"stargazers_count":1122,"open_issues_count":4,"forks_count":162,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-13T13:19:08.074Z","etag":null,"topics":["fastapi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhanymkanov.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}},"created_at":"2023-01-05T15:54:14.000Z","updated_at":"2025-04-11T17:29:23.000Z","dependencies_parsed_at":"2023-02-04T13:15:36.423Z","dependency_job_id":"6659c983-e10e-42c4-88d1-50ce59e25fa3","html_url":"https://github.com/zhanymkanov/fastapi_production_template","commit_stats":{"total_commits":36,"total_committers":10,"mean_commits":3.6,"dds":0.25,"last_synced_commit":"649e8404b0678e39a563601011a42656cf05fdd4"},"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanymkanov%2Ffastapi_production_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanymkanov%2Ffastapi_production_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanymkanov%2Ffastapi_production_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhanymkanov%2Ffastapi_production_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhanymkanov","download_url":"https://codeload.github.com/zhanymkanov/fastapi_production_template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717239,"owners_count":21150390,"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","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"],"created_at":"2024-08-13T07:04:12.967Z","updated_at":"2025-10-18T16:17:49.589Z","avatar_url":"https://github.com/zhanymkanov.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# FastAPI Template\nThis repo is kind of a template I use when starting up new FastAPI projects:\n- easy local development\n  - environment with configured postgres\n  - script to lint code with `ruff` and `ruff format`\n- SQLAlchemy with slightly configured `alembic`\n  - async SQLAlchemy engine\n  - pessimistic connection pooling configuration ([link](https://docs.sqlalchemy.org/en/20/core/pooling.html#module-sqlalchemy.pool))\n  - migrations set in easy to sort format (`YYYY-MM-DD_slug`)\n  - migrations are formated with `ruff`\n- global pydantic model with \n  - explicit timezone setting during JSON export\n- some configs for production\n  - gunicorn with dynamic workers configuration (stolen from [@tiangolo](https://github.com/tiangolo))\n  - Dockerfile optimized for small size and fast builds with a non-root user\n  - JSON logs\n  - sentry for deployed envs\n- and some other extras like global exceptions, sqlalchemy keys naming convention, shortcut scripts for alembic, etc.\n\n## Local Development\n\n### Setup just\nMacOS:\n```shell\nbrew install just\n```\n\nDebian/Ubuntu:\n```shell\napt install just\n````\n\nOthers: [link](https://github.com/casey/just?tab=readme-ov-file#packages)\n\n### Setup poetry\n```shell\npip install poetry\n```\n\nOther ways: [link](https://python-poetry.org/docs/#installation)\n\n### Setup Postgres (16.3)\n```shell\njust up\n```\n### Copy the environment file and install dependencies\n1. `cp .env.example .env`\n2. `poetry install`\n\n### Run the uvicorn server\nWith default settings:\n```shell\njust run\n```\nWith extra configs (e.g. logging file)\n```shell\njust run --log-config logging.ini\n```\n\n### Linters\nFormat the code with `ruff --fix` and `ruff format`\n```shell\njust lint\n```\n\n### Migrations\n- Create an automatic migration from changes in `src/database.py`\n```shell\njust mm *migration_name*\n```\n- Run migrations\n```shell\njust migrate\n```\n- Downgrade migrations\n```shell\njust downgrade downgrade -1  # or -2 or base or hash of the migration\n```\n\n## Deployment\nDeployment is done with Docker and Gunicorn. The Dockerfile is optimized for small size and fast builds with a non-root user. The gunicorn configuration is set to use the number of workers based on the number of CPU cores.\n\nExample of running the app with docker compose:\n```shell\ndocker compose -f docker-compose.prod.yml up -d --build\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanymkanov%2Ffastapi_production_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhanymkanov%2Ffastapi_production_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhanymkanov%2Ffastapi_production_template/lists"}