Documentation: | http://packages.python.org/python-stdnet/ |
---|---|
Dowloads: | http://pypi.python.org/pypi/python-stdnet/ |
Source: | http://code.google.com/p/python-stdnet/ |
Keywords: | server, database, cache, redis, orm |
--
An object relational mapper fro remote data structures.
The data is owned by different, configurable back-end databases and it is accessed using a light-weight Object Relational Mapper (ORM) inspired by Django and SQLAlchemy. The source code is hosted at google code while Documentation and Downloads are available via PyPi.
To install, download, uncompress and type:
python setup.py install
otherwise use easy_install
:
easy_install python-stdnet
or pip
:
pip install python-stdnet
To know whech version you have installed:
>>> import stdnet >>> stdnet.__version__ '0.3.2'
At the moment, only redis back-end is available, so to run tests you need to install redis. Once done that, launch redis and type:
>>> import stdnet >>> stdnet.runtests()
otherwise from the package directory:
python runtests.py
Running tests with the above commands assumes your Redis server is running on the same machine.
StdNet comes with two default settings.
>>> from stdnet.conf import settings >>> settings.__dict__ {'DEFAULT_BACKEND': 'redis://127.0.0.1:6379/?db=7', 'DEFAULT_KEYPREFIX': 'stdnet'}
If your redis server runs on a different machine, you need to setup a script file along these lines:
if __name__ == '__main__': from stdnet.conf import settings settings.DEFAULT_BACKEND = 'redis://your.server.url:6379/?db=10' import stdnet stdnet.runtests()
Backend data-stores provide the backbone of the library, while the Object Relational Mapper the syntactic sugar. Currently the list of back-ends is limited to
- Redis. Requires redis-py.
- Local memory (planned). For testing purposes.
- CouchDB (planned). Requires couchdb-python.
Only Redis is operational.
The module stdnet.orm
is a lightweight ORM:
from stdnet import orm class Base(orm.StdModel): name = orm.SymbolField(unique = True) ccy = orm.SymbolField() def __str__(self): return str(self.name) class Meta: abstract = True class Instrument(Base): type = orm.SymbolField() class Fund(Base): description = orm.CharField() class PositionDescriptor(orm.StdModel): dt = orm.DateField() size = orm.FloatField() price = orm.FloatField() position = orm.ForeignKey("Position") class Position(orm.StdModel): instrument = orm.ForeignKey(Instrument, related_name = 'positions') fund = orm.ForeignKey(Fund) history = orm.ListField(model = PositionDescriptor) def __str__(self): return '%s: %s @ %s' % (self.fund,self.instrument,self.dt)
Register models with backend:
orm.register(Instrument,'redis://localhost/?db=1') orm.register(Fund,'redis://localhost/?db=1') orm.register(PositionDescriptor,'redis://localhost/?db=2') orm.register(Position,'redis://localhost/?db=2')
And play with the API:
>>> f = Fund(name="pluto,description="The super pluto fund",ccy="EUR").save() Fund: pluto
This software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text.