Can we make synchronous queries with Beanie?

404 views Asked by At

I'm developing a webserver using FastAPI, Beanie and Celery. The asynchronous nature of the ODM is userful when writing routers, however there are places where it is not required. For example, in a celery task I don't need to make asynchronous database calls.

Is there a way to make synchronous queries with Beanie?

I'm forced to wrap my celery task code in an async function and run it with asyncio.

1

There are 1 answers

0
sorenlittle On

Check out bunnet!

It is a completely synchronous ODM developed and maintained by the same author as beanie.

See this excerpt of the beanie documentation:

Beanie - is an asynchronous Python object-document mapper (ODM) for MongoDB. Data models are based on Pydantic. [...] There is a synchronous version of Beanie ODM - Bunnet