Skip to main content

Django QuerySets that can be Twisted aware. Adds several methods on a custom manager and queryset that return deferreds/coroutine/future.

Project description

Django ORM + Twisted + asyncio - blocking
This is a library that contains a custom queryset and a custom manager that adds introspection to use
the twisted database api instead of django. It returns deferred (Future or coroutine) instead of just hitting the database.

since v0.6:
- added support for django_bulk_update (

since v0.5:
- model instance save method replacing on the fly, now u can:

since v0.3-0.4:
- get_or_create fix

since v0.2:
- mostly rewrited;
- renamed package as "twisted-django-orm";
- python 3.5.2+ now is required;
- used asyncio to avoid "callback hell";
- you still can obtain result as defered;
- there are some untested cases;

To install:
Python 3.5.2+ is required

1. pip install twango
2. Import and set the manager as the manager for any model (see examples)
3. Use it on the top of the twisted and asyncio

This will keep the orm from blocking when using the django orm!

Does not make job in asynchronous way, but goes into threads and do not perform blocking main reactor.

Example 352+:

q = await Operation.twisted.all()[:5].fetch()

b = await Operation.twisted.all().fetch()

async for x in Operation.twisted.all().order_by('cell', 'status'):
print(x.price, x.status, x.cell)

async for x in Operation.twisted.all().order_by('cell', 'status')[:5]:
print(x.price, x.status, x.cell)

x = await Operation.twisted.get(price=3000, status=1, cell=11)

p = await Operation.twisted.count()

x, created = await Operation.twisted.update_or_create(defaults={'cell': 11, 'price': 333}, price=1, status=1, cell=25)

x, _created = await Operation.twisted.get_or_create(price=27, status=1, cell=11)

Example (old):
You can create models that are separate to be used in twisted processes:

from myapp import Book
from twango.manager import TwistedManager
from django.db.models.manager import Manager

class TwistedBook(Book):
objects = Manager()
twisted = TwistedManager()

class Meta:
app_label = 'myapp'
proxy = True

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for djangotworm, version 0.6.1
Filename, size File type Python version Upload date Hashes
Filename, size djangotworm-0.6.1.tar.gz (6.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page