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

.. 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



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.2.2.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

gblackboard-0.2.2-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gblackboard-0.2.2.tar.gz.

File metadata

  • Download URL: gblackboard-0.2.2.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for gblackboard-0.2.2.tar.gz
Algorithm Hash digest
SHA256 16d1d7006c6126c18d1457d3bc6d475b3058f8522bf0d5b618c834ce7b23d9a2
MD5 9813867b722482bb65b93446eeb7b1b2
BLAKE2b-256 ec09ffb3a1ebfe02f2f8219f34b6f8b93fd9014b8fc62453741e7673d6a13b5b

See more details on using hashes here.

File details

Details for the file gblackboard-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: gblackboard-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for gblackboard-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 359e86fc010fe528602169b7b96ca3234fab706602a12ae801cb60ce0eef61db
MD5 6f950e375458f696340eb35096070e45
BLAKE2b-256 b2716f16bcbf3c948f9c2ecc29eb8443920a8231c3aa69ee0201c2512424f499

See more details on using hashes here.

Supported by

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