skip to navigation
skip to content

Not Logged In

autumn2 0.6.8.2

Lightweight python ORM (Object-relational mapper).

Latest Version: 0.6.9.5

Autumn exists as a super-lightweight Object-relational mapper (ORM) for Python. Autumn ORM follows the KISS principle. 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), and minimal size. Autumn as small as possible.

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

This project is currently considered beta software.

PostgreSQL Example

Using these tables:

CREATE TABLE autumn_tests_models_author (
    id serial NOT NULL PRIMARY KEY,
    first_name VARCHAR(40) NOT NULL,
    last_name VARCHAR(40) NOT NULL,
    bio TEXT
);
CREATE TABLE books (
    id serial NOT NULL PRIMARY KEY,
    title VARCHAR(255),
    author_id integer REFERENCES autumn_tests_models_author(id) ON DELETE CASCADE
);

Put in your PYTHONPATH file autumn_settings.py with your settings. See file autumn/settings.py for more details.

You can also set the settings directly:

import autumn.settings
autumn.settings.DATABASES = {
    'default': {
        'engine': "postgresql",
        'user': "devel",
        'database': "devel_autumn",
        'password': "devel",
        'debug': True,
        'initial_sql': "SET NAMES 'UTF8';",
        'thread_safe': True,
    }
}

We setup our objects like so:

from autumn.model import Model, ForeignKey, OneToMany

class Author(Model):

    class Meta:
        defaults = {'bio': 'No bio available'}
        validations = {'first_name': (
            lambda v: len(v) > 1 or "Too short first name",
            lambda self, key, value: value != self.last_name or "Please, enter another first name",
        )}

class Book(Model):
    author = ForeignKey(Author, related_name='books')

    class Meta:
        db_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()

SQLBuilder integration

ta = Author.s
tb = Book.s
qs = tb.qs

object_list = qs.tables(
    qs.tables() & ta.on(tb.author_id == ta.id)
).where(
    (ta.first_name != 'James') & (ta.last_name != 'Joyce')
)[:10]

QuerySet based on sqlbuilder.smartsql, see more info.

Signals support

  • pre_init
  • post_init
  • pre_save
  • post_save
  • pre_delete
  • post_delete
  • class_prepared

Web

You can use Autumn ORM with lightweight web-frameworks, like wheezy.web, Bottle, Tornado, pysi, etc.

Gratitude

 
File Type Py Version Uploaded on Size
autumn2-0.6.8.2.tar.gz (md5) Source 2013-12-08 15KB
  • Downloads (All Versions):
  • 53 downloads in the last day
  • 497 downloads in the last week
  • 2162 downloads in the last month