Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App factory #338

Closed
ZeN220 opened this issue Jun 27, 2024 · 1 comment
Closed

App factory #338

ZeN220 opened this issue Jun 27, 2024 · 1 comment

Comments

@ZeN220
Copy link

ZeN220 commented Jun 27, 2024

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
Copy link
Member

gi0baro commented Jun 29, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants