rethinkModel Module

class rethinkORM.rethinkModel.RethinkModel(id=False, **kwargs)[source]

Emulates a python object for the data which is returned from rethinkdb and the official Python client driver. Raw data from the database is stored in _data to keep the objects namespace clean. For more information look at how _get() and _set() function in order to keep the namespace cleaner but still provide easy access to data.

This object has a __repr__ method which can be used with print or logging statements. It will give the id and a representation of the internal _data dict for debugging purposes.

table = ''

The table which this document object will be stored in

primaryKey = 'id'

The current primary key of the table

durability = 'soft'

Can either be Hard or Soft, and is passed to RethinkDB

non_atomic = False

Determins if the transaction can be non atomic or not

upsert = True

Will either update, or create a new object if true and a primary key is given.

__init__(id=False, **kwargs)[source]

Initializes the main object, if id is in kwargs, then we assume this is already in the database, and will try to pull its data, if not, then we assume this is a new entry that will be inserted.

(Optional, only if not using .repl()) conn or connection can also be passed, which will be used in all the .run() clauses.


A hook called at the end of the main __init__ to allow for custom inherited classes to customize their init process without having to redo all of the existing int. This should accept nothing besides self and nothing should be returned.


Deletes the given item from the objects _data dict, or if from the objects namespace, if it does not exist in _data.


Allows for the use of syntax similar to:

if "blah" in model:

This only works with the internal _data, and does not include other properties in the objects namepsace.

classmethod new(**kwargs)[source]

Creates a new instance, filling out the models data with the keyword arguments passed, so long as those keywords are not in the protected items array.

classmethod create(id=None, **kwargs)[source]

Similar to new() however this calls save() on the object before returning it.

classmethod find(id)[source]

Loads an existing entry if one can be found, otherwise an exception is raised.

Parameters:id (Str) – The id of the given entry
Returns:cls instance of the given id entry

If an id exists in the database, we assume we’ll update it, and if not then we’ll insert it. This could be a problem with creating your own id’s on new objects, however luckily, we keep track of if this is a new object through a private _new variable, and use that to determine if we insert or update.


Deletes the current instance. This assumes that we know what we’re doing, and have a primary key in our data already. If this is a new instance, then we’ll let the user know with an Exception


Allows for the representation of the object, for debugging purposes


Provides a cleaner interface to dynamically add items to the models list of protected functions to not store in the database

rethinkCollection Module

class rethinkORM.rethinkCollection.RethinkCollection(model, filter=None)[source]

A way to fetch groupings of documents that meet a criteria and have them in an iterable storage object, with each document represented by RethinkModel objects

__init__(model, filter=None)[source]

Instantiates a new collection, using the given models table, and wrapping all documents with the given model.

Filter can be a dictionary or lambda, similar to the filters for the RethinkDB drivers filters.

joinOn(model, onIndex)[source]

Performs an eqJoin on with the given model. The resulting join will be accessible through the models name.

joinOnAs(model, onIndex, whatAs)[source]

Like joinOn but allows setting the joined results name to access it from.

Performs an eqJoin on with the given model. The resulting join will be accessible through the given name.

orderBy(field, direct='desc')[source]

Allows for the results to be ordered by a specific field. If given, direction can be set with passing an additional argument in the form of “asc” or “desc”


Fetches the query and then tries to wrap the data in the model, joining as needed, if applicable.

Table Of Contents

Previous topic


Next topic


This Page