扩展Fastapi的微服务框架, 支持 Class Route、Class View、配置注入装饰器
Project description
remit-service
remit-service是基于FastApi框架扩展出支持多配置文件、配置注入的框架
- 类试图
- 类路由
- 蓝图路由
- 服务管理
- 多配置文件
- 配置注入
配置介绍
单体项目配置文件介绍
所有的配置都是已yaml支持
主配置文件project/resources/config.yaml
resources文件目录这是必须存在的, 这是存储资源文件的必须目录, 加载配置文件首先会定位resources目录
config:
# 激活环境, 获取ENV环境变量,如果不存在赋值env
active: !env ${ENV, dev}
环境配置文件project/resources/config.dev.yaml
service:
ip: 0.0.0.0 # 项目启动ID
port: 9045 # 项目启动端口
service_name: test # 服务启动名称
多服务项目配置文件介绍
主配置文件project/resources/config.yaml
config:
# 激活环境, 获取ENV环境变量,如果不存在赋值env
active: !env ${ENV, dev}
# 跟随启动服务的配置文件
include: !config ${service:True}
- include:引入配置文件
!config ${service:True}: 加载当前启动服务的配置文件
服务配置文件project/a_service/resources/config.dev.yaml
service:
ip: 0.0.0.0 # 项目启动ID
port: 9045 # 项目启动端口
service_name: a # 服务启动名称
项目启动
定义视图
视图文件project/view/a.py
from remin_service.base.controller import Controller, RequestGet
@Controller(prefix="", tags=["测试接口"])
class DocsView:
@RequestGet(path="/a")
async def get_documentation(
self,
):
pass
路由注册project/init_router.py
from remin_service.base.load_router import register_nestable_blueprint_for_log
def init_routes(fastapi_app):
# 此处必须用__name__, 否则会自动引入两次
register_nestable_blueprint_for_log(
fastapi_app, __name__, api_name='a'
)
项目启动文件project/main.py
import os
import uvicorn
from remin_service.app import FastSkeletonApp
from init_router import init_routes
resources_path = os.path.dirname(__file__)
app = FastSkeletonApp(
init_routes,
__file__,
resources_path=resources_path
).app
if __name__ == '__main__':
if __name__ == '__main__':
uvicorn.run(app=app, host=app.HOST, port=app.PORT)
配置注入
视图文件project/a_service/resources/config.dev.yaml
service:
ip: 0.0.0.0 # 项目启动ID
port: 9045 # 项目启动端口
service_name: a # 服务启动名称
test:
a: a
b: b
注入文件project/**/config.py
from pydantic import BaseModel
from remin_service.config import ImportConfig
@ImportConfig("test")
class Test(BaseModel):
a: str
b: str
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file remit_service-1.2.8.tar.gz.
File metadata
- Download URL: remit_service-1.2.8.tar.gz
- Upload date:
- Size: 729.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a73a0d0913e6b41147480b382c7ec84808555985afd9a0a3272640f919fa1df7
|
|
| MD5 |
1a3216208133eb0a557c91d6d54e89ac
|
|
| BLAKE2b-256 |
86701f145a9191863a9e0491edcc7a5f19fec276d8edc7be26ab464011cd7fc1
|
File details
Details for the file remit_service-1.2.8-py3-none-any.whl.
File metadata
- Download URL: remit_service-1.2.8-py3-none-any.whl
- Upload date:
- Size: 734.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dac7815ec3bae38513791164182fadc38ec1431e7187ba41dc8cc48baaa634bd
|
|
| MD5 |
f2f9a4f4d79af71d5b2263be54253f8d
|
|
| BLAKE2b-256 |
7c1487764a2c250f7203dad9fe90cfe79fa44733d2166393b415faf94eb564bd
|