Skip to main content

Blackboard pattern implementation

Project description

===========
gblackboard
===========


.. image:: https://img.shields.io/pypi/v/gblackboard.svg
:target: https://pypi.python.org/pypi/gblackboard

.. image:: https://img.shields.io/travis/GTedHa/gblackboard.svg
:target: https://travis-ci.org/GTedHa/gblackboard

.. image:: https://readthedocs.org/projects/gblackboard/badge/?version=latest
:target: https://gblackboard.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status




Blackboard pattern implementation


* Free software: MIT license
* Documentation: https://gblackboard.readthedocs.io.
* Repository: https://github.com/GTedHa/gblackboard


Features
-------

* To be updated
* Refer to 'Usage'


Usage
-------

To use gblackboard in a project:

- basic usage::

from gblackboard import Blackboard
from gblackboard import SupportedMemoryType

blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
# setup blackboard, it should be called once before using blackboard
blackboard.setup()
# set a key-value data; `set` method should be called only once for a key.
# it's a kind of initialization.
# supported data-type: int, int[], float, float[], str, str[], dict, dict[]
blackboard.set('key', 'value')
# retrieve data with key
value = blackboard.get('key')
# update data with new value;
# `update` method should be called after `set` method called for a key.
blackboard.update('key', 'new_value')
# delete data from blackboard with key
blackboard.drop('key')
# clear all data in blackboard
blackboard.clear()

- observer::

from gblackboard import Blackboard
from gblackboard import SupportedMemoryType

def callback(data):
print(data)

blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
blackboard.setup()
blackboard.set('key', 'value')
# register callback
blackboard.register_callback('key', callback)
# update data, `callback` function will be called during `update`
# and `new_value` will passed to `callback` function.
blackboard.update('key', 'new_value')

- complex data::

from gblackboard import Blackboard
from gblackboard import SupportedMemoryType

from marshmallow import Schema, fields, post_load
import datetime as dt

class User(object):

def __init__(self, name, email):
self.name = name
self.email = email
self.created_at = dt.datetime.now()

def __repr__(self):
return '<User(name={self.name!r})>'.format(self=self)

class UserSchema(Schema):

name = fields.Str()
email = fields.Email()
created_at = fields.DateTime()

@post_load
def make_user(self, data):
return User(data['name'], data['email'])

blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
blackboard.setup()

# with marshmallow Scheme, you can also handle complex python objects.
blackboard.set('user',
User("G.Ted", "gted221@gmail.com"),
scheme_cls=UserScheme
)
user = blackboard.get('user')
print(user)
# <User(name='G.Ted')> will be printed

# list of complex objects is also supported.
blackboard.set('users',
[
User("User1", "user1@gblackboard.com"),
User("User2", "user2@gblackboard.com"),
],
scheme_cls=UserScheme
)
users = blackboard.get('users')
print(users)
# [<User(name='User1')>, <User(name='User2')>] will be printed.


TODO
-------

* Export blackboard in JSON format
* Save blackboard contents
* Validation for Redis configurations
* Print blackboard contents for debugging


Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


=======
History
=======

0.1.0 (2019-01-24)
------------------

* First commit on GitHub.


0.1.1 (2019-01-30)
------------------

* Add fakeredis for test


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gblackboard-0.1.1.tar.gz (22.5 kB view hashes)

Uploaded Source

Built Distribution

gblackboard-0.1.1-py2.py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page