Skip to main content
Help us improve Python packaging – donate today!

ORM for Redis

Project Description

PyPI Version Build Status

redis-astra

Redis-astra is Python light ORM for Redis.

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

Example:

import redis
from astra import models

db = redis.StrictRedis(host='127.0.0.1', 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 = 'mike@null.com'
    * {'action': 'pre_assign', 'attr': 'login', 'value': 'mike@null.com'}
        * {'action': 'post_assign', 'attr': 'login', 'value': 'mike@null.com'}
>>> user.login
'mike@null.com'
>>> user.viewers_incr(2)
7
>>> site = SiteObject(pk=1, name="redis.io")
>>> user.site = site
    * {'attr': 'site', 'action': 'm2m_link', 'value': <Model SiteObject(pk=1)>}
>>> user.sites_list.lpush(site, site, site)
3
>>> len(user.sites_list)
3
>>> user.sites_list[2].name
'redis.io'
>>> user.site = None
        * {'attr': 'site', 'action': 'm2m_remove'}
>>> user.remove()
    * {'action': 'pre_remove', 'attr': 'pk', 'value': '1'}
    * {'action': 'post_remove', 'attr': 'pk', 'value': '1'}

Install

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

pip install redis-astra

Release history Release notifications

This version
History Node

2.0.0

History Node

1.0.7

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

0.6.4

History Node

0.4.5

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
redis-astra-2.0.0.zip (12.0 kB) Copy SHA256 hash SHA256 Source None Mar 27, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page