Skip to main content

扩展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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

remit_service-1.3.1.tar.gz (729.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remit_service-1.3.1-py3-none-any.whl (734.4 kB view details)

Uploaded Python 3

File details

Details for the file remit_service-1.3.1.tar.gz.

File metadata

  • Download URL: remit_service-1.3.1.tar.gz
  • Upload date:
  • Size: 729.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for remit_service-1.3.1.tar.gz
Algorithm Hash digest
SHA256 a7dfc2096e0928d39d9725e0a043262767c715b67fbcaa5d6d3f8cc31520c8c6
MD5 a647247ecf351ef42798ca9c8eba4039
BLAKE2b-256 bd3c85cb9d920af7117f3641622d8cb6b1896cf55bfe2c6b741491ba9e4e70c6

See more details on using hashes here.

File details

Details for the file remit_service-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: remit_service-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 734.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.16

File hashes

Hashes for remit_service-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 714d1822fc821698caa0b60e0af1b0fcf47d9d2aea4e2415c25ecdba5b643fb9
MD5 27e8251e9e36865283d606a0236a2f92
BLAKE2b-256 be19144e7837a62ba1234c0f9a478b6426c828b5dfcd518f2c3cc4e6f5612a8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page