piccolo_admin icon indicating copy to clipboard operation
piccolo_admin copied to clipboard

Is here a granian support?

Open Forceres opened this issue 1 year ago • 7 comments

Does piccolo admin support granian instead of uvicorn? Piccolo CLI gives only 2 options: uvicorn and hypercorn

Forceres avatar Jun 28 '24 22:06 Forceres

I haven't tried granian, but it should work - it supports ASGI apps.

We could add it as an option to piccolo asgi new. We would have to copy this code:

https://github.com/emmett-framework/granian/blob/de03e2c3f5f81b3372cac788bcff22d4471c1656/granian/cli.py#L251-L298

To here:

https://github.com/piccolo-orm/piccolo/blob/master/piccolo/apps/asgi/commands/templates/app/main.py.jinja

dantownsend avatar Jun 29 '24 10:06 dantownsend

@dantownsend I just tried granian and the settings are pretty similar to uvicorn. We just need to add this to main.py.jinja

if __name__ == "__main__":
    ... # previous code
    {% elif server == 'granian' %}
    import granian

    granian.Granian("app:app", interface="asgi", reload=True).serve()
    {% endif %}

and this in new.py

SERVERS = ["uvicorn", "Hypercorn", "granian"]

and everything works.

sinisaos avatar Jul 01 '24 09:07 sinisaos

@sinisaos Interesting - that's much simpler than I imagined. If you have time, can you create a PR and I'll merge it in?

dantownsend avatar Jul 01 '24 11:07 dantownsend

@dantownsend PR is not a problem, but something is strange to me. The suggested code works in an old (not fresh) env where uvicorn is already used (and I just replace the uvicorn code with granian suggested code in main.py). But if I use a fresh env (or clear browser cache), Piccolo Admin doesn't work (FastAPI docs do). Then I found this issue with Starlette that describes the problem. I won't be doing PR for now. I'm sorry I didn't check it before, but I wasn't aware of that problem because everything worked in the old env when uvicorn was first used. Sorry again.

sinisaos avatar Jul 01 '24 13:07 sinisaos

@sinisaos No worries. I wasn't aware of the path send extension, but here are some docs for reference:

https://asgi.readthedocs.io/en/latest/extensions.html#path-send

dantownsend avatar Jul 01 '24 13:07 dantownsend

@dantownsend Just for info, I tried patching Starlette with this PR (from the author of granian) and everything works. If that PR would merge, we can add granian support with the code suggested earlier.

sinisaos avatar Jul 01 '24 15:07 sinisaos

@sinisaos Thanks - that PR looks close to completion, so fingers crossed.

dantownsend avatar Jul 01 '24 15:07 dantownsend

jfyi, starlette 0.38.1 was just released with pathsend support removed. Given you rely on FastAPI, you should wait for them to bump the Starlette dependency; with that Granian should work fine.

gi0baro avatar Jul 23 '24 10:07 gi0baro

@gi0baro thanks for info.

sinisaos avatar Jul 23 '24 10:07 sinisaos