gblackboard 0.2.2
Blackboard pattern implementation
License: MIT license
Keywords: gblackboard

===========
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::

.. code-block:: python

    from gblackboard import Blackboard
    from gblackboard import SupportedMemoryType

    blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
    # Set a key-value data;
    # `set` method should be called only once for a key.
    # It's a kind of initialization for data.
    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::

.. code-block:: python

    from gblackboard import Blackboard
    from gblackboard import SupportedMemoryType

    def callback(data):
        print(data)

    blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
    blackboard.set('key', 'value')
    # Register `callback` function as a 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::

.. code-block:: python

    from gblackboard import Blackboard
    from gblackboard import SupportedMemoryType

    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)

    blackboard = Blackboard(SupportedMemoryType.DICTIONARY)

    # You can also store customized class objects in blackboard.
    blackboard.set('user', User("G.Ted", "gted221@gmail.com"))
    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"),
        ]
    )
    users = blackboard.get('users')
    print(users)
    # [<User(name='User1')>, <User(name='User2')>] will be printed.


- save & load::

.. code-block:: python

    from gblackboard import Blackboard
    from gblackboard import SupportedMemoryType

    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)

    blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
    # Store sample data
    blackboard.set('user', User("G.Ted", "gted221@gmail.com"))
    # Save current blackboard contents as file.
    blackboard.save()
    # Close current blackboard;
    # this means clear all data in blackboard
    blackboard.close()
    # ------------------------------------------------------------
    blackboard = Blackboard(SupportedMemoryType.DICTIONARY)
    # Load saved blackboard contents from files.
    blackboard.load()
    user = blackboard.get('user')
    print(user)
    # <User(name='G.Ted')> will be printed.


TODO
-------

* `Save & Load` on subprocess
* 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


0.2.0 (2019-02-16)
------------------

* Eliminates the limitations of supported data types.
* Change object serialization method for storing data from JSON serialization method using marshmallow (external)
  library to serialization method using pickle library.
* Replace CRUD methods of redis with Hash-CRUD methods
    - set(key, value) -> hset('gblackboard', key, value)
    - get(key)        -> hget('gblackboard', key)
    - delete(key)     -> hdel('gblackboard', key)
    - exists(key)     -> hexists('gblackboard', key)
* Remove useless setup() step and mem_ready status
* Add raise_conn_error (raise 'connection error') decorator for RedisWrapper CRUD methods
* Add save & load features