{"id":24625359,"url":"https://github.com/ahnaf19/learn_fastapi","last_synced_at":"2026-04-20T10:32:33.102Z","repository":{"id":272906555,"uuid":"918131005","full_name":"Ahnaf19/learn_fastapi","owner":"Ahnaf19","description":"This repository is dedicated to learning and practicing fastapi, a powerful web framework for Python. Also, it contains some workflow yml files, practising github actions too!","archived":false,"fork":false,"pushed_at":"2025-02-02T12:32:40.000Z","size":1966,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T13:28:36.132Z","etag":null,"topics":["fastapi","github-actions"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/Ahnaf19.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-17T10:04:46.000Z","updated_at":"2025-02-02T12:32:43.000Z","dependencies_parsed_at":"2025-02-02T13:28:35.218Z","dependency_job_id":"b1afa06c-ec77-4899-af86-c510286088c7","html_url":"https://github.com/Ahnaf19/learn_fastapi","commit_stats":null,"previous_names":["ahnaf19/learn_fastapi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahnaf19%2Flearn_fastapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahnaf19%2Flearn_fastapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahnaf19%2Flearn_fastapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahnaf19%2Flearn_fastapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ahnaf19","download_url":"https://codeload.github.com/Ahnaf19/learn_fastapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244394469,"owners_count":20445634,"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","github-actions"],"created_at":"2025-01-25T04:33:12.838Z","updated_at":"2026-04-20T10:32:33.088Z","avatar_url":"https://github.com/Ahnaf19.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# learn_fastapi — Intern Teaching Kit\n\nA structured, runnable teaching kit for learning FastAPI from scratch.\nAligned with the **\"Get Faster with FastAPI\"** guide (see `docs/`).\n\n---\n\n## Quick Start\n\nThis project uses **[uv](https://docs.astral.sh/uv/)** for dependency and environment management.\n\n```bash\n# Install uv (if not already installed)\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n\n# Install all dependencies and create .venv automatically\nuv sync\n\n# Run any numbered teaching file (from project root)\nuv run uvicorn learn.01_hello_world:app --reload\n\n# Run the structured demo app\nuv run uvicorn app.main:app --reload\n\n# Run all tests\nuv run pytest tests/ -v\n```\n\nThen open **http://127.0.0.1:8000/docs** for interactive Swagger UI.\n\n\u003e The `.venv` is created and managed by `uv` — do not create it manually.\n\n---\n\n## Starter Kit Learning Path\n\nStep through the numbered files in `learn/` in order. Each builds on the previous.\nAll commands run from the **project root**.\n\n| File | Concept | Run Command |\n|------|---------|-------------|\n| `learn/01_hello_world.py` | FastAPI app, first endpoint, auto docs (`/docs`, `/redoc`) | `uv run uvicorn learn.01_hello_world:app --reload` |\n| `learn/02_path_params.py` | Path parameters, `Path()` validation, `HTTPException` | `uv run uvicorn learn.02_path_params:app --reload` |\n| `learn/03_query_params.py` | Query parameters, `Query()`, `Optional`, filters + pagination | `uv run uvicorn learn.03_query_params:app --reload` |\n| `learn/04_request_body.py` | Pydantic `BaseModel`, POST/PUT/PATCH, `model_dump()`, `exclude_unset` | `uv run uvicorn learn.04_request_body:app --reload` |\n| `learn/05_pydantic_field.py` | `Field()` constraints, `EmailStr`, nested models, Swagger examples | `uv run uvicorn learn.05_pydantic_field:app --reload` |\n| `learn/06_response_status.py` | `response_model`, status codes, Create/Update/Out schema pattern | `uv run uvicorn learn.06_response_status:app --reload` |\n| `learn/07_crud_all_in_one.py` | Full CRUD — all best practices combined in one file | `uv run uvicorn learn.07_crud_all_in_one:app --reload` |\n\n---\n\n## Structured App Demo (`app/`)\n\nA modular, production-style FastAPI application with **Users** and **Orders** CRUD.\n\n```bash\nuv run uvicorn app.main:app --reload\n```\n\n### What it demonstrates\n\n| Concept | Where |\n|---------|-------|\n| `APIRouter` with `prefix` + `tags` | `app/routers/users.py`, `app/routers/orders.py` |\n| `include_router` to compose the app | `app/main.py` |\n| `Depends()` for pagination | `app/dependencies.py` → used in both routers |\n| `Depends()` for get-or-404 | `app/dependencies.py` → `get_user_or_404` |\n| Separate `schemas/` directory | `app/schemas/user.py`, `app/schemas/order.py` |\n| `Field()` constraints + `EmailStr` | `app/schemas/user.py` |\n| In-memory fake DB | `app/db/fake_db.py` |\n| Cross-resource validation | `app/routers/orders.py` (user must exist) |\n| Full CRUD with proper status codes | Both routers |\n\n### App structure\n\n```\napp/\n├── __init__.py\n├── main.py               # FastAPI instance + include_router\n├── dependencies.py       # Shared Depends(): pagination, get_user_or_404\n├── db/\n│   └── fake_db.py        # In-memory dicts (users_db, orders_db)\n├── schemas/\n│   ├── user.py           # UserCreate, UserUpdate, UserOut\n│   └── order.py          # OrderCreate, OrderUpdate, OrderOut\n├── routers/\n│   ├── users.py          # /users  — full CRUD\n│   └── orders.py         # /orders — full CRUD\n└── utils/\n    └── helpers.py        # next_id() helper\n```\n\n---\n\n## Docker (`app/` only)\n\nThe `app/` service is fully containerized using the official uv Docker image.\n\n```bash\n# Build the image\ndocker build -t demo-api .\n\n# Run (production mode, no reload)\ndocker run -p 8000:8000 demo-api\n\n# Dev mode with hot reload (mounts ./app into the container)\ndocker compose up\n\n# Rebuild after dependency changes\ndocker compose up --build\n\n# Stop and remove containers\ndocker compose down\n```\n\nVisit **http://localhost:8000/docs** after starting.\n\n| File | Purpose |\n|------|---------|\n| `Dockerfile` | Image definition — uv base, prod deps only, `app/` copied in |\n| `docker-compose.yml` | Dev setup — volume mount + `--reload` + env vars |\n| `.dockerignore` | Excludes `learn/`, `tests/`, `.venv`, notebooks from build context |\n\n---\n\n## Tests\n\n```bash\nuv run pytest tests/ -v\n```\n\n| File | Tests |\n|------|-------|\n| `tests/test_myapi.py` | Original student API (reference) |\n| `tests/test_app.py`   | Structured app — Users + Orders full coverage |\n\n---\n\n## uv Cheatsheet\n\n| Task | Command |\n|------|---------|\n| Install / sync all deps | `uv sync` |\n| Run tests | `uv run pytest tests/ -v` |\n| Run the demo app | `uv run uvicorn app.main:app --reload` |\n| Run a teaching file | `uv run uvicorn learn.01_hello_world:app --reload` |\n| Add a dependency | `uv add \u003cpackage\u003e` |\n| Add a dev dependency | `uv add --dev \u003cpackage\u003e` |\n| Remove a dependency | `uv remove \u003cpackage\u003e` |\n| Show installed packages | `uv pip list` |\n\n---\n\n## Reference\n\n- `pyproject.toml` — project manifest and dependency declaration (uv)\n- `uv.lock` — exact lockfile for reproducible installs\n- `myapi.py` — original student CRUD (kept as reference)\n- `docs/Fast API_ Beginner to Intermediate Guide.pdf` — the companion guide\n- FastAPI official docs: https://fastapi.tiangolo.com\n\n---\n\n## Road to Glory — What's Next?\n\nAfter the Starter Kit, explore these advanced topics:\n\n- **Get Modular** — `APIRouter`, bigger app structure (done in `app/`)\n- **DB Connection** — SQLAlchemy / Tortoise ORM (`app/db/db_session.py`)\n- **Dependencies** — auth, DB sessions, rate limiting (see `app/dependencies.py`)\n- **Middleware** — CORS, logging, timing\n- **Security** — OAuth2, JWT, `passlib`\n- **Lifespan Events** — startup/shutdown hooks\n- **Background Tasks** — `BackgroundTasks`\n- **Custom Exception Handling** — global exception handlers\n- **Testing \u0026 CI** — `pytest` + GitHub Actions\n\n\u003e GOAT of all resources: [FastAPI Official Documentation](https://fastapi.tiangolo.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahnaf19%2Flearn_fastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahnaf19%2Flearn_fastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahnaf19%2Flearn_fastapi/lists"}