Skip to content

A low-effort, fully asynchronous ORM for Django applications, powered by Tortoise ORM under the hood.

License

Notifications You must be signed in to change notification settings

efe/django-raphael

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-raphael

A low-effort, fully asynchronous ORM for Django applications, powered by Tortoise ORM under the hood. (draft)

Why?

Django’s async ORM currently runs asynchronous calls in a separate thread, which introduces a performance difference compared to a fully asynchronous ORM. django-raphael provides a bridge between Django models and a fully async ORM like Tortoise ORM, enabling developers to use async database operations without redefining models and while maintaining synchronization.

Usage

# books/models.py
from django_raphael.models import RaphaelMixin

class Book(RaphaelMixin, models.Model):
    title = models.CharField(max_length=200)
    author = models.CharField(max_length=100)
# books/views.py

async def retrieve_book(request, id: int):
    book = await Book.aobjects.get(id=id)
    return JsonResponse({
        "id": book.id,
        "title": book.title,
        "author": book.author,
    })

async def create_book(request):
    book = await Book.aobjects.create(
        title=request.body.get("title"),
        author=request.body.get("author"),
    )

    return JsonResponse({
        "id": book.id,
        "title": book.title,
        "author": book.author,
    }, status=201)
  • book.aobjects returns the Tortoise ORM model.

"raphael?"

Tortoise ORM does its thing behind the scenes and it reminds me of the Ninja Turtles. Raphael, the hot-headed one, feels like the perfect spirit animal for async Python’s feel.

About

A low-effort, fully asynchronous ORM for Django applications, powered by Tortoise ORM under the hood.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published