{"id":20673010,"url":"https://github.com/relph1119/fastapi-learning-notes","last_synced_at":"2025-09-27T02:30:54.704Z","repository":{"id":203049448,"uuid":"708673904","full_name":"Relph1119/fastapi-learning-notes","owner":"Relph1119","description":"《利用FastAPI构建Python微服务》学习笔记","archived":false,"fork":false,"pushed_at":"2023-11-17T02:35:50.000Z","size":18774,"stargazers_count":33,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T18:48:47.865Z","etag":null,"topics":["fastapi"],"latest_commit_sha":null,"homepage":"https://relph1119.github.io/fastapi-learning-notes/#/","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/Relph1119.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}},"created_at":"2023-10-23T06:45:38.000Z","updated_at":"2025-04-02T14:56:59.000Z","dependencies_parsed_at":"2023-11-17T04:15:50.221Z","dependency_job_id":null,"html_url":"https://github.com/Relph1119/fastapi-learning-notes","commit_stats":null,"previous_names":["relph1119/fastapi-learning-notes"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Relph1119/fastapi-learning-notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relph1119%2Ffastapi-learning-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relph1119%2Ffastapi-learning-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relph1119%2Ffastapi-learning-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relph1119%2Ffastapi-learning-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Relph1119","download_url":"https://codeload.github.com/Relph1119/fastapi-learning-notes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Relph1119%2Ffastapi-learning-notes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277171412,"owners_count":25773208,"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-09-27T02:00:08.978Z","response_time":73,"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":["fastapi"],"created_at":"2024-11-16T20:39:47.222Z","updated_at":"2025-09-27T02:30:49.695Z","avatar_url":"https://github.com/Relph1119.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 《利用FastAPI构建Python微服务》学习笔记\n\n本书主要从FastAPI核心功能出发，结合后端项目介绍各组件使用，包括： \n1. 熟悉FastAPI初始化及配置，并了解HTTP的8个方法的构建，详细介绍了`@app`的装饰器使用，以及FastAPI的路径参数、查询参数、默认参数、可选参数、请求正文、请求头、响应数据等。\n2. 结合智能旅游系统项目，探索核心功能，包含API服务的实现、注册router、状态响应码、异常处理、转换JSON兼容的对象、后台任务埋点、日志管理等。\n3. 结合在线食谱系统，了解依赖注入原理，包含依赖函数和可调用类的注入、缓存依赖项以及注入依赖项的方法，还可以采用第三方容器`Dependency Inject`和`Lagom`。\n4. 结合大学企业资源计划系统，采用子域分解方式，构建教师、图书馆和学生管理模块，结合领域模型，实现微服务应用程序，其中包括子模块的挂载、异常处理、集中日志记录、配置管理等。\n5. 结合健身俱乐部管理系统，介绍使用`SQLAlchemy`创建CRUD事务，使用多种ORM框架（Pony ORM、Peewee）构建存储库层，还介绍了CQRS设计模式，分离查询事务与命令事务（插入、更新、删除）\n6. 结合在线图书转售系统，介绍使用`PyMongo`、`Motor`创建CRUD事务，比较`MongoEngine`、`Beanie`、`ODMantic`和`MongoFrames`的功能，其中`Beanie`是`Motor`的升级版，`ODMantic`是`Motor`和`Pydantic`的组合版，创建异步CRUD时，可以使用`ODMantic`框架，创建同步CRUD时，可以使用`MongoFrames`框架。\n7. 结合安全的在线拍卖系统，介绍身份验证和授权管理，身份验证包含`Basic`和`Digest`两个基础的身份验证、基于`OAuth2`的密码身份验证、`JWT`的`token`密钥验证，授权管理包括基于作用域的授权、`OAuth2AuthorizationCodeBearer`的授权码流，并和`Keycloak`、`Auth0`、`Okta`等系统集成，完成身份和用户管理。\n8. 结合在线报纸管理系统，介绍协程和异步后台任务的创建与使用，并了解`Celery`任务，使用`RabbitMQ`或`Kafka`发布和订阅消息。还通过`rx`包介绍反应式编程范式。\n9. 结合在线餐厅评论系统，介绍一些FastAPI高级功能，包括基于`request.session`的会话管理、使用`CORSMiddleware`的CORS解决方案、自定义`APIRoute`和`Request`解决数据正文的加解密，还介绍了响应的选择、OpenAPI 3.x规范，以及使用pytest进行API端点测试。\n10. 结合定期普查和计算系统的基本框架，介绍Piccolo ORM框架，使用`sympy`、`numpy`、`pandas`和`scipy`进行数据处理与统计分析，并通过Celery模拟BPMN工作流，还介绍了Neo4j数据库的集成。\n11. 结合在线体育管理系统，介绍基于`starlette-exporter`的API服务监控、基于`opentelemetry-exporter-jaeger`的服务跟踪、基于`py_eureka_client`的服务注册和发现，还对Docker部署、Flask和Django子应用的集成进行了讲解。\n\n建议学习时长：6天\n\n原书项目地址：https://github.com/PacktPublishing/Building-Python-Microservices-with-FastAPI\n\n## 在线阅读地址\n在线阅读地址：https://relph1119.github.io/fastapi-learning-notes\n\n## 项目结构\n\u003cpre\u003e\ndocs---------------------------------------学习笔记\ncodes--------------------------------------代码练习\n+---ch01---------------------------------------第1章 设置FastAPI\n+---ch02---------------------------------------第2章 探索核心功能\n+---ch03---------------------------------------第3章 依赖注入研究\n+---ch04---------------------------------------第4章 构建微服务应用程序\n+---ch05---------------------------------------第5章 连接到关系数据库\n+---ch06---------------------------------------第6章 使用非关系数据库\n+---ch07---------------------------------------第7章 保护REST API的安全\n+---ch08---------------------------------------第8章 创建协程、事件和消息驱动的事务\n+---ch09---------------------------------------第9章 利用其他高级功能\n+---ch10---------------------------------------第10章 解决数值、符号和图形问题\n+---ch11---------------------------------------第11章 添加其他微服务功能\nrequirements.txt---------------------------运行环境依赖包\n\u003c/pre\u003e\n\n## 环境安装\n### Python版本\nPython 3.10 Windows环境\n\n### 运行环境配置\n安装相关的依赖包\n```shell\npip install -r requirements.txt\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelph1119%2Ffastapi-learning-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frelph1119%2Ffastapi-learning-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelph1119%2Ffastapi-learning-notes/lists"}