Django introduced async capabilities in recent versions, but most ORM operations remain synchronous. This limits Django’s efficiency when handling high-concurrency applications such as real-time web apps, chat applications, and dashboards.
To improve Django’s async compatibility, I propose adding async support for read operations in Django ORM.
✅ Achievable within 12 weeks – Writing async queries is easier than updating ORM internals for writes.
✅ High impact – Many applications perform more reads than writes.
✅ Backward compatibility – Async reads won’t break existing sync-based projects.
✅ Performance boost – Async reads reduce bottlenecks in API-heavy Django applications.
This project will introduce async alternatives for Django ORM’s read operations:
await Model.objects.aget(pk=1)
– Retrieve a single object asynchronously.async for obj in Model.objects.all():
– Iterate over querysets asynchronously.await Model.objects.acount()
– Get the count of records without blocking the main thread.
def get_user():
user = User.objects.get(id=1)
return user
async def get_user():
user = await User.objects.aget(id=1)
return user
Method | Async Alternative | Description |
---|---|---|
get() |
aget() |
Fetch a single object |
count() |
acount() |
Get count of objects |
exists() |
aexists() |
Check if records exist |
first() |
afirst() |
Get the first record |
last() |
alast() |
Get the last record |
Queryset Iteration | async for obj in queryset: |
Async iteration |
The project will be structured in three phases over 12 weeks.
📌 Study Django ORM’s sync internals.
📌 Analyze existing async ORM discussions in Django community.
📌 Design an incremental implementation strategy for async reads.
✅ Implement async support for aget()
, acount()
, aexists()
, etc.
✅ Write unit tests for async methods.
✅ Ensure compatibility with existing Django models.
📌 Write detailed Django documentation for async ORM.
📌 Get community feedback and refine code.
📌 Submit a pull request to Django for review.
Challenge | Proposed Solution |
---|---|
ORM heavily depends on sync execution | Implement async methods separately while maintaining backward compatibility |
Database drivers may lack async support | Use async-compatible database drivers like asyncpg for PostgreSQL |
Ensuring smooth integration with Django’s ORM API | Follow Django’s existing API structure and async implementation in views/middleware |
🔹 Improves Django’s async compatibility, making it a better fit for modern web apps.
🔹 Reduces response time in high-concurrency scenarios.
🔹 Encourages more async-first Django projects, aligning with frameworks like FastAPI.
👋 Name: Azhan Khan
🎓 Background: Final-year B.Tech CSE student
💻 Experience: 2+ years working with Django, FastAPI, Python, Frappe
🔗 GitHub: github.com/azhannnnn
🌍 Portfolio: azhanfolio.pythonanywhere.com
I’m excited about contributing to Django’s future and making async ORM a reality! Looking forward to feedback and mentorship. 😊