Tentacles logo

Tentacles is a python ORM (Objec-Relational Mapper) written in python.

Python ORMs usually try to map SQL syntax with python classes (see django or sqlalchemy samples).
Tentacles is going the opposite direction, trying to express queries in "'python natural language'''.

Declarative part

Objects declarations in Tentacles is looking quite similare to what is done in Django: A class is mapped to a Table in a database (or more generally to a storage unit - think of non-SQL storages, like LDAP or MongoDB); store fields must be expressivly described (with thre type and capabilities)

Example:

from tentacles import Storage, Object, fields, filter
db = Storage('sqlite3::memory:')

class Constructor(Object):
   name   = String()

class Car(Object):
   model         = String()
   power         = Integer()            # in horsepowers
   constructor   = Reference(Power)       # a Car as one unique constructor

Querying part

Tentacles bring to manipulate stored datas as you do for basics python objects. To acheave that goal, Tentacles extend filter and map functions to allow their use with Tentacles objects.

Example:

# get all 'De Dion-Bouton' cars, ordered by model
cars = filter(lambda c: c.constructor.name == 'De Dion-Bouton', Car) >> 'model'

# get 10 first cars having power > 100 hps
cars = filter(lambda c: c.power > 100, Car)[0:10]
<< and >> operators are use to sort results, while brackets are used to limit result size (in the same manner as for a python list)
(NOTE that both are done at SQL level, not on python results)


In conclusion, this short introduction shows you the basic aims and capabilities of this new library. I invite you to download and install Tentacles and play with to discover all its possibilities.