Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 autumn
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 MANIFEST.in
Octocat-spinner-32 PKG-INFO
Octocat-spinner-32 README.markdown
Octocat-spinner-32 setup.py
README.markdown

Autumn, a Python ORM

Autumn exists as a super-lightweight Object-relational mapper (ORM) for Python. It’s an alternative to SQLObject, SQLAlchemy, Storm, etc. Perhaps the biggest difference is the automatic population of fields as attributes (see the example below).

It is released under the MIT License (see LICENSE file for details).

This project is currently considered beta software.

MySQL Example

Using these tables:

DROP TABLE IF EXISTS author;
CREATE TABLE author (
    id INT(11) NOT NULL auto_increment,
    first_name VARCHAR(40) NOT NULL,
    last_name VARCHAR(40) NOT NULL,
    bio TEXT,
    PRIMARY KEY (id)
);
DROP TABLE IF EXISTS books;
CREATE TABLE books (
    id INT(11) NOT NULL auto_increment,
    title VARCHAR(255),
    author_id INT(11),
    FOREIGN KEY (author_id) REFERENCES author(id),
    PRIMARY KEY (id)
);

We setup our objects like so:

from autumn.db.connection import db
from autumn.model import Model
from autumn.db.relations import ForeignKey, OneToMany
import datetime

db.connect('mysql', user='root', db='mydatabase')

class Author(Model):
    books = OneToMany('Book')

    class Meta:
        defaults = {'bio': 'No bio available'}
        validations = {'first_name': lambda self, v: len(v) > 1}

class Book(Model):
    author = ForeignKey(Author)

    class Meta:
        table = 'books'

Now we can create, retrieve, update and delete entries in our database. Creation

james = Author(first_name='James', last_name='Joyce')
james.save()

u = Book(title='Ulysses', author_id=james.id)
u.save()

Retrieval

a = Author.get(1)
a.first_name # James
a.books      # Returns list of author's books

# Returns a list, using LIMIT based on slice
a = Author.get()[:10]   # LIMIT 0, 10
a = Author.get()[20:30] # LIMIT 20, 10

Updating

a = Author.get(1)
a.bio = 'What a crazy guy! Hard to read but... wow!'
a.save()

Deleting

a.delete()
Something went wrong with that request. Please try again.