diff --git a/.travis.yml b/.travis.yml index debfce0..485e319 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,6 @@ python: - "pypy" script: # need to skip pylint on 3.5 since it doesn't work yet. - - if [[ $TRAVIS_PYTHON_VERSION != '3.5' ]]; then pylint devourer --rcfile=.pylintrc; fi + - if [[ $TRAVIS_PYTHON_VERSION != '3.5' ]]; then pylint basilisk --rcfile=.pylintrc; fi - coverage run --source=basilisk -m basilisk.tests && coverage report -m - cd docs && make html \ No newline at end of file diff --git a/README.md b/README.md index 28a4746..171e219 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,54 @@ Basilisk Basilisk is a object-NoSQL mapper for Python 2.7 and 3.3+, supporting models, lists, hashes and sorted sets. +A simple example: + +```python +import basilisk + +basilisk.Config.load(redis={'host': 'localhost', + 'port': 6379, + 'db': 0, + 'max_connections': 10}, + elastic={}) + + +class Item(basilisk.RedisModel): + id = basilisk.MapField(key=True) + name = basilisk.MapField() + content = basilisk.MapField() + attachments = basilisk.JsonMapField() + + @classmethod + def select(cls): + redis_items = basilisk.RedisList('items') + variables = basilisk.RedisHash('items_variables') + last_modified = int(variables['last_modified'] or 0) + + if (not len(redis_items) or + not last_modified or + last_modified + 30 < time.time()): + items = DownloadNewItemsFromDatabase(last_modified) + for item in items: + redis_items.append(item.id) + variables['last_modified'] = int(time.time()) + variables.save() + return list(redis_items) + +items = Item.select() +for item in items: + print(Item.get(item).content) +``` + Installation ------------ +You can just `pip install basilisk`. Documentation ------------- Feel free to browse the code and especially the tests to see what's going on behind the scenes. +The current verson of Sphinx docs is always on http://basiliskpy.readthedocs.org/en/latest/ Questions and contact --------------------- @@ -29,7 +70,7 @@ We use Travis CI. The targets are 10.00 for lint 10.00 and 100% for coverage, as You can of also check the build manually, just make sure to `pip install -r requirements.txt` before: ``` -pylint devourer --rcfile=.pylintrc +pylint basilisk --rcfile=.pylintrc coverage run --source=basilisk -m basilisk.tests && coverage report -m cd docs && make html ``` \ No newline at end of file diff --git a/basilisk/__init__.py b/basilisk/__init__.py index 3c6ae92..141ba82 100644 --- a/basilisk/__init__.py +++ b/basilisk/__init__.py @@ -1,6 +1,44 @@ """ Basilisk enables Pythonic use of Redis hashes, lists and sorted sets with simple class interface as well as provides an ORM Model-like class using Redis hash or Elasticsearch inside. + +A simple example: + +>>> import basilisk +>>> +>>> basilisk.Config.load(redis={'host': 'localhost', +>>> 'port': 6379, +>>> 'db': 0, +>>> 'max_connections': 10}, +>>> elastic={}) +>>> +>>> +>>> class Item(basilisk.RedisModel): +>>> id = basilisk.MapField(key=True) +>>> name = basilisk.MapField() +>>> content = basilisk.MapField() +>>> attachments = basilisk.JsonMapField() +>>> +>>> @classmethod +>>> def select(cls): +>>> redis_items = basilisk.RedisList('items') +>>> variables = basilisk.RedisHash('items_variables') +>>> last_modified = int(variables['last_modified'] or 0) +>>> +>>> if (not len(redis_items) or +>>> not last_modified or +>>> last_modified + 30 < time.time()): +>>> items = DownloadNewItemsFromDatabase(last_modified) +>>> for item in items: +>>> redis_items.append(item.id) +>>> variables['last_modified'] = int(time.time()) +>>> variables.save() +>>> return list(redis_items) +>>> +>>> items = Item.select() +>>> for item in items: +>>> print(Item.get(item).content) + """ from .fields import MapField, JsonMapField from .redis_entities import RedisModel, RedisList, RedisHash, RedisSortedSet, RedisModelException