Skip to main content

ORM for Redis

Project description

PyPI Version Build Status


Redis-astra is Python light ORM for Redis.

Note: version 2 has uncomportable changes with version 1. See CHANGELOG.txt


import redis
from astra import models

db = redis.StrictRedis(host='', decode_responses=True)

class SiteObject(models.Model):
    def get_db(self):
        return db

    name = models.CharHash()

class UserObject(models.Model):
    def get_db(self):
        return db

    name = models.CharHash()
    login = models.CharHash()
    site = models.ForeignKey(to=SiteObject)
    sites_list = models.List(to=SiteObject)
    viewers = models.IntegerField()

    def save(self, action, attr=None, value=None):
        print('\t * %s' % kwargs)

So you can use it like this:

>>> user = UserObject(pk=1, name="Mike", viewers=5)
    * {'action': 'post_init', 'value': {'name': 'Mike', 'viewers': 5}}
>>> user.login = ''
    * {'action': 'pre_assign', 'attr': 'login', 'value': ''}
        * {'action': 'post_assign', 'attr': 'login', 'value': ''}
>>> user.login
>>> user.viewers_incr(2)
>>> site = SiteObject(pk=1, name="")
>>> = site
    * {'attr': 'site', 'action': 'm2m_link', 'value': <Model SiteObject(pk=1)>}
>>> user.sites_list.lpush(site, site, site)
>>> len(user.sites_list)
>>> user.sites_list[2].name
>>> = None
        * {'attr': 'site', 'action': 'm2m_remove'}
>>> user.remove()
    * {'action': 'pre_remove', 'attr': 'pk', 'value': '1'}
    * {'action': 'post_remove', 'attr': 'pk', 'value': '1'}


Python versions 2.6, 2.7, 3.3, 3.4, 3.5 are supported Redis-py versions >= 2.9.1

pip install redis-astra

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 redis-astra, version 2.0.0
Filename, size File type Python version Upload date Hashes
Filename, size (12.0 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