An ActiveRecord ORM for Python


The Orator ORM provides a simple yet beautiful ActiveRecord implementation.

class Dream(Model):
    Think big...

    def you(self):
        return Dreamer
from orator import Model, SoftDeletes

class User(SoftDeletes, Model):

    __fillable__ = ['name', 'email']

    def posts(self):
        return Post
ActiveRecord at hand

A Beautiful ORM

The Orator ORM is based on conventions to avoid the hassle of defining every single aspect of your models.

Relationships are also a breeze to setup.

Write beautiful code

Expressive Syntax

Write readable and expressive code using the ORM or the low-level Query Builder.

And if it's not enough, you can use raw queries.

user = User.where('name', 'John').first() = 'Simon'

# Eager load relationships
post = Post.with_('comments').first()
for comment in post.comments:

# Use the query builder directly
db.table('users').insert(name="Cleo", email='')
Manipulate your databases schemas

A Schema Builder

With the Orator Schema Builder, manipulating your databases schemas has never been so easy.

It gives you all the tools to make all the operations you might possibly need on you databases.

with schema.create('users') as table:
    # Add an autoincrementing primary key

    # Add a unique "name" column
    table.string('name', 128).unique()

    # Add a "votes" column with default value to 0

    # Add "created_at" and "updated_at" timestamp columns

~/apps $ orator migrations:make create_users_table
✓ Migration created successfully!

~/apps $ orator migrations:run --seed
✓ Migrated 2015_01_12_000000_create_users_table
✓ Migrated 2015_01_12_100000_create_posts_table
✓ Migrated 2015_01_13_162500_create_comments_table
✓ Migrated 2015_01_13_162508_create_roles_table
Keep your databases in sync


Orator supports Migrations out of the box. Keep a trace of databases modifications with migrations files.

Reset and rebuild your database to start fresh.

Model Events

Hook into your models' livecycle with a simple events system.

Stop actions based on conditions.

User.saving(lambda user: user.is_valid())

Easily paginate your query results with the integrated paginators.

Almost every queries can be paginated.

User.where('votes', '>', 7).paginate(15, 2)

Models and Collections can be automatically converted to a JSON representation.

Attributes can be hidden, casted or appended