• This repository has been archived on 03/Sep/2021
  • Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created about 14 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Twistar is an object-relational mapper (ORM) for Python that uses the Twisted library to provide asynchronous DB interaction.

twistar: Asynchronous Python ORM

Build Status Coverage Status

The Twistar Project provides an ActiveRecord (ORM) pattern interface to the Twisted Project's RDBMS library. This file contains minimal documentation - see the project home page at http://findingscience.com/twistar for more information.

Installation

pip install twistar

Usage

Your database must be one of: MySQL, PostgreSQL, or SQLite. The only DBAPI modules supported by Twistar are: MySQLdb, psycopg2, and sqlite3 - at least one of these must be installed.

Here's the obligatory TL;DR example of creating a User record, assuming that there is a table named "users" with varchar columns for first_name and last_name and an int age column:

#!/usr/bin/env python
from twisted.enterprise import adbapi
from twistar.registry import Registry
from twistar.dbobject import DBObject
from twisted.internet import reactor

class User(DBObject):
     pass

def done(user):
     print "A user was just created with the name %s" % user.first_name
     reactor.stop()

# Connect to the DB
Registry.DBPOOL = adbapi.ConnectionPool('MySQLdb', user="twistar", passwd="apass", db="twistar")

# make a user
u = User()
u.first_name = "John"
u.last_name = "Smith"
u.age = 25

# Or, use this shorter version:
u = User(first_name="John", last_name="Smith", age=25)

# save the user
u.save().addCallback(done)

reactor.run()

Then, finding this user is easy:

def found(users):
    print "I found %i users!" % len(users)
    for user in users:
        print "User: %s %s" % (user.first_name, user.last_name)

u = User.findBy(first_name="John", age=25).addCallback(found)

This is a very simple example - see http://findingscience.com/twistar for more complicated examples and additional uses.

Testing

To run unit-tests you simply require Tox

To run the tests:

tox

By default, the tests are run with the database driver sqlite3. To change this, set the DBTYPE environment variable:

DBTYPE=postgres trial twistar
DBTYPE=mysql trial twistar

You'll need a database named "twistar" for each of those tests (or you can change the dbname, user, etc in the <db type>_config.py file in the tests folder).

Documentation

If you intent on generating API documentation, you will need pydoctor. If you want to generate the user documentation, you will need to install Twisted Lore.

To generate documentation:

make docs

Then open the docs/index.html file in a browser.

More Repositories

1

kademlia

A DHT in Python using asyncio
Python
791
star
2

gender_detector

Get gender from first name in Ruby.
Ruby
422
star
3

bandit

A multi-armed bandit optimization framework for Rails
Ruby
129
star
4

ankusa

Text classifier in Ruby that uses Hadoop/HBase, Mongo, or Cassandra for storage. New location for http://github.com/livingsocial/ankusa
Ruby
100
star
5

rpcudp

Python library for RPC over UDP
Python
89
star
6

mod_auth_openid

mod_auth_openid is an authentication module for the Apache 2 webserver. It handles the functions of an OpenID consumer as specified in the OpenID 2.0 specification.
C++
74
star
7

arrow

Date interaction for Golang, with strftime formatting for time
Go
41
star
8

hbaserb

HBase Thrift interface for Ruby
Ruby
34
star
9

gatling_gun

A Ruby library wrapping SendGrid's Newsletter API.
Ruby
33
star
10

pundit-elixir

Simple authorization helpers for Elixir stucts, like Ruby's Pundit
Elixir
29
star
11

abanalyzer

A/B test analysis library for Ruby - performs Chi-Square tests and G-tests on A/B results - New location for https://github.com/livingsocial/abanalyzer
Ruby
29
star
12

fastimage

Python library that finds the size / type of an image given its URI by fetching as little as needed
Python
28
star
13

StactiveRecord

StactiveRecord is a C++ ORM library designed to make simple database use as simple as possible. It was inspired by Ruby on Rail's Active Record, however, no similar look, feel, or performance is guaranteed. It uses an Object-relational mapping pattern to represent records as objects. It also provides persistent object relationships (one to many, many to many, one to one).
C++
26
star
14

pymur

pymur is a Python interface to The Lemur Toolkit.
C++
19
star
15

fake

Make Python's Fabric act like Ruby's Capistrano
Python
19
star
16

telemetry_metrics_cloudwatch

Provides an AWS CloudFront reporter for Elixir Telemetry.Metrics definitions
Elixir
19
star
17

robostrippy

Python lib to strip websites. Like a robot.
Python
17
star
18

campfirer

Jabber to Campfire gateway
Python
13
star
19

imgproxy

Elixir module to generate imgproxy URLs
Elixir
12
star
20

genderator

A Python library to determine gender based on first name, with i18n support.
Python
12
star
21

toquen

Capistrano + AWS + Chef-Zero
Ruby
11
star
22

gridcli

A command line client for The Grid
Ruby
11
star
23

txyam

Yet Another Memcached (YAM) client for Python Twisted
Python
10
star
24

endon

ActiveRecord type helpers for Elixir's Ecto 3+
Elixir
8
star
25

hubot-aws-sesame

Hubot script to open/close AWS EC2 ports automagically based on chat presence
CoffeeScript
8
star
26

readembedability

Turn unstructured webpages into structured content. Readability + oembed
Python
6
star
27

pubsub.in

Async pubsub broker between twitter/xmpp/email/identi.ca/sms/etc using Python's Twisted
Python
5
star
28

aioipfs-api

IPFS API Bindings for Python 3 using asyncio
Python
5
star
29

clive

Clojure library for interacting with Hive via Thrift
Clojure
4
star
30

pubsubd

Distributed PubSub using Node.js
JavaScript
3
star
31

SassyPy

More featureful CSV handling
Python
3
star
32

aws-sesame

node package to open/close access to servers on AWS by IP like a boss
CoffeeScript
3
star
33

configulator

Generate config files from a template
Ruby
2
star
34

debmeo

oEmbed for Python3
Python
2
star
35

grid-plugin-echo

An example plugin for the grid
Ruby
2
star
36

txairbrake

Report exceptions in Twisted code to an airbrake server
Python
2
star
37

doop

A Hadoop command line utility that acts like a shell.
Shell
2
star
38

ex_aws_s3_crypto

AWS S3 client-side encryption support for Elixir
Elixir
2
star
39

twistler

Controller class extensions for Divmod's Nevow
Python
2
star
40

bizratr

Synthesize business information from many sources
Ruby
1
star
41

Sane.R

A library for making R act sane.
R
1
star
42

robostrippure

Clojure lib to strip websites. Like a robot.
Clojure
1
star
43

blobber

A program that tracks points of light (lasers, LEDs) and projects reactions. The results range from graffiti to various games.
C++
1
star
44

dorsey

A microframework for Go. There are many like it, but this one is mine.
Go
1
star
45

onionvpn

Docker image for a OpenVPN => Tor gateway
Shell
1
star
46

gossipr

Jabber chatroom logger (logs XMPP MUC rooms and provides web interface) using Python Twisted
JavaScript
1
star
47

bmuller.github.io

HTML
1
star
48

oper8r

DEPRECATED - See https://github.com/bmuller/toquen
Ruby
1
star
49

txque

Python library for running asynchronous background jobs using Twisted
Python
1
star
50

grid-plugin-osx-notifier

OSX notifier for new message on the grid http://griddoor.com
Ruby
1
star