Wallace wraps database adapters for easy connection handling and data modeling in Python apps. We extend the enterprise libraries but do not override or replace their functionality, so performance profiles etc. remain intact. Major features include:
- Databases: Currently supports PostgreSQL (psycopg), Redis (redispy), and MongoDB (pymongo). More to come
- Modeling: A bare-bones ORM, built around a consistent type interface to model attributes across backends. Use of the ORM is optional, other database and config utilities can be used without it.
- Caching: Automatic connection pool sharing - set it and forget it
To spin up a Postgres connection pool, pass DNS connection info and an optional min/max number of connections:
>>> from wallace import PostgresPool
>>> dns = {'host': '/tmp/', 'database': 'postgres', 'user': 'postgres', 'password': ''}
>>> pool = PostgresPool.construct(**dns) # defaults to max 1 connection in the pool
>>>
>>> # or, specifying a max pool size:
>>> pool = PostgresPool.construct(maxconn=5, **dns)
>>>
>>> # name the connection if you would like to cache it
>>> pool = PostgresPool.construct(name='my_db', **dns)
To use the standard interface, wrap a table:
And create a model to plug the table like so:
>>> from wallace import PostgresModel, String
>>> class User(PostgresModel):
>>> table = UserTable
>>> name = String()
>>> email = String(pk=True) # primary key field
>>>
>>> # models may be used to retrieve existing records,
>>> u = User.fetch(email='bdfl@python.org')
>>> u.name
'guido'
>>>
>>> # create new ones,
>>> newguy = User.construct(name='spacemanspiff', email='spaceman@spiff.com')
>>> newguy.push()
>>>
>>> # and execute searches
>>> [u.email for u in User.find_all(name='spacemanspiff')]
['spaceman@spiff.com']
'push' to update a model:
'delete' to delete:
pip install wallace
to install the latest stable release.
Code, tutorials, and documentation for wallace are all open source under the BSD license.
Enjoy your data.