Skip to content

Commit

Permalink
Fixed lint call and added example.
Browse files Browse the repository at this point in the history
  • Loading branch information
bujniewicz committed Oct 30, 2015
1 parent cf9ceae commit 71d04b2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -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
43 changes: 42 additions & 1 deletion README.md
Expand Up @@ -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
---------------------
Expand All @@ -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
```
38 changes: 38 additions & 0 deletions 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
Expand Down

0 comments on commit 71d04b2

Please sign in to comment.