{"id":26562612,"url":"https://github.com/ysskrishna/fastapi-sync-async-starter","last_synced_at":"2026-04-05T23:05:00.877Z","repository":{"id":282076272,"uuid":"944919538","full_name":"ysskrishna/fastapi-sync-async-starter","owner":"ysskrishna","description":"A modern Python web application template built with FastAPI, demonstrating sync vs async operations using SQLAlchemy 2.0, psycopg2, and asyncpg. Features comprehensive testing with pytest-asyncio and pytest-cov, includes Docker support with multi-stage builds, Poetry for dependency management, and production-ready rate limiting with Redis support.","archived":false,"fork":false,"pushed_at":"2025-03-28T14:07:52.000Z","size":4227,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-23T07:32:09.575Z","etag":null,"topics":["async","asyncpg","boilerplate","docker","fastapi","fastapi-boilerplate","postgres","pydantic","pytest","python","python3","rate-limiting","redis","slowapi","sqlalchemy","starter-template","template"],"latest_commit_sha":null,"homepage":"https://www.producthunt.com/posts/fastapi-sync-async-starter-template","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ysskrishna.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2025-03-08T08:30:04.000Z","updated_at":"2025-03-28T14:07:56.000Z","dependencies_parsed_at":"2025-03-28T15:23:21.873Z","dependency_job_id":"718acb13-e661-480b-afda-642170e26d11","html_url":"https://github.com/ysskrishna/fastapi-sync-async-starter","commit_stats":null,"previous_names":["ysskrishna/fastapi-sync-async-starter"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ysskrishna/fastapi-sync-async-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysskrishna%2Ffastapi-sync-async-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysskrishna%2Ffastapi-sync-async-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysskrishna%2Ffastapi-sync-async-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysskrishna%2Ffastapi-sync-async-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysskrishna","download_url":"https://codeload.github.com/ysskrishna/fastapi-sync-async-starter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysskrishna%2Ffastapi-sync-async-starter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28132995,"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-12-30T02:00:05.476Z","response_time":64,"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":["async","asyncpg","boilerplate","docker","fastapi","fastapi-boilerplate","postgres","pydantic","pytest","python","python3","rate-limiting","redis","slowapi","sqlalchemy","starter-template","template"],"created_at":"2025-03-22T15:18:18.729Z","updated_at":"2025-12-30T22:06:52.130Z","avatar_url":"https://github.com/ysskrishna.png","language":"HTML","readme":"# FastAPI Sync-Async Starter\n\n[![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![Poetry](https://img.shields.io/badge/Poetry-2.1.1+-blue.svg)](https://python-poetry.org/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\u003ca href=\"https://www.producthunt.com/posts/fastapi-sync-async-starter-template?embed=true\u0026utm_source=badge-featured\u0026utm_medium=badge\u0026utm_souce=badge-fastapi\u0026#0045;sync\u0026#0045;async\u0026#0045;starter\u0026#0045;template\" target=\"_blank\"\u003e\u003cimg src=\"https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=945292\u0026theme=light\u0026t=1742755988478\" alt=\"Fastapi\u0026#0032;Sync\u0026#0032;Async\u0026#0032;Starter\u0026#0032;Template - Launch\u0026#0032;production\u0026#0045;ready\u0026#0032;FastAPI\u0026#0032;apps—effortlessly\u0026#0033; | Product Hunt\" style=\"width: 250px; height: 54px;\" width=\"250\" height=\"54\" /\u003e\u003c/a\u003e\n\nA modern Python web application template built with FastAPI, demonstrating sync vs async operations using SQLAlchemy 2.0, psycopg2, and asyncpg. Features comprehensive testing with pytest-asyncio and pytest-cov, includes Docker support with multi-stage builds, Poetry for dependency management, and production-ready rate limiting with Redis support.\n\n![FastAPI Sync-Async Starter](./media/assets/header_image.png)\n\n## Features\n\n- **FastAPI Framework Integration**\n  - Modern Python web framework with automatic OpenAPI documentation\n  - Built-in Swagger UI and ReDoc interfaces\n  - High-performance ASGI server with uvicorn\n\n- **Database Layer**\n  - Dual database access patterns with `psycopg2` (sync) and `asyncpg` (async)\n  - SQLAlchemy 2.0+ ORM with both sync and async session management\n  - Type-safe database operations and model relationships\n  - Structured database schema management\n\n- **Testing Infrastructure**\n  - Comprehensive test suite using `pytest`\n  - Async endpoint testing with `pytest-asyncio`\n  - Code coverage reporting with `pytest-cov`\n  - HTML test reports via `pytest-html`\n  - Database fixtures and test data management\n  - Containerized test environment with separate test stage\n\n- **Production Features**\n  - CORS middleware configuration\n  - Type validation with Pydantic v2\n  - Clean and scalable project structure\n  - Docker support with multi-stage builds\n  - Containerized development environment\n  - Poetry dependency management\n  - Optimized production and test environments\n  - Rate limiting with Redis support:\n    - Basic rate limiting (5 requests/minute)\n    - Shared rate limiting across endpoints\n    - Burst rate limiting (5/minute; 10/hour)\n    - Rate limiting for slow endpoints\n    - Environment-based configuration (Redis for production, memory for testing)\n\n## Prerequisites\n\n- Python 3.8+\n- PostgreSQL database\n- Redis (for rate limiting in production)\n- Poetry 2.1.1 (Python package manager)\n- Docker and Docker Compose (for containerized development)\n\n## Installation\n\n### Local Development Setup\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/ysskrishna/fastapi-sync-async-starter\ncd fastapi-sync-async-starter\n```\n\n2. Create and activate a virtual environment using Poetry:\n```bash\n# Install dependencies and create virtual environment\npoetry install\n```\n\n### Docker Setup\n\n1. Build and start the containers:\n```bash\ndocker-compose up --build\n```\n\nThis will:\n- Build the FastAPI application container with multi-stage optimization for development and production\n- Start a PostgreSQL database container with persistent volume\n- Start a Redis container for rate limiting\n- Set up the necessary networks and volumes\n- Initialize the database with the provided schema\n- Run api-tests and generate pytest and coverage reports\n- Manage environment variables automatically\n\n## Running the Application\n\n### Local Development\nStart the FastAPI server:\n```bash\npoetry run python main.py\n```\n\n### Docker Environment\nThe application will automatically start when using Docker Compose:\n```bash\ndocker-compose up\n```\n\nThe API will be available at `http://localhost:8000`\n\n### API Documentation\n- Swagger UI: `http://localhost:8000/docs`\n- ReDoc: `http://localhost:8000/redoc`\n\n## Testing\n\nThe project includes a comprehensive test suite using pytest. Here are the different ways to run tests:\n\n### Run all tests\n```bash\npoetry run pytest\n```\n\n### Run tests with cleared cache\n```bash\npoetry run pytest --cache-clear\n```\n\n### Run specific test file\n```bash\npoetry run pytest tests/routers/test_async_endpoints.py\n```\n\nAfter running the test suite, detailed reports will be generated in the following locations:\n\n- `report/pytest/index.html`: Interactive HTML report showing test results, including:\n  - Test case execution summary\n  - Pass/fail statistics\n  - Detailed error messages and tracebacks\n  - Test execution time\n\n- `report/coverage/index.html`: Comprehensive code coverage report containing:\n  - Overall coverage percentage\n  - File-by-file coverage analysis\n  - Line-by-line coverage highlighting\n  - Missing coverage identification\n\nYou can open these HTML reports in any web browser for a detailed view of test results and coverage analysis.\n\nExample reports are available in the repository:\n- [Example Pytest Report](media/example_pytest_report/index.html): See a sample of the test execution report\n- [Example Coverage Report](media/example_coverage_report/index.html): View a sample code coverage analysis\n\n## Project Structure\n\n```\nfastapi-sync-async-starter/\n├── src/\n│   ├── core/                     # Core functionality (database, config, rate limiting)\n│   ├── models/                   # SQLAlchemy models, pydantic schemas\n│   └── routers/                  # API endpoints\n├── tests/\n│   ├── routers/                  # API endpoint tests\n│   └── conftest.py               # Test configurations and fixtures\n├── scripts/                      # Utility scripts\n├── report/                       # Generated test and coverage reports\n│   ├── coverage/                 # Coverage reports generated by pytest-cov\n│   └── pytest/                   # Test reports generated by pytest-html\n├── media/                        \n│   ├── example_coverage_report/  # Sample coverage report\n│   └── example_pytest_report/    # Sample pytest report\n├── .coveragerc                   # Coverage configuration\n├── .dockerignore                 # Docker ignore rules\n├── .env                          # Environment variables\n├── .gitignore                    # Git ignore rules\n├── CHANGELOG.md                  # Project changelog\n├── docker-compose.yml           # Docker Compose configuration\n├── Dockerfile                   # Docker build configuration\n├── main.py                      # Application entry point\n├── pytest.ini                   # Pytest configuration\n├── pyproject.toml               # Poetry project configuration\n├── poetry.lock                  # Poetry lock file\n└── README.md                    # Project documentation\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysskrishna%2Ffastapi-sync-async-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysskrishna%2Ffastapi-sync-async-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysskrishna%2Ffastapi-sync-async-starter/lists"}