A functional reactive graph database backed by PostgreSQL
In layman's terms, OpenARC lets you build graphs of objects that react to one another.
OpenARC requires Python 3+ and PostgreSQL 10+.
Consult your operating system documentation for details on how to install these requirements.
Use pip
to install the last release:
pip install openarc --user
Live on the edge by cloning our repository:
git clone https://www.github.com/kchoudhu/openarc
cd openarc
pip install . --user
If you don't already have a database to point to, you can use the makefile to spin up your own local instance to work with:
cd openarc
make dbmshardinit
OpenARC follows the XDG specification, and looks for openarc.conf
in the following locations:
XDG_CONFIG_HOME
$HOME/.config/
/usr/local/etc/
An annotated sample openarc.conf
is available in the cfg
directory of the project distribution.
Start by importing the library and defining an OAG class:
class OAG_User(OAG_RootNode):
@staticproperty
def context(cls): return "myproject"
@staticproperty
def streams(cls): return {
'username' : [ 'text', str(), None ],
'password' : [ 'text', str(), None ]
}
new_user =\
OAG_User(initprms={
'username' : 'kamil',
'password' : 'hunter2'
})
print(new_user.username)
# Output: kamil
Persist to the database:
new_user.db.create()
This creates a table in the database:
> select * from myproject.user;
_user_id | password | username
----------+----------+----------
1 | hunter2 | kamil
Update the object:
new_user[0].username = 'hana'
new_user.db.update()
The database is updated accordingly:
> select * from myproject.user;
_user_id | password | username
----------+----------+----------
1 | hunter2 | hana
More documentation about the database capabilities of OpenARC is available here.
An OAG_Group
is a collection of users:
class OAG_Group(OAG_RootNode):
@staticproperty
def context(cls): return "myproject"
@staticproperty
def streams(cls): return {
'user' : [ OAG_User, False, "user_update_handler" ]
}
def user_update_handler(self):
print("[user_update_handler] User [%s] has been updated" % self.user.username)
group = OAG_Group()
group.user = new_user
An event dependency is created between group
and new_user
by assigning the latter to the former under group
's user
node.
user_update_handler
is an event handler that is invoked whenever the user
node of the OAG_Group object is changed:
new_user.password = '*****'
# [user_update_handler] User [hana] has been updated
Nodes can be nested arbitrarily, permitting complex functional event chains. Think Excel, but for programmers.
If you have the project distribution, take a look under openarc/tests
for a wide variety of use cases. Assuming your environment is set up, you can execute the tests by executing
make test
Interesting examples of OpenARC usage live under openarc/examples
. Each example is thoroughly documented and comes with a README; the hope is that they will open your eyes as to what is possible with OpenARC.
Documentation is distributed with the code, and can be generated by executing
make docs