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

add Quart asgi template #1138

Merged
merged 1 commit into from
Jan 17, 2025
Merged

Conversation

sinisaos
Copy link
Member

Adding Quart asgi template. I was able to add a Piccolo admin using Hypercorn DispatcherMiddleware

@dantownsend
Copy link
Member

@sinisaos Interesting - I've been aware of Quart for a long time, but wasn't sure how to mount a third party ASGI app. Congratulations on finding a solution 👏

@sinisaos
Copy link
Member Author

Same thing also works with Sanic. I will create an asgi template for Sanic, but first I need to understand how Pydantic and OpenAPI docs work in Sanic. They say it's automatic, but that's not exactly true because we need to make a lot of decorators for the configuration. I will do my best.

@dantownsend
Copy link
Member

Using the Hypercorn middleware is a nice idea, I wasn't aware it existed.

@sinisaos
Copy link
Member Author

@dantownsend Small offtopic. If you have some time you can check this repo. I made some benchmarks for asgi drivers and ORM's. I'm not a benchmark expert, but benchmarks show that Piccolo has the best performance (by some margin) for reading data than other ORMs. I didn't consider ORM's like Ormar or SQLModel (and many others) because those ORM's are just wrappers around SQLALchemy. Other than that, Piccolo is the easiest to use, easy to configure and set up, and has many great features (still missing unique_constaints, reverse_lookup, but there are PRs for that). I think that is great.

@sinisaos
Copy link
Member Author

Using the Hypercorn middleware is a nice idea, I wasn't aware it existed.

@dantownsend Yes. That feature is really useful and allows us to enable Piccolo Admin for frameworks that don't have asgi app mounting options.

@dantownsend
Copy link
Member

@sinisaos That's good to know, thanks! I did some optimisation work a while ago, but over time the focus has moved to adding features instead of optimisation.

There is probably still lots of room for improvement.

One potential 'cheat' is to use frozen queries:

https://piccolo-orm.readthedocs.io/en/latest/piccolo/query_clauses/freeze.html#freeze

The idea is it makes the performance of some queries closer to just writing raw SQL. In practice it doesn't save that much time, but is useful if a query is run 1000s of times. Again, it's something which could probably be optimised further.

@dantownsend
Copy link
Member

still missing unique_constaints, reverse_lookup, but there are PRs for that

Yes, I do need to get around to testing those. The big PRs are challenging because I need to find a big block of time to properly review and test them. It's also challenging balancing the features which the community needs vs what I need immediately for work. Sometimes it might look like I prioritise random stuff, but it's usually something I need for a project I'm working on.

I think the composite unique constraints one is probably highest priority. I have never actually needed that feature on a project, but I know a lot of people would expect it to exist.

@sinisaos
Copy link
Member Author

No worries. Piccolo already has a lot of cool features, but I see a lot of interest in those two features. A reverse lookup (in some form) would also be valuable in a situation like this where we need one less db query and it affects performance (results have better reqs/s for that endpoint with a reverse lookup).

@sinisaos
Copy link
Member Author

@dantownsend I've created a Sanic asgi template, but I'm having problems with the integration test because our dummy server doesn't start the Sanic app (which throws a Sanic exception Loop can only be retrieved after the app has started running. Not supported with create_server function). I made changes to use Uvicorn as the test server (based on the code found in the Uvicorn tests). Is that okay with you or?

@dantownsend
Copy link
Member

I'm not sure, I haven't experimented with Sanic recently. So you can't just run it with AsyncClient(transport=ASGITransport(app=app))? Does it have its own server or something?

@sinisaos
Copy link
Member Author

Sanic has its own server, but it is also ASGI-compliant and we can use uvicorn and everything works with uvicorn. Only the integration tests don't pass, so I just changed the dummy_server to use uvicorn. I want to know if that's okay with you or if you have a different idea.

@sinisaos sinisaos added the enhancement New feature or request label Jan 14, 2025
@dantownsend
Copy link
Member

This looks good to me, thanks!

@dantownsend dantownsend merged commit 02ef5f5 into piccolo-orm:master Jan 17, 2025
46 checks passed
@dantownsend
Copy link
Member

@sinisaos One potential issue with this, which I only just though of, is the user has to pick Hypercorn as the server. Ideally we would not give them the option to pick a router, and just Hypercorn automatically.

@sinisaos
Copy link
Member Author

One potential issue with this, which I only just though of, is the user has to pick Hypercorn as the server

Sorry for the slow reply, I wasn't home for the weekend. I don't know if I understood correctly (the user does not have to use Hypercorn exclusively). In my case all 3 servers are working fine.

@sinisaos sinisaos deleted the quart_asgi_template branch January 19, 2025 12:35
@dantownsend
Copy link
Member

Ah, ok - I thought it just worked with Hypercorn. I'll give it a go, thanks!

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

Successfully merging this pull request may close these issues.

2 participants