emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.67k stars 79 forks source link

App factory #338

Closed ZeN220 closed 3 months ago

ZeN220 commented 3 months ago

I didn't find any functionality similar to --factory from uvicorn. are there any plans to add such a thing? something like that:

def create_app():
    app = MyAPP()
    return app

And running like this:

granian "module:create_app()"
gi0baro commented 3 months ago

As of today, there's no support for this in CLI. But you can run Granian via Python code and customise the target_loader parameter of Granian.serve.

Given your use-case, probably it's easier to write a run.py file which runs the factory, eg:

from your_module import your_factory

app = your_factory()

and point Granian to run:app. It might also be worth checking #35.