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

A Redis object mapper for Python

Project Description

Rom - the Redis object mapper for Python

Copyright 2013 Josiah Carlson

Released under the LGPL license.

What

Rom is a package whose purpose is to offer active-record style data modeling within Redis from Python, similar to the semantics of Django ORM, SQLAlchemy + Elixir, Google’s Appengine datastore, and others.

Why

I was building a personal project, wanted to use Redis to store some of my data, but didn’t want to hack it poorly. I looked at the existing Redis object mappers available in Python, but didn’t like the features and functionality offered.

What is available

Data types:

  • Strings, ints, floats, decimals
  • Json columns (for nested structures)
  • OneToMany and ManyToOne columns (for model references)

Indexes:

  • Numeric range fetches, searches, and ordering
  • Full-word text search (find me entries with col X having words A and B)

Other features:

  • Per-thread entity cache (to minimize round-trips, easy saving of all entities)

Getting started

  1. Make sure you have Python 2.6 or 2.7 installed

  2. Make sure that you have Andy McCurdy’s Redis library installed: https://github.com/andymccurdy/redis-py/ or https://pypi.python.org/pypi/redis

  3. (optional) Make sure that you have the hiredis library installed for Python

  4. Make sure that you have a Redis server installed and available remotely

  5. Update the Redis connection settings for rom via rom.util.set_connection_settings() (other connection update options, including per-model connections, can be read about in the rom.util documentation):

    import redis
    from rom import util
    
    util.set_connection_settings(host='myhost', db=7)
    

Warning

If you forget to update the connection function, rom will attempt to connect to localhost:6379 .

  1. Create a model:

    class User(Model):
        email_address = String(required=True, unique=True)
        salt = String()
        hash = String()
        created_at = Float(default=time.time)
    
  2. Create an instance of the model and save it:

    PASSES = 32768
    def gen_hash(password, salt=None):
        salt = salt or os.urandom(16)
        comp = salt + password
        out = sha256(comp).digest()
        for i in xrange(PASSES-1):
            out = sha256(out + comp).digest()
        return salt, out
    
    user = User(email_address='user@host.com')
    user.salt, user.hash = gen_hash(password)
    user.save()
    # session.commit() or session.flush() works too
    
  3. Load and use the object later:

    user = User.get_by(email_address='user@host.com')
    

Release history Release notifications

History Node

0.42.0

History Node

0.41.2

History Node

0.41.1

History Node

0.41.0

History Node

0.40.2

History Node

0.40.1

History Node

0.40.0

History Node

0.39.5

History Node

0.39.4

History Node

0.39.3

History Node

0.39.2

History Node

0.39.1

History Node

0.39.0

History Node

0.38.1

History Node

0.38.0

History Node

0.37.3

History Node

0.37.2

History Node

0.37.1

History Node

0.37.0

History Node

0.36.0

History Node

0.35.3

History Node

0.35.2

History Node

0.35.1

History Node

0.35.0

History Node

0.34.1

History Node

0.34.0

History Node

0.33.0

History Node

0.32.2

History Node

0.32.1

History Node

0.32.0

History Node

0.31.4

History Node

0.31.3

History Node

0.31.2

History Node

0.31.1

History Node

0.31.0

History Node

0.30.1

History Node

0.30.0

History Node

0.29.5

History Node

0.29.4

History Node

0.29.3

History Node

0.29.2

History Node

0.29.0

History Node

0.28.0

History Node

0.27.0

History Node

0.26.5

History Node

0.26.4

History Node

0.26.3

History Node

0.26.2

History Node

0.26.1

History Node

0.26.0

History Node

0.25.1

History Node

0.25.0

History Node

0.22

History Node

0.21

History Node

0.20

History Node

0.19

History Node

0.18

History Node

0.17

History Node

0.16

This version
History Node

0.15

History Node

0.14

History Node

0.13

History Node

0.12

History Node

0.10

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
rom-0.15.tar.gz (19.3 kB) Copy SHA256 hash SHA256 Source None Jun 20, 2013

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