Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Object-data mapper and advanced query manager for non relational databases
Python Lua Shell

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
docs
examples
lib
stdnet
tests
.coveragerc
.gitignore
CHANGELOG.rst
LICENSE
MANIFEST.in
README.rst
TODO
clean.py
index.html
luatests.lua
runtests.py
setup.py

README.rst

A stand-alone Python 3 compatible data manager for Redis 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) with API inspired by SQLAlchemy and Django. The source code and documentation are hosted at github while Downloads are available via PyPi.

--

Documentation:http://lsbardel.github.com/python-stdnet/
Dowloads:http://pypi.python.org/pypi/python-stdnet/
Source:https://github.com/lsbardel/python-stdnet
Issues:https://github.com/lsbardel/python-stdnet/issues
Mailing List:https://groups.google.com/group/python-stdnet
Keywords:server, database, cache, redis, orm

Requirements

  • Python 2.6 to Python 3.3. Single codebase.
  • Optional Cython for faster redis protocol parser.
  • You need access to a Redis server.

Philosophy

Key-valued pairs databases have many differences from traditional relational databases, most important being they do not use SQL as their query language, storage does not require a fixed table schemas and usually they do not support complex queries.

StdNet aims to accommodate a flexible schema and join type operations via a lightweight object relational mapper. Importantly, it is designed with large data sets in mind. You pull data you need, nothing more, nothing less. Bandwidth and server round-trips can be reduced to the bare minimum so that your application is fast and memory efficient.

Installing

To install, download, uncompress and type:

python setup.py install

otherwise use easy_install:

easy_install python-stdnet

or pip:

pip install python-stdnet

Documentation

StdNet uses Sphinx for its documentation, and the latest is available at GitHub:

Version Check

To know which version you have installed:

>>> import stdnet
>>> stdnet.__version__
'0.7.0'

Running Tests

At the moment, only redis back-end is available and therefore to run tests you need to install Redis. If you are using linux, it can be achieved simply by downloading, uncompressing and running make, if you are using windows and want to save yourself a headache you can download precompiled binaries at servicestack.

Requirements for running tests

Note, these requirements are only needed if you are planning to run tests.

Testing

To run tests open a shell and launch Redis. On another shell, from the package directory, type:

python runtests.py

Tests are run against a local redis server on port 6379 and database 7 by default. To change the server and database where to run tests pass the --server option as follow:

python runtests.py --server redis://myserver.com:6450/?db=12

For more information type:

python runtests.py -h

To access coverage of tests you need to install the coverage package and run the tests using:

coverage run runtests.py

and to check out the coverage report:

coverage html

Backends

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.
  • Local memory (planned). For testing purposes.

Only Redis is operational.

Object Relational Mapper

The module stdnet.orm is the ORM, it maps python object into database data. It is design to be fast and safe to use:

from stdnet import orm

class Base(orm.StdModel):
    '''An abstract model. This won't have any data in the database.'''
    # A unique symbol field, a symbol is an immutable string
    name = orm.SymbolField(unique = True)
    # Another symbol, symbol fields are by default indexes
    ccy  = orm.SymbolField()

    def __str__(self):
        return str(self.name)

    class Meta:
        abstract = True


class Instrument(Base):
    itype = orm.SymbolField()


class Fund(Base):
        # A char field is a string and it is never an index
    description = orm.CharField()


class PositionDescriptor(orm.StdModel):
    dt    = orm.DateField()
    # A float field is not an index by default
    size  = orm.FloatField()
    price = orm.FloatField()
    # A FK field which we explicitly set as non-index
    position = orm.ForeignKey("Position", index = False)


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

Kudos

  • Redis simply because this library uses its awesome features.
  • redis-py for the Redis Python client initial implementation which has been subsequently modified.
  • hiredis-py for some parts of the C parser.
  • SQLAlchemy and Django for ideas and API design.
  • Armin Ronacher and Ask Solem for the celery sphinx theme used for the documentation.

Contributing

Development of stdnet happens at Github: http://github.com/lsbardel/python-stdnet

We very much welcome your contribution of course. To do so, simply follow these guidelines:

  1. Fork python-stdnet on github
  2. Create a topic branch git checkout -b my_branch
  3. Push to your branch git push origin my_branch
  4. Create an issue at https://github.com/lsbardel/python-stdnet/issues with a link to your patch

Licence

This software is licensed under the New BSD License. See the LICENSE file in the top distribution directory for the full license text.

Something went wrong with that request. Please try again.