GithubHelp home page GithubHelp logo

fastapi-pluggable's Introduction

fastapi-pluggable

Make your FastAPI app pluggable with entrypoints.

This module is mainly aimed around monolithic applications where you would install your applications via a package registry, treating each plugin application as a separate repository that imports a core application to use the common functionality like HTML templates, dependencies and more!

Using entry points, we can treat each separate plugin as a separate installable module, here is an example using Poetry with the pyproject.toml,

[tool.poetry.plugins."myapp.plugins"]
plugin_a = 'myapp_plugin_example.main:app'

from fastapi import FastAPI, Request
from pydantic import BaseModel

class Cool(BaseModel):
    yes: bool
    maybe: str

app = FastAPI(root_path="/plugin-a")


@app.get("/hello", response_model=Cool, tags=["Plugin-A"])
async def home(request: Request):
    return Cool(yes=True, maybe="No")

Now we need to ensure we load the plugins for our entrypoint defined in the toml file "myapp.plugins", we can also set a default path for all plugins to be loaded under, here is an example of the core application which will use these plugins.

from fastapi import FastAPI


app = FastAPI()

@app.get("/hello", tags=["Core-App"])
async def hello():
    return "this is the main application ok"


# Register plugins
from fastapi_pluggable import load_plugins

load_plugins(app=app, entrypoint="myapp.plugins", path="/plugins")

Now, plugin-a is reachable via the /plugins/plugin-a endpoint. If you also set merge_docs on the load_plugins function, fastapi_pluggable will attempt to merge the OpenAPI schemas between all the plugins so you can simply visit the /docs endpoint instead of multiple endpoints eg. /docs and /plugins/plugin-a/docs. This is set to False by default so you will have separate plugin openapi schemas unless your plugin disables them when initializing app = FastAPI().

This module is still under heavy work to ensure the best user experience, so expect the logging, openschema merging and some of the other features to not fully work between versions and may even change without backwards compatibility if required. Documentation will also be reworked at some point...

fastapi-pluggable's People

Contributors

bspendlove avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.