{"id":16200390,"url":"https://github.com/andfanilo/fastapi-techtalk-livedemo","last_synced_at":"2026-05-09T16:02:40.896Z","repository":{"id":99876095,"uuid":"343148260","full_name":"andfanilo/fastapi-techtalk-livedemo","owner":"andfanilo","description":"FastAPI livecode session for meetups/tech talks ","archived":false,"fork":false,"pushed_at":"2021-02-28T16:09:35.000Z","size":1,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-13T19:52:14.518Z","etag":null,"topics":["api","fastapi","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/andfanilo.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":"2021-02-28T16:07:56.000Z","updated_at":"2021-02-28T16:10:38.000Z","dependencies_parsed_at":"2023-05-10T21:00:15.007Z","dependency_job_id":null,"html_url":"https://github.com/andfanilo/fastapi-techtalk-livedemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andfanilo%2Ffastapi-techtalk-livedemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andfanilo%2Ffastapi-techtalk-livedemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andfanilo%2Ffastapi-techtalk-livedemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andfanilo%2Ffastapi-techtalk-livedemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andfanilo","download_url":"https://codeload.github.com/andfanilo/fastapi-techtalk-livedemo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704515,"owners_count":20982292,"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":["api","fastapi","python"],"created_at":"2024-10-10T09:30:10.396Z","updated_at":"2025-10-29T13:02:51.891Z","avatar_url":"https://github.com/andfanilo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FastAPI Live Demo\n\n## Prerequisites\n\n```\nconda create -n fastapi python=3.7\nconda activate fastapi\npip install fastapi pytest\n```\n\n## Run\n\n```\nuvicorn app:app --reload\n```\n\n## Demo steps\n\n### Part 1 - First steps \n\n- Create empty `app.py`\n- Open terminal with `CTRL + SHIFT + ù`. Run `uvicorn app:app --reload`\n- Open `http://localhost:8000` and `http://localhost:8000/docs`\n- Enter some code in `app.py`: \n\n```python\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef get_status():\n    return {\"Hello\": \"World\"}\n```\n- Check browser and docs. Change name of function and see interactive docs change.\n\n### Part 2 - Static type hints\n\n- Add some code \n\n```python\n@app.get(\"/items/{item_id}\")\ndef read_item(item_id, q = None):\n    return {\"item_id\": item_id, \"q\": q}\n```\n    - see now `item_id` is required\n\n- Use static hints\n\n```python\nfrom typing import Optional \n@app.get(\"/items/{item_id}\")\ndef read_item(item_id: int, q: Optional[str] = None):\n    return {\"item_id\": item_id, \"q\": q}\n```\n    - see in docs that typings have changed\n\n- Use modern Python type declarations with Pydantic\n\n```python\nfrom typing import List, Dict\nfrom datetime import date\n\nfrom pydantic import BaseModel\n\n# A Pydantic model\nclass User(BaseModel):\n    id: int\n    name: str\n    joined: date\n\n@app.post(\"/users\")\ndef get_user(user: User):\n    return user.name\n```\n- showoff type inference/autocompletion on `user.name` in editor\n\n- Reformat code with Black: `black app.py`\n\n### Part 3 - Unit testing\n\n```python\nfrom fastapi.testclient import TestClient\nfrom app import app\n\nclient = TestClient(app)\n\ndef test_get_status():\n    response = client.get(\"/\")\n    assert response.status_code == 200\n    assert response.json() == {\"Hello\": \"World\"}\n\ndef test_post_user():\n    response = client.post(\"/users\", json={\n        \"id\": 4,\n        \"name\": \"Mary\",\n        \"joined\": \"2018-11-30\",\n    })\n    assert response.status_code == 200\n    assert response.json() == \"Mary\"\n```\n\n- Run with `pytest test_app.py`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandfanilo%2Ffastapi-techtalk-livedemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandfanilo%2Ffastapi-techtalk-livedemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandfanilo%2Ffastapi-techtalk-livedemo/lists"}