Skip to content

Instantly share code, notes, and snippets.

@azhannnnn
Created March 29, 2025 06:50

Django ORM Async Read Support – GSoC 2025 Proposal

1. Motivation

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.

1.1. Why Focus on Read Operations?

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.


2. Proposal: Async Read Methods for Django ORM

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.

2.1. Example Usage

Synchronous (current approach)
def get_user():
    user = User.objects.get(id=1)
    return user
Asynchronous (proposed approach)
async def get_user():
    user = await User.objects.aget(id=1)
    return user

2.2. Supported ORM Methods

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

3. Scope & Deliverables

The project will be structured in three phases over 12 weeks.

Phase 1: Research & Design (Week 1-3)

📌 Study Django ORM’s sync internals.
📌 Analyze existing async ORM discussions in Django community.
📌 Design an incremental implementation strategy for async reads.

Phase 2: Implementation & Testing (Week 4-9)

✅ Implement async support for aget(), acount(), aexists(), etc.
✅ Write unit tests for async methods.
✅ Ensure compatibility with existing Django models.

Phase 3: Documentation & Finalization (Week 10-12)

📌 Write detailed Django documentation for async ORM.
📌 Get community feedback and refine code.
📌 Submit a pull request to Django for review.


4. Expected Challenges & Solutions

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

5. Benefits to the Django Community

🔹 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.


6. About Me

👋 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. 😊


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment