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.0.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.0-py3-none-any.whl (734.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: remit_service-1.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 7cc29a7e1026a76164770c175772b51b4df6cc96de4fdfdb1a1840cb87657db6
MD5 f10daf1d317dd21270a3cf847035c6ab
BLAKE2b-256 178ad8fd16e539d95c43078ce36c83956b7a179beb2aa3860189fbec948aea49

See more details on using hashes here.

File details

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

File metadata

  • Download URL: remit_service-1.3.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98e9eba206f472df66978829cc97f99359121153d7c709eba352bc5d8252218d
MD5 13157bdc0b2911dd2c42714ad1fbe03d
BLAKE2b-256 32de92977dc43e032b0528a60fc65daab72dc94e9e2e6d19bb0fbb813e682675

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