{"id":20079497,"url":"https://github.com/neZorinEgor/FastAPI-StarterPack","last_synced_at":"2025-05-05T23:30:29.814Z","repository":{"id":245671179,"uuid":"818885322","full_name":"NeZorinEgor/FastAPI-Pattern","owner":"NeZorinEgor","description":"⚡ Шаблон для создания backend приложений на фреймворке FastAPI в связке с Redis, Nginx и Mysql","archived":false,"fork":false,"pushed_at":"2024-08-29T13:47:00.000Z","size":16,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-29T15:04:15.499Z","etag":null,"topics":["alembic","fastapi","mysql","nginx","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","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/NeZorinEgor.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":"2024-06-23T06:40:42.000Z","updated_at":"2024-08-29T13:47:04.000Z","dependencies_parsed_at":"2024-06-23T10:23:27.479Z","dependency_job_id":"fee05555-3836-4d5b-9084-2ea70cd187e8","html_url":"https://github.com/NeZorinEgor/FastAPI-Pattern","commit_stats":null,"previous_names":["nezorinegor/fastapi-pattern"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeZorinEgor%2FFastAPI-Pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeZorinEgor%2FFastAPI-Pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeZorinEgor%2FFastAPI-Pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeZorinEgor%2FFastAPI-Pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NeZorinEgor","download_url":"https://codeload.github.com/NeZorinEgor/FastAPI-Pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224472297,"owners_count":17316962,"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":["alembic","fastapi","mysql","nginx","redis"],"created_at":"2024-11-13T15:23:05.158Z","updated_at":"2025-05-05T23:30:29.806Z","avatar_url":"https://github.com/NeZorinEgor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI-StarterPack\n\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/fastapi/fastapi-original.svg\" title=\"FastAPI\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/postgresql/postgresql-original.svg\" title=\"FastAPI\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/redis/redis-original.svg\" title=\"FastAPI\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n\u003cimg src=\"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/sqlalchemy/sqlalchemy-original.svg\" title=\"FastAPI\" width=\"40\" height=\"40\"/\u003e\u0026nbsp;\n\n\u003e Everything you need to create a `production ready` application on FastAPI.\n\nFeature:\n1. DB configuration: `Postgres + SQLAlchemy + Alembic`\n2. Filestorage: `AWS-S3`\n3. Broker/Cache: `Celery + Redis`\n\nThe presence of `postgresql`, `redis` and `s3` is simulated in `docker-compose`.\n\n###  Usefulness's:\n1. Creating and launching migrations:\n```bash\nalembic revision --autogenerate -m \"\u003cmigration message\u003e\"\nalembic upgrade head\n```\n2. Setting up models for migration in [env.py](app/alembic/env.py)\n```bash\n# add your model's MetaData object here\nfrom src.database import Base\n# Your models here ↓\n# from src.\u003cyour_service_name\u003e.model import SomeModel\n\ntarget_metadata = Base.metadata\n```\n3. Generation of `RSA` keys for JWT: \n```bash\n# Generate an RSA private key of size 2048\nopenssl genrsa -out jwt-private.pem 2048\n# Extract a public key from a key pair that can be used in a certificate\nopenssl rsa -in jwt-private.pem -outform PEM -pubout -out jwt-public.pem\n```\n\n4. Cache connections to `get` routers:\n```python\nfrom collections.abc import AsyncIterator\nfrom contextlib import asynccontextmanager\n\nfrom fastapi import FastAPI\n\nfrom fastapi_cache import FastAPICache\nfrom fastapi_cache.backends.redis import RedisBackend\nfrom fastapi_cache.decorator import cache\n\nfrom redis import asyncio as aioredis\n\n\n@asynccontextmanager\nasync def lifespan(_: FastAPI) -\u003e AsyncIterator[None]:\n    redis = aioredis.from_url(\"redis://localhost\")\n    FastAPICache.init(RedisBackend(redis), prefix=\"fastapi-cache\")\n    yield\n\n\napp = FastAPI(lifespan=lifespan)\n\n\n@app.get(\"/\")\n@cache(expire=60)   # \u003c--- Obligatory after the router decorator\nasync def index():\n    return dict(hello=\"world\")\n```\n5. Local dev start up:\n```bash\ndocker compose up\nalembic upgrade head; uvicorn src.main:app --reload --host 0.0.0.0 --port 8000\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FneZorinEgor%2FFastAPI-StarterPack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FneZorinEgor%2FFastAPI-StarterPack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FneZorinEgor%2FFastAPI-StarterPack/lists"}