awaredb 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- awaredb-0.1.0/AwareDB/__init__.py +1 -0
- awaredb-0.1.0/AwareDB/api.py +282 -0
- awaredb-0.1.0/AwareDB.egg-info/PKG-INFO +21 -0
- awaredb-0.1.0/AwareDB.egg-info/SOURCES.txt +18 -0
- awaredb-0.1.0/AwareDB.egg-info/dependency_links.txt +1 -0
- awaredb-0.1.0/AwareDB.egg-info/requires.txt +1 -0
- awaredb-0.1.0/AwareDB.egg-info/top_level.txt +1 -0
- awaredb-0.1.0/LICENSE +21 -0
- awaredb-0.1.0/PKG-INFO +21 -0
- awaredb-0.1.0/README.md +362 -0
- awaredb-0.1.0/setup.cfg +7 -0
- awaredb-0.1.0/setup.py +29 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .api import AwareDB
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any, Dict, List, Union
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AwareDB:
|
|
9
|
+
"""
|
|
10
|
+
Python API to interact with AwareDB.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
# pylint: disable=too-many-arguments
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
db: str,
|
|
17
|
+
token=None,
|
|
18
|
+
user: str = None,
|
|
19
|
+
password: str = None,
|
|
20
|
+
host: str = None,
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
:param db: Name of the database to connect to
|
|
24
|
+
:type db: str
|
|
25
|
+
:param user: Username of the database to connect to
|
|
26
|
+
:type user: str
|
|
27
|
+
:param pass: Password of the database to connect to
|
|
28
|
+
:type pass: str
|
|
29
|
+
:param host: Host of the database to connect to
|
|
30
|
+
:type host: str
|
|
31
|
+
:param token: Token of the database to connect to
|
|
32
|
+
:type token: str
|
|
33
|
+
"""
|
|
34
|
+
self.host = host or "https://aware-db.com"
|
|
35
|
+
self.db = db
|
|
36
|
+
self.user = user
|
|
37
|
+
self.password = password
|
|
38
|
+
self.token = token
|
|
39
|
+
|
|
40
|
+
# Check if token or user and pass are provided
|
|
41
|
+
if not token and not (user and password):
|
|
42
|
+
raise ValueError("Database token or username and password are required")
|
|
43
|
+
|
|
44
|
+
# If token is not provided, get it from the server
|
|
45
|
+
if not self.token:
|
|
46
|
+
self.token = self._get_token(user=user, password=password)
|
|
47
|
+
|
|
48
|
+
# Check if connection is valid
|
|
49
|
+
if not self._check_connection():
|
|
50
|
+
raise ValueError("Unable to connect to database")
|
|
51
|
+
|
|
52
|
+
# -------------------------------------------------------------------------
|
|
53
|
+
# Login and connection methods
|
|
54
|
+
# -------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
def _check_connection(self):
|
|
57
|
+
"""
|
|
58
|
+
Check if token is valid and if database exists.
|
|
59
|
+
"""
|
|
60
|
+
return self._request("check") == {"connected": True}
|
|
61
|
+
|
|
62
|
+
def _get_token(self, user: str = None, password: str = None):
|
|
63
|
+
"""
|
|
64
|
+
Get a token from the server with the provided username and password.
|
|
65
|
+
"""
|
|
66
|
+
response = requests.post(
|
|
67
|
+
f"{self.host}/rest/auth/token/login/",
|
|
68
|
+
json={"username": user, "password": password},
|
|
69
|
+
timeout=30,
|
|
70
|
+
)
|
|
71
|
+
return response.json().get("token")
|
|
72
|
+
|
|
73
|
+
# -------------------------------------------------------------------------
|
|
74
|
+
# Read database commands
|
|
75
|
+
# -------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
def get(
|
|
78
|
+
self,
|
|
79
|
+
path: str,
|
|
80
|
+
states: List[str] = None,
|
|
81
|
+
) -> Any:
|
|
82
|
+
"""
|
|
83
|
+
Returns the value of a specific path from nodes in the database
|
|
84
|
+
|
|
85
|
+
:param path: Path to get from the database.
|
|
86
|
+
:type path: str
|
|
87
|
+
:param states: List of states from which data should be retrieved.
|
|
88
|
+
:type states: List[str]
|
|
89
|
+
:return: Value of the path
|
|
90
|
+
:rtype: Any
|
|
91
|
+
"""
|
|
92
|
+
data = {"path": path, "states": states or []}
|
|
93
|
+
return self._request("get", data)
|
|
94
|
+
|
|
95
|
+
def query(
|
|
96
|
+
self,
|
|
97
|
+
nodes: List[str] = None,
|
|
98
|
+
conditions: List[str] = None,
|
|
99
|
+
properties: List[str] = None,
|
|
100
|
+
states: List[str] = None,
|
|
101
|
+
show_abstract: bool = False,
|
|
102
|
+
) -> List[Dict[str, Any]]:
|
|
103
|
+
"""
|
|
104
|
+
Returns a list of nodes based on the input.
|
|
105
|
+
|
|
106
|
+
:param nodes: List of ids, uids and names from nodes to fetch. Defaults to all.
|
|
107
|
+
:type nodes: List[str]
|
|
108
|
+
:param conditions: A list of conditions that validates if node should be retrieved.
|
|
109
|
+
:type conditions: List[str]
|
|
110
|
+
:param properties: A list of properties that should be retrieve. Defaults to all.
|
|
111
|
+
:type properties: List[str]
|
|
112
|
+
:param states: List of states from which data should be retrieved.
|
|
113
|
+
:type states: List[str]
|
|
114
|
+
:param show_abstract: If abstract nodes should be retrieved. Defaults to False.
|
|
115
|
+
:type show_abstract: bool
|
|
116
|
+
:return: Value of the path
|
|
117
|
+
:rtype: Dict[str, Any]
|
|
118
|
+
"""
|
|
119
|
+
data = {
|
|
120
|
+
"nodes": nodes or ["*"],
|
|
121
|
+
"conditions": conditions or [],
|
|
122
|
+
"properties": properties or [],
|
|
123
|
+
"states": states or [],
|
|
124
|
+
"show_abstract": show_abstract,
|
|
125
|
+
}
|
|
126
|
+
return self._request("query", data)
|
|
127
|
+
|
|
128
|
+
def calculate(
|
|
129
|
+
self,
|
|
130
|
+
formula: Union[str, List[str]],
|
|
131
|
+
states: List[str] = None,
|
|
132
|
+
) -> Union[Any, List[Any]]:
|
|
133
|
+
"""
|
|
134
|
+
Calculates a formula on the database.
|
|
135
|
+
|
|
136
|
+
If only one formula is passed, the response will result of the calculation.
|
|
137
|
+
If multiple formulas are passed, the response will be a list of results.
|
|
138
|
+
|
|
139
|
+
:param formula: Formula to calculate
|
|
140
|
+
:type formula: Union[str, List[str]]
|
|
141
|
+
:return: Value of the formula
|
|
142
|
+
:rtype: Union[Dict[str, Any], List[Dict[str, Any]]]
|
|
143
|
+
"""
|
|
144
|
+
data = {"formula": formula, states: states or []}
|
|
145
|
+
return self._request("calculate", data)
|
|
146
|
+
|
|
147
|
+
def what_if(
|
|
148
|
+
self,
|
|
149
|
+
changes: Dict[str, Any],
|
|
150
|
+
states: List[str] = None,
|
|
151
|
+
) -> Dict[str, Any]:
|
|
152
|
+
"""
|
|
153
|
+
Returns the impacts of changes without saving them on database.
|
|
154
|
+
|
|
155
|
+
:param changes: A dictionary where keys represents paths and values the new values.
|
|
156
|
+
:type changes: Dict[str, Any]
|
|
157
|
+
:param states: List of states from which data should be retrieved.
|
|
158
|
+
:type states: List[str]
|
|
159
|
+
:return: Dictionary with the impacts of the changes.
|
|
160
|
+
:rtype: Dict[str, Any]
|
|
161
|
+
"""
|
|
162
|
+
data = {"changes": changes, states: states or []}
|
|
163
|
+
return self._request("what-if", data)
|
|
164
|
+
|
|
165
|
+
# -------------------------------------------------------------------------
|
|
166
|
+
# Write database commands
|
|
167
|
+
# -------------------------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
def update(
|
|
170
|
+
self,
|
|
171
|
+
data: Union[Dict[str, Any], List[Dict[str, Any]]],
|
|
172
|
+
partial: bool = False,
|
|
173
|
+
) -> List[Dict[str, Any]]:
|
|
174
|
+
"""
|
|
175
|
+
Updates nodes on the database.
|
|
176
|
+
|
|
177
|
+
:param data: List of nodes, relations and relation types to created or update.
|
|
178
|
+
:type data: List[Dict[str, Any]]
|
|
179
|
+
:param partial: Updates only passed properties for exiting data. Defaults to False.
|
|
180
|
+
:type partial: bool
|
|
181
|
+
:return: List of updated nodes, relations and relation types.
|
|
182
|
+
:rtype: List[Dict[str, Any]]
|
|
183
|
+
"""
|
|
184
|
+
data = {"data": data, "partial": partial}
|
|
185
|
+
return self._request("update", data)
|
|
186
|
+
|
|
187
|
+
def remove(self, ids: List[str]) -> None:
|
|
188
|
+
"""
|
|
189
|
+
Removes specific nodes, relations and relation types from database.
|
|
190
|
+
|
|
191
|
+
:param ids: List of ids from nodes, relations and relation types to remove.
|
|
192
|
+
:type ids: List[str]
|
|
193
|
+
"""
|
|
194
|
+
data = {"ids": ids}
|
|
195
|
+
return self._request("remove", data)
|
|
196
|
+
|
|
197
|
+
def flush(self) -> None:
|
|
198
|
+
"""
|
|
199
|
+
Removes all nodes, relations and relation types from database.
|
|
200
|
+
"""
|
|
201
|
+
return self._request("flush")
|
|
202
|
+
|
|
203
|
+
# -------------------------------------------------------------------------
|
|
204
|
+
# Generic methods to handle command requests
|
|
205
|
+
# -------------------------------------------------------------------------
|
|
206
|
+
|
|
207
|
+
def _request(self, command: str, data: Dict[str, Any] = None) -> Any:
|
|
208
|
+
"""
|
|
209
|
+
Run a command on the server
|
|
210
|
+
|
|
211
|
+
:param command: Command to execute on the server.
|
|
212
|
+
:type command: str
|
|
213
|
+
:param data: Data to send to the server as part of the command.
|
|
214
|
+
:type data: Dict[str, Any]
|
|
215
|
+
:return: Servers response
|
|
216
|
+
:rtype: Any
|
|
217
|
+
"""
|
|
218
|
+
url = f"{self.host}/rest/db/{self.db}/{command}/"
|
|
219
|
+
response = requests.post(
|
|
220
|
+
url,
|
|
221
|
+
json=data or {},
|
|
222
|
+
headers={"Authorization": f"Token {self.token}"},
|
|
223
|
+
timeout=180,
|
|
224
|
+
)
|
|
225
|
+
if response.status_code == 400:
|
|
226
|
+
raise ValueError("Invalid request", response.json())
|
|
227
|
+
if response.status_code != 200:
|
|
228
|
+
raise ValueError("Invalid request", response.content)
|
|
229
|
+
return response.json().get("data")
|
|
230
|
+
|
|
231
|
+
# -------------------------------------------------------------------------
|
|
232
|
+
# Load and save database methods
|
|
233
|
+
# -------------------------------------------------------------------------
|
|
234
|
+
|
|
235
|
+
def load(self, filepath: str, recursive: bool = False, flush: bool = False):
|
|
236
|
+
"""
|
|
237
|
+
Load a file or folder of JSONs into the database.
|
|
238
|
+
"""
|
|
239
|
+
path = Path(filepath)
|
|
240
|
+
|
|
241
|
+
# If path is invalid, theres nothing to load
|
|
242
|
+
if not path.exists():
|
|
243
|
+
raise ValueError(f"Path {path} does not exist.")
|
|
244
|
+
|
|
245
|
+
# If flush is True, remove all data from database
|
|
246
|
+
if flush:
|
|
247
|
+
self.flush()
|
|
248
|
+
|
|
249
|
+
# Gather data to be loaded
|
|
250
|
+
data = []
|
|
251
|
+
if path.is_dir():
|
|
252
|
+
self._load_folder(data, path, recursive)
|
|
253
|
+
else:
|
|
254
|
+
self._load_file(data, path)
|
|
255
|
+
|
|
256
|
+
# Upload data to database
|
|
257
|
+
self.update(data)
|
|
258
|
+
|
|
259
|
+
def _load_folder(
|
|
260
|
+
self, data: List[Dict[str, Any]], path: Path, recursive: bool = False
|
|
261
|
+
):
|
|
262
|
+
"""
|
|
263
|
+
Loads a folder of JSONs into list of data to be loaded.
|
|
264
|
+
"""
|
|
265
|
+
for file in path.iterdir():
|
|
266
|
+
if file.is_dir():
|
|
267
|
+
if recursive:
|
|
268
|
+
self._load_folder(data, file, recursive=recursive)
|
|
269
|
+
elif file.suffix.lower() == ".json":
|
|
270
|
+
self._load_file(data, file)
|
|
271
|
+
|
|
272
|
+
def _load_file(self, data: List[Dict[str, Any]], path: Path):
|
|
273
|
+
"""
|
|
274
|
+
Loads a JSON file into a list of data to be loaded.
|
|
275
|
+
"""
|
|
276
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
277
|
+
content = json.load(f)
|
|
278
|
+
|
|
279
|
+
if isinstance(content, list):
|
|
280
|
+
data.extend(content)
|
|
281
|
+
else:
|
|
282
|
+
data.append(content)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: awaredb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AwareDB: data modularity, simplified. Python API.
|
|
5
|
+
Home-page: https://github.com/nelsonmonteiro/awaredb-python-api
|
|
6
|
+
Download-URL: https://github.com/nelsonmonteiro/awaredb-python-api/archive/v_0_1_1.tar.gz
|
|
7
|
+
Author: Nelson Monteiro
|
|
8
|
+
Author-email: nelson@aware-db.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: AwareDB,modularity
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
License-File: LICENSE
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.cfg
|
|
4
|
+
setup.py
|
|
5
|
+
AwareDB/__init__.py
|
|
6
|
+
AwareDB/api.py
|
|
7
|
+
AwareDB.egg-info/PKG-INFO
|
|
8
|
+
AwareDB.egg-info/SOURCES.txt
|
|
9
|
+
AwareDB.egg-info/dependency_links.txt
|
|
10
|
+
AwareDB.egg-info/requires.txt
|
|
11
|
+
AwareDB.egg-info/top_level.txt
|
|
12
|
+
awaredb/__init__.py
|
|
13
|
+
awaredb/api.py
|
|
14
|
+
awaredb.egg-info/PKG-INFO
|
|
15
|
+
awaredb.egg-info/SOURCES.txt
|
|
16
|
+
awaredb.egg-info/dependency_links.txt
|
|
17
|
+
awaredb.egg-info/requires.txt
|
|
18
|
+
awaredb.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
awaredb
|
awaredb-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Nelson Monteiro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
awaredb-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: awaredb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AwareDB: data modularity, simplified. Python API.
|
|
5
|
+
Home-page: https://github.com/nelsonmonteiro/awaredb-python-api
|
|
6
|
+
Download-URL: https://github.com/nelsonmonteiro/awaredb-python-api/archive/v_0_1_1.tar.gz
|
|
7
|
+
Author: Nelson Monteiro
|
|
8
|
+
Author-email: nelson@aware-db.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: AwareDB,modularity
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
License-File: LICENSE
|
awaredb-0.1.0/README.md
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# AwareDB: Python API
|
|
2
|
+
|
|
3
|
+
This is a simple plugin to execute commands on AwareDB. For more information about AwareDB, read [here the full documentation](https://docs.aware-db.com/).
|
|
4
|
+
|
|
5
|
+
## About AwareDB
|
|
6
|
+
|
|
7
|
+
AwareDB aims to revolutionize the traditional approach to data by introducing the principle
|
|
8
|
+
of **modularity** directly into the **data structure**. While modularity is a well-established
|
|
9
|
+
concept in computer science, primarily applied to programming and infrastructure, the realm
|
|
10
|
+
of data has remained predominantly static and non-modular,tightly bound to the code
|
|
11
|
+
that governs it.
|
|
12
|
+
|
|
13
|
+
Our innovative approach introduces a groundbreaking concept wherein data becomes **self-aware**.
|
|
14
|
+
Individual pieces of data can seamlessly **connect**, **reference one another** through direct links
|
|
15
|
+
or employ **mathematical** and **logical operations**. Notably, alterations to one node trigger
|
|
16
|
+
**automatic cascading impacts** throughout the system, all achieved without the need for
|
|
17
|
+
additional code.
|
|
18
|
+
|
|
19
|
+
This marks a paradigm shift in data management, empowering a dynamic,
|
|
20
|
+
interconnected, and **self-aware data environment**.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$ pip install awaredb
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
|
|
32
|
+
from awaredb import AwareDB
|
|
33
|
+
|
|
34
|
+
# Using token
|
|
35
|
+
awaredb = AwareDB(db="<my_db>", token="<my_token>")
|
|
36
|
+
|
|
37
|
+
# Using username and password
|
|
38
|
+
awaredb = AwareDB(db="<my_db>", user="<username>", password="<my_password>")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Read commands
|
|
42
|
+
|
|
43
|
+
#### calculate
|
|
44
|
+
|
|
45
|
+
Execute calculations using existing nodes in the database.
|
|
46
|
+
|
|
47
|
+
Params:
|
|
48
|
+
* `formula`: A singular formula or a list of formulas to be computed.
|
|
49
|
+
* `states`: A list specifying the active states used during calculations.
|
|
50
|
+
|
|
51
|
+
Example of a call:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
awaredb.calculate(
|
|
55
|
+
formula="${car.power} * 2",
|
|
56
|
+
states=["car.model.x"],
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Example of response:
|
|
60
|
+
Output: "500 hp"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### get
|
|
64
|
+
|
|
65
|
+
Returns the value of a specific path from nodes in the database.
|
|
66
|
+
|
|
67
|
+
Params:
|
|
68
|
+
* `path`: A single path to be retrieved.
|
|
69
|
+
* `states`: A list of states from which data should be retrieved.
|
|
70
|
+
|
|
71
|
+
Example of a call:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
awaredb.get(path="car.power", states=[car.model.x])
|
|
75
|
+
|
|
76
|
+
# Example of a calculate response
|
|
77
|
+
Output: "250 hp"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### query
|
|
82
|
+
|
|
83
|
+
Returns a list of nodes based on the input.
|
|
84
|
+
|
|
85
|
+
Params:
|
|
86
|
+
* `nodes`: List of ids, uids and names from existing nodes.
|
|
87
|
+
* `conditions`: A list of conditions that validates if node should be retrieved.
|
|
88
|
+
* `properties`: A list of properties that should be retrieve. Defaults to all.
|
|
89
|
+
* `states`: A list of states from which data should be retrieved.
|
|
90
|
+
* `show_abstract`: If abstract nodes should be retrieved. Defaults to False.
|
|
91
|
+
|
|
92
|
+
Note: To retrieve all nodes, use `'*'` as `nodes` value.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
Example of a call:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
awaredb.query(
|
|
99
|
+
nodes=["employee"],
|
|
100
|
+
conditions=["${node.salary.gross} > 60000"],
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# Example of a calculate response
|
|
104
|
+
Output: [
|
|
105
|
+
{
|
|
106
|
+
"id": "7037a8a5-ac2f-4a65-a913-ab1e631fda76"
|
|
107
|
+
"node_type": "employee",
|
|
108
|
+
"name": "John Doe",
|
|
109
|
+
"salary": {
|
|
110
|
+
"gross": "80000"
|
|
111
|
+
},
|
|
112
|
+
"value": {
|
|
113
|
+
"salary": {
|
|
114
|
+
"gross": "80000",
|
|
115
|
+
"net": "56000"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"id": "7037a8a5-ac2f-4a65-a913-ab1e631fda77"
|
|
121
|
+
"node_type": "employee",
|
|
122
|
+
"name": "Jane Doe",
|
|
123
|
+
"salary": {
|
|
124
|
+
"gross": "100000"
|
|
125
|
+
},
|
|
126
|
+
"value": {
|
|
127
|
+
"salary": {
|
|
128
|
+
"gross": "100000",
|
|
129
|
+
"net": "70000"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### what_if
|
|
138
|
+
|
|
139
|
+
Allows to return the impacts of changes without saving them on database.
|
|
140
|
+
|
|
141
|
+
Params:
|
|
142
|
+
* `change`: A dictionary where keys represents paths and values the new values.
|
|
143
|
+
* `states`: A list of states from which data should be retrieved.
|
|
144
|
+
|
|
145
|
+
Example of a call:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
awaredb.what_if(
|
|
149
|
+
changes={"battery.capacity": "55 kWh"},
|
|
150
|
+
states=["car.performance"],
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Example of a calculate response
|
|
154
|
+
Output: {
|
|
155
|
+
"battery.capacity": "55 kWh",
|
|
156
|
+
"car.range": "180 km"
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Write commands
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
### flush
|
|
165
|
+
|
|
166
|
+
Deletes all data currently on database.
|
|
167
|
+
|
|
168
|
+
Example of a call:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
awaredb.flush()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### remove
|
|
175
|
+
|
|
176
|
+
Removes specific nodes and relations from database.
|
|
177
|
+
|
|
178
|
+
Params:
|
|
179
|
+
* `ids`: List of ids from nodes and relations to be deleted.
|
|
180
|
+
|
|
181
|
+
Example of a call:
|
|
182
|
+
```python
|
|
183
|
+
awaredb.remove(ids=[
|
|
184
|
+
"7037a8a5-ac2f-4a65-a913-ab1e631fda76",
|
|
185
|
+
"7037a8a5-ac2f-4a65-a913-ab1e631fda77",
|
|
186
|
+
])
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### update
|
|
190
|
+
|
|
191
|
+
Add and/or updates nodes, relations and relation types from a database.
|
|
192
|
+
|
|
193
|
+
Params:
|
|
194
|
+
* `data`: List of nodes, relations and relation types to created or update.
|
|
195
|
+
* `partial`: Updates only passed properties for exiting data. Defaults to False.
|
|
196
|
+
|
|
197
|
+
Example of a call:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
awaredb.update(data=[
|
|
201
|
+
{
|
|
202
|
+
"name": "Fan",
|
|
203
|
+
"mode": {
|
|
204
|
+
"states": {
|
|
205
|
+
"off": ["this.engine.mode.off", "this.lights.status.off"],
|
|
206
|
+
"low": ["this.engine.mode.low", "this.lights.status.on"],
|
|
207
|
+
"mid": ["this.engine.mode.mid", "this.lights.status.on"],
|
|
208
|
+
"high": ["this.engine.mode.high", "this.lights.status.on"]
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
"power": "=sum(${this.children.power})",
|
|
212
|
+
"engine": {
|
|
213
|
+
"mode": {"states": ["off", "low", "mid", "high"]},
|
|
214
|
+
"power": {
|
|
215
|
+
"linked-to": "${this.engine.mode}",
|
|
216
|
+
"cases": [
|
|
217
|
+
["low", "10 W"],
|
|
218
|
+
["mid", "20 W"],
|
|
219
|
+
["high", "30 W"],
|
|
220
|
+
["default", "0 W"]
|
|
221
|
+
]
|
|
222
|
+
},
|
|
223
|
+
"speed": "=10 rpm * (${this.engine.power} / 1 W)"
|
|
224
|
+
},
|
|
225
|
+
"lights": {
|
|
226
|
+
"status": {"states": ["off", "on"]},
|
|
227
|
+
"power": {
|
|
228
|
+
"linked-to": "this.lights.status",
|
|
229
|
+
"cases": [
|
|
230
|
+
["off", "0 W"],
|
|
231
|
+
["on", "5 W"]
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
])
|
|
237
|
+
|
|
238
|
+
# Example of a calculate response
|
|
239
|
+
Output: [
|
|
240
|
+
{
|
|
241
|
+
"name": "Fan",
|
|
242
|
+
"mode": {
|
|
243
|
+
"states": {
|
|
244
|
+
"off": ["this.engine.mode.off", "this.lights.status.off"],
|
|
245
|
+
"low": ["this.engine.mode.low", "this.lights.status.on"],
|
|
246
|
+
"mid": ["this.engine.mode.mid", "this.lights.status.on"],
|
|
247
|
+
"high": ["this.engine.mode.high", "this.lights.status.on"]
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
"power": "=sum(${this.children.power})",
|
|
251
|
+
"engine": {
|
|
252
|
+
"mode": {"states": ["off", "low", "mid", "high"]},
|
|
253
|
+
"power": {
|
|
254
|
+
"linked-to": "${this.engine.mode}",
|
|
255
|
+
"cases": [
|
|
256
|
+
["low", "10 W"],
|
|
257
|
+
["mid", "20 W"],
|
|
258
|
+
["high", "30 W"],
|
|
259
|
+
["default", "0 W"]
|
|
260
|
+
]
|
|
261
|
+
},
|
|
262
|
+
"speed": "=10 rpm * (${this.engine.power} / 1 W)"
|
|
263
|
+
},
|
|
264
|
+
"lights": {
|
|
265
|
+
"status": {"states": ["off", "on"]},
|
|
266
|
+
"power": {
|
|
267
|
+
"linked-to": "this.lights.status",
|
|
268
|
+
"cases": [
|
|
269
|
+
["off", "0 W"],
|
|
270
|
+
["on", "5 W"]
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
"value": {
|
|
275
|
+
"mode": {
|
|
276
|
+
"states": {
|
|
277
|
+
"off": ["this.engine.mode.off", "this.lights.status.off"],
|
|
278
|
+
"low": ["this.engine.mode.low", "this.lights.status.on"],
|
|
279
|
+
"mid": ["this.engine.mode.mid", "this.lights.status.on"],
|
|
280
|
+
"high": ["this.engine.mode.high", "this.lights.status.on"]
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
"power": {
|
|
284
|
+
"linked-to": "this.engine.mode",
|
|
285
|
+
"cases": [
|
|
286
|
+
[
|
|
287
|
+
"low",
|
|
288
|
+
{
|
|
289
|
+
"linked-to": "this.lights.status",
|
|
290
|
+
"cases": [
|
|
291
|
+
["off", "10.0 W"],
|
|
292
|
+
["on", "15.0 W"],
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
[
|
|
297
|
+
"mid",
|
|
298
|
+
{
|
|
299
|
+
"linked-to": "this.lights.status",
|
|
300
|
+
"cases": [
|
|
301
|
+
["off", "20.0 W"],
|
|
302
|
+
["on", "25.0 W"],
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
[
|
|
307
|
+
"high",
|
|
308
|
+
{
|
|
309
|
+
"linked-to": "this.lights.status",
|
|
310
|
+
"cases": [
|
|
311
|
+
["off", "30.0 W"],
|
|
312
|
+
["on", "35.0 W"],
|
|
313
|
+
],
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
[
|
|
317
|
+
"default",
|
|
318
|
+
{
|
|
319
|
+
"linked-to": "this.lights.status",
|
|
320
|
+
"cases": [
|
|
321
|
+
["off", "0.0 W"],
|
|
322
|
+
["on", "5.0 W"],
|
|
323
|
+
],
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
"engine": {
|
|
329
|
+
"mode": {"states": ["off", "low", "mid", "high"]},
|
|
330
|
+
"power": {
|
|
331
|
+
"linked-to": "${this.engine.mode}",
|
|
332
|
+
"cases": [
|
|
333
|
+
["low", "10 W"],
|
|
334
|
+
["mid", "20 W"],
|
|
335
|
+
["high", "30 W"],
|
|
336
|
+
["default", "0 W"]
|
|
337
|
+
]
|
|
338
|
+
},
|
|
339
|
+
"speed": {
|
|
340
|
+
"linked-to": "this.engine.mode",
|
|
341
|
+
"cases": [
|
|
342
|
+
["low", "100.0 rpm"],
|
|
343
|
+
["mid", "200.0 rpm"],
|
|
344
|
+
["high", "300.0 rpm"],
|
|
345
|
+
["default", "0.0 rpm"],
|
|
346
|
+
],
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
"lights": {
|
|
350
|
+
"status": {"states": ["off", "on"]},
|
|
351
|
+
"power": {
|
|
352
|
+
"linked-to": "this.lights.status",
|
|
353
|
+
"cases": [
|
|
354
|
+
["off", "0 W"],
|
|
355
|
+
["on", "5 W"]
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
]
|
|
362
|
+
```
|
awaredb-0.1.0/setup.cfg
ADDED
awaredb-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="awaredb",
|
|
5
|
+
packages=["awaredb"],
|
|
6
|
+
version="0.1.0",
|
|
7
|
+
license="MIT",
|
|
8
|
+
description="AwareDB: data modularity, simplified. Python API.",
|
|
9
|
+
author="Nelson Monteiro",
|
|
10
|
+
author_email="nelson@aware-db.com",
|
|
11
|
+
url="https://github.com/nelsonmonteiro/awaredb-python-api",
|
|
12
|
+
download_url="https://github.com/nelsonmonteiro/awaredb-python-api/archive/v_0_1_1.tar.gz",
|
|
13
|
+
keywords=["AwareDB", "modularity"],
|
|
14
|
+
install_requires=[
|
|
15
|
+
"requests",
|
|
16
|
+
],
|
|
17
|
+
classifiers=[
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Topic :: Database :: Front-Ends",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.8",
|
|
24
|
+
"Programming Language :: Python :: 3.9",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
],
|
|
29
|
+
)
|