Django Async ORM

It’s been a while I’m writing wrappers for django orm features, but at some point I was really tired because it’s really ugly to have tons of imports like this :

from utils.wrappers import async_render, async_modelform_is_valid, \
    async_get_or_create_model, async_save_model_instance, async_user_is_authenticated, async_login, async_logout, \
    async_get_model, async_get_twitch_engine, async_add_event_subscription_to_twitch_account, \
    async_first_twitchaccount_set, async_delete_model_instance, async_get_config, async_user_is_superuser, async_all_event_subscriptions, async_queryset_to_list

from asgiref.sync import sync_to_async, async_to_sync

So what I decided to do is to write a Django module (app) that will patch all available models and add async capabilities. : django-async-orm · PyPI

The manager now have methods prefixed with async_ I couldn’t decide to have a different manager or namespace. but after watching Andew’s Talk decided to follow the namespacing.

here is an example:

async def my_view(request):
    obj = await MyModel.objects.async_get(name='something')
    ...

I also added some wrappers for template rendering and form validation and iterating on QuerySet.

now there still a lot of work, for example anything related to methods from Models directly like Model.save() , delete() etc …

feel free to test it and create an issue, Django ORM is big and I certainly can’t cover all use cases.

1 Like

Just wanted to link a related thread here : Asynchronous ORM

1 Like