edgeable 0.1.78__tar.gz → 0.2.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.
- {edgeable-0.1.78/edgeable.egg-info → edgeable-0.2.0}/PKG-INFO +53 -32
- edgeable-0.1.78/PKG-INFO → edgeable-0.2.0/README.md +30 -36
- {edgeable-0.1.78 → edgeable-0.2.0}/edgeable/__init__.py +5 -0
- edgeable-0.2.0/edgeable/database.py +425 -0
- {edgeable-0.1.78 → edgeable-0.2.0}/edgeable/edge.py +20 -8
- edgeable-0.2.0/edgeable/node.py +430 -0
- edgeable-0.2.0/edgeable/threadlock.py +57 -0
- edgeable-0.1.78/README.md → edgeable-0.2.0/edgeable.egg-info/PKG-INFO +58 -19
- edgeable-0.2.0/edgeable.egg-info/SOURCES.txt +28 -0
- edgeable-0.2.0/edgeable.egg-info/requires.txt +7 -0
- edgeable-0.2.0/pyproject.toml +38 -0
- edgeable-0.2.0/tests/test_database.py +99 -0
- edgeable-0.2.0/tests/test_database_events.py +189 -0
- edgeable-0.2.0/tests/test_database_persistance.py +56 -0
- edgeable-0.2.0/tests/test_database_properties.py +44 -0
- edgeable-0.2.0/tests/test_edge.py +46 -0
- edgeable-0.2.0/tests/test_edge_properties.py +107 -0
- edgeable-0.2.0/tests/test_fix_db_callbacks_validation.py +214 -0
- edgeable-0.2.0/tests/test_fix_db_persistence.py +399 -0
- edgeable-0.2.0/tests/test_fix_db_threadlock.py +337 -0
- edgeable-0.2.0/tests/test_fix_node_edges.py +481 -0
- edgeable-0.2.0/tests/test_fix_node_routing.py +256 -0
- edgeable-0.2.0/tests/test_node.py +134 -0
- edgeable-0.2.0/tests/test_node_neighbors.py +49 -0
- edgeable-0.2.0/tests/test_node_properties.py +55 -0
- edgeable-0.2.0/tests/test_node_route.py +72 -0
- edgeable-0.2.0/tests/test_threadlock.py +107 -0
- edgeable-0.1.78/edgeable/database.py +0 -213
- edgeable-0.1.78/edgeable/node.py +0 -277
- edgeable-0.1.78/edgeable/threadlock.py +0 -73
- edgeable-0.1.78/edgeable.egg-info/SOURCES.txt +0 -12
- edgeable-0.1.78/edgeable.egg-info/requires.txt +0 -1
- edgeable-0.1.78/setup.py +0 -31
- {edgeable-0.1.78 → edgeable-0.2.0}/edgeable.egg-info/dependency_links.txt +0 -0
- {edgeable-0.1.78 → edgeable-0.2.0}/edgeable.egg-info/top_level.txt +0 -0
- {edgeable-0.1.78 → edgeable-0.2.0}/setup.cfg +0 -0
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: edgeable
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Easy to use, in memory,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Easy to use, in memory, persistable graph database.
|
|
5
|
+
Author-email: Lee Adcock <lee@katieandlee.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/LeeAdcock/edgeable
|
|
8
|
+
Project-URL: Issues, https://github.com/LeeAdcock/edgeable/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/LeeAdcock/edgeable/blob/master/CHANGELOG.md
|
|
10
|
+
Keywords: graph,database,in-memory
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Requires-Python: >=3.10
|
|
16
20
|
Description-Content-Type: text/markdown
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest; extra == "dev"
|
|
23
|
+
Requires-Dist: coverage; extra == "dev"
|
|
24
|
+
Requires-Dist: black~=26.0; extra == "dev"
|
|
25
|
+
Requires-Dist: build; extra == "dev"
|
|
26
|
+
Requires-Dist: twine; extra == "dev"
|
|
17
27
|
|
|
18
28
|
<img src="https://raw.githubusercontent.com/LeeAdcock/edgeable/master/assets/logo.png" alt="Edgeable" width="300"/>
|
|
19
29
|
|
|
20
|
-
*Edgeable is an easy to use, in memory,
|
|
30
|
+
*Edgeable is an easy to use, in memory, persistable graph database. It is perfect for prototyping, exploring, and quick implementation in Python applications.* The library is written completely in Python, supporting 3.10+.
|
|
21
31
|
|
|
22
|
-
In Edgeable, graphs are made of nodes with a string or numeric identifier and can have any number of properties. Nodes are connected by directed or non-directed edges that can also have any number of properties. Additional convenience capabilities, like route detection through the graph, are built-in. Edgeable is thread safe for multi-threaded applications and easily handles databases with tens to hundreds of thousands of nodes.
|
|
32
|
+
In Edgeable, graphs are made of nodes with a string or numeric identifier and can have any number of properties. Nodes are connected by directed or non-directed edges that can also have any number of properties. Additional convenience capabilities, like route detection through the graph, are built-in. Edgeable is thread safe for multi-threaded applications (operations on a database are serialized by a re-entrant, per-database lock) and easily handles databases with tens to hundreds of thousands of nodes.
|
|
23
33
|
|
|
24
34
|
## Installation
|
|
25
35
|
|
|
@@ -32,7 +42,7 @@ The Edgeable database library can easily be installed with pip using `pip instal
|
|
|
32
42
|
```
|
|
33
43
|
from edgeable import GraphDatabase
|
|
34
44
|
|
|
35
|
-
graph =
|
|
45
|
+
graph = GraphDatabase()
|
|
36
46
|
A = graph.put_node('A', {'type': 'building'})
|
|
37
47
|
B = graph.put_node('B', {'type': 'classroom'})
|
|
38
48
|
A.attach(B, {'relationship': 'contains'})
|
|
@@ -50,7 +60,7 @@ with open('edges.csv') as csvfile:
|
|
|
50
60
|
for row in reader:
|
|
51
61
|
node_a = graph.put_node(row[0].strip())
|
|
52
62
|
node_b = graph.put_node(row[1].strip())
|
|
53
|
-
|
|
63
|
+
node_a.attach(node_b)
|
|
54
64
|
```
|
|
55
65
|
|
|
56
66
|
### Write a csv file of edges
|
|
@@ -72,51 +82,61 @@ with open('edges.csv', 'w') as csvfile:
|
|
|
72
82
|
The `GraphDatabase` class represents the entire graph. Instances of `GraphDatabase` provide the ability to retrieve and creates nodes, as well as save or load from the file system.
|
|
73
83
|
|
|
74
84
|
##### Graph Constructor
|
|
75
|
-
The `GraphDatabase(filename="graph.db")` constructor is used to create a new graph database instance. The file name used to persist the database can optionally be ovewritten. If a persisted database file already exists, it will be loaded.
|
|
85
|
+
The `GraphDatabase(filename="graph.db", properties=None)` constructor is used to create a new graph database instance. The file name used to persist the database can optionally be ovewritten. If a persisted database file already exists, it will be loaded.
|
|
86
|
+
|
|
87
|
+
An optional dict of database properties can be provided. If a persisted database file is loaded, the properties stored in it are loaded first and the provided properties are then set on top of them, so a provided value replaces a loaded value with the same key.
|
|
76
88
|
|
|
77
89
|
The `with` syntax can be used to initialize the graph and ensure it is saved once the block is exited.
|
|
78
90
|
|
|
79
91
|
```
|
|
80
92
|
from edgeable import GraphDatabase
|
|
81
93
|
|
|
82
|
-
with
|
|
94
|
+
with GraphDatabase(filename="mygraph.db") as graph:
|
|
83
95
|
A = graph.put_node('A', {'type': 'building'})
|
|
84
96
|
B = graph.put_node('B', {'type': 'classroom'})
|
|
85
97
|
A.attach(B, {'relationship': 'contains'})
|
|
86
98
|
```
|
|
87
99
|
|
|
88
100
|
##### Graph Persistance
|
|
89
|
-
- `reload()` - Reload the graph from the file system. The persisted file is loaded automatically when the `GraphDatabase` instance is initialized, calling `
|
|
90
|
-
- `save()` - Save the graph to the file system. When using the `with` syntax, this is called automatically. Save operations are done in a way to be thread-safe and avoid corruption if the application terminates during a write.
|
|
101
|
+
- `reload()` - Reload the graph from the file system. The persisted file is loaded automatically when the `GraphDatabase` instance is initialized, calling `reload()` is only neccessary to reload it, overwriting any changes to nodes, edges and database properties. Registered callbacks are kept, and apply to the reloaded nodes and edges.
|
|
102
|
+
- `save()` - Save the graph to the file system. When using the `with` syntax, this is called automatically. Save operations are done in a way to be thread-safe and avoid corruption if the application terminates during a write: the content is written and synced to a temporary file in the same directory, which then replaces the database file. The directory must already exist.
|
|
103
|
+
|
|
104
|
+
Nodes, edges, their properties and the database properties are persisted. Callbacks are not.
|
|
105
|
+
|
|
106
|
+
Property values (on the database, nodes and edges) must be made up of the following types to be persisted: `None`, `bool`, `int`, `float`, `complex`, `str`, `bytes`, `bytearray`, `list`, `tuple`, `dict`, `set`, `frozenset`, `range`, `slice`, `datetime.datetime`, `datetime.date`, `datetime.time`, `datetime.timedelta`, `datetime.timezone`, `decimal.Decimal`, `fractions.Fraction`, `uuid.UUID`, `collections.OrderedDict`, `collections.deque` and `collections.Counter`. Other values, such as instances of your own classes, can be held in memory but `save()` raises `pickle.PicklingError` for them and leaves the existing file untouched.
|
|
107
|
+
|
|
108
|
+
The file is a gzip compressed pickle. When loading, anything other than Edgeable's own classes and the types above is refused with `pickle.UnpicklingError` rather than imported, so loading a file does not run code embedded in it. This is a safeguard and not a guarantee: a crafted file can still contain a misleading or very large graph, so only load database files from sources you trust. Files written by earlier releases can still be loaded, and are written in the current format on the next `save()`; earlier releases cannot read files in the current format.
|
|
91
109
|
|
|
92
110
|
##### Graph Nodes and Edges
|
|
93
111
|
|
|
94
112
|
- `put_node(id, properties={})` - Creates or retrieves the instance of `GraphNode` with the provided identifier. The optionally provided properties are set or updated on the node.
|
|
95
|
-
- `has_node(id)` - Taking a node identifier,
|
|
113
|
+
- `has_node(id)` - Taking a node identifier, returns a boolean indicating whether a node with that identifier exists in the database.
|
|
96
114
|
- `get_node(id)` - Taking a node identifier, return an instance of type `GraphNode` if it exists in the database. Returns `None` otherwise.
|
|
97
115
|
- `get_nodes(filter_fn=lambda node: True)` - Retrieve a list of `GraphNode` instances from the database. If the optional filter function is not provided, all nodes are returned, otherwise the filter function is used to return only matching nodes.
|
|
98
|
-
- `
|
|
116
|
+
- `get_edges(edge_filter_fn=lambda edge: True, node_filter_fn=lambda node: True)` - Retrieve a list of `GraphEdge` instances from the database. If the optional filter functions are not provided, all edges are returned, otherwise only edges matching `edge_filter_fn` whose source node matches `node_filter_fn` are returned. Filters can be any callable.
|
|
99
117
|
- `get_node_count()` - Return the number of nodes in the database.
|
|
100
118
|
- `get_edge_count()` - Return the number of edges in the database.
|
|
101
119
|
|
|
102
120
|
##### Graph Properties
|
|
103
|
-
|
|
121
|
+
Database properties are saved to and loaded from the file system together with the graph. Property keys must be strings.
|
|
122
|
+
|
|
123
|
+
- `set_property(key, value)` - Set a property on the database with the provided key and value.
|
|
104
124
|
- `set_properties(properties)` - Provide a dict to set multiple properites on the database.
|
|
105
|
-
- `get_property(key)` - Retrieve the
|
|
106
|
-
- `get_properties()` - Retrieve a `dict` containing all properties set on the
|
|
125
|
+
- `get_property(key)` - Retrieve the database's property value for the provided key.
|
|
126
|
+
- `get_properties()` - Retrieve a `dict` containing all properties set on the database.
|
|
107
127
|
- `has_property(key)` - Returns a boolean indicating whether the property key is defined.
|
|
108
128
|
- `delete_property(key)` - Removes a property.
|
|
109
129
|
|
|
110
130
|
##### Graph Callbacks
|
|
111
131
|
|
|
112
|
-
Event callbacks can be provided that will have the opportunity to process objects in the graph. Multiple callbacks can be defined for an event type. Each callbacks has an identifier, this can be specified when created or one will automatically be generated and returned. The id can be later used to overwrite or remove (set to `None`) the callback.
|
|
132
|
+
Event callbacks can be provided that will have the opportunity to process objects in the graph. Multiple callbacks can be defined for an event type. Each callbacks has an identifier, this can be specified when created or one will automatically be generated and returned. The id can be later used to overwrite or remove (set to `None`) the callback. Removing an id which is not registered does nothing. Callbacks can be any callable; anything else raises a `RuntimeError`.
|
|
113
133
|
|
|
114
134
|
- `on_create_node(fn, id=None)` - Sets or changes a callback that is called when a node is added to the graph.
|
|
115
135
|
- `on_create_edge(fn, id=None)` - Sets or changes a callback that is called when a edge is added to the graph.
|
|
116
136
|
- `on_delete_node(fn, id=None)` - Sets or changes a callback that is called when a node is deleted from the graph.
|
|
117
137
|
- `on_delete_edge(fn, id=None)` - Sets or changes a callback that is called when a edge is deleted from the graph.
|
|
118
138
|
|
|
119
|
-
Callback functions that return
|
|
139
|
+
Callback functions that return `False` will cancel the event; any other return value, including `None` and `0`, does not. Every callback registered for an event is called, even after one of them has cancelled it. Callbacks, like filter functions, can themselves read and modify the graph. Callback functions are not persisted with the database.
|
|
120
140
|
|
|
121
141
|
### Node Class
|
|
122
142
|
The `GraphNode` class represent nodes and associated properties within the graph. Nodes can be connected through directed or non-directed edges.
|
|
@@ -139,8 +159,8 @@ The `GraphNode` class represent nodes and associated properties within the graph
|
|
|
139
159
|
- `delete_property(key)` - Removes a property.
|
|
140
160
|
|
|
141
161
|
##### Node Routes
|
|
142
|
-
- `
|
|
143
|
-
- `
|
|
162
|
+
- `find_route_to(end, skip=[])` - Find a shortest route (by number of edges) from the current node to the `end` node, returned as a list of `GraphNode` instances starting with the current node and ending with `end`. Returns `None` if there is no route. Nodes in the optional `skip` list are not travelled through.
|
|
163
|
+
- `find_routes_to(end, effort=5)` - Find alternative routes from the current node to the `end` node, returned as a list of routes with the shortest first. After the shortest route, further routes are found by searching again while avoiding nodes used by the routes found so far. `effort` bounds how many nodes may be avoided at once: higher values find more, less direct routes and take longer.
|
|
144
164
|
|
|
145
165
|
##### Node Neighbors
|
|
146
166
|
- `find_neighbors(distance=1, distance_fn=lambda edge: 1)` - Find all nodes within a specified distance. By default, each edge is considered a distance of one. A custom function can be provided to provide a custom distance calculation.
|
|
@@ -162,7 +182,8 @@ The `GraphEdge` class representes the connections between `GraphNode` instances
|
|
|
162
182
|
|
|
163
183
|
## Resources
|
|
164
184
|
|
|
165
|
-
Build process: https://
|
|
185
|
+
Build process: https://github.com/LeeAdcock/edgeable/actions
|
|
166
186
|
|
|
167
|
-
|
|
187
|
+
Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
168
188
|
|
|
189
|
+
PyPi: https://pypi.org/project/edgeable/
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: edgeable
|
|
3
|
-
Version: 0.1.78
|
|
4
|
-
Summary: Easy to use, in memory, peristable graph database.
|
|
5
|
-
Home-page: https://github.com/leeadcock/edgeable
|
|
6
|
-
Author: Lee Adcock
|
|
7
|
-
Author-email: lee@katieandlee.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
|
|
18
1
|
<img src="https://raw.githubusercontent.com/LeeAdcock/edgeable/master/assets/logo.png" alt="Edgeable" width="300"/>
|
|
19
2
|
|
|
20
|
-
*Edgeable is an easy to use, in memory,
|
|
3
|
+
*Edgeable is an easy to use, in memory, persistable graph database. It is perfect for prototyping, exploring, and quick implementation in Python applications.* The library is written completely in Python, supporting 3.10+.
|
|
21
4
|
|
|
22
|
-
In Edgeable, graphs are made of nodes with a string or numeric identifier and can have any number of properties. Nodes are connected by directed or non-directed edges that can also have any number of properties. Additional convenience capabilities, like route detection through the graph, are built-in. Edgeable is thread safe for multi-threaded applications and easily handles databases with tens to hundreds of thousands of nodes.
|
|
5
|
+
In Edgeable, graphs are made of nodes with a string or numeric identifier and can have any number of properties. Nodes are connected by directed or non-directed edges that can also have any number of properties. Additional convenience capabilities, like route detection through the graph, are built-in. Edgeable is thread safe for multi-threaded applications (operations on a database are serialized by a re-entrant, per-database lock) and easily handles databases with tens to hundreds of thousands of nodes.
|
|
23
6
|
|
|
24
7
|
## Installation
|
|
25
8
|
|
|
@@ -32,7 +15,7 @@ The Edgeable database library can easily be installed with pip using `pip instal
|
|
|
32
15
|
```
|
|
33
16
|
from edgeable import GraphDatabase
|
|
34
17
|
|
|
35
|
-
graph =
|
|
18
|
+
graph = GraphDatabase()
|
|
36
19
|
A = graph.put_node('A', {'type': 'building'})
|
|
37
20
|
B = graph.put_node('B', {'type': 'classroom'})
|
|
38
21
|
A.attach(B, {'relationship': 'contains'})
|
|
@@ -50,7 +33,7 @@ with open('edges.csv') as csvfile:
|
|
|
50
33
|
for row in reader:
|
|
51
34
|
node_a = graph.put_node(row[0].strip())
|
|
52
35
|
node_b = graph.put_node(row[1].strip())
|
|
53
|
-
|
|
36
|
+
node_a.attach(node_b)
|
|
54
37
|
```
|
|
55
38
|
|
|
56
39
|
### Write a csv file of edges
|
|
@@ -72,51 +55,61 @@ with open('edges.csv', 'w') as csvfile:
|
|
|
72
55
|
The `GraphDatabase` class represents the entire graph. Instances of `GraphDatabase` provide the ability to retrieve and creates nodes, as well as save or load from the file system.
|
|
73
56
|
|
|
74
57
|
##### Graph Constructor
|
|
75
|
-
The `GraphDatabase(filename="graph.db")` constructor is used to create a new graph database instance. The file name used to persist the database can optionally be ovewritten. If a persisted database file already exists, it will be loaded.
|
|
58
|
+
The `GraphDatabase(filename="graph.db", properties=None)` constructor is used to create a new graph database instance. The file name used to persist the database can optionally be ovewritten. If a persisted database file already exists, it will be loaded.
|
|
59
|
+
|
|
60
|
+
An optional dict of database properties can be provided. If a persisted database file is loaded, the properties stored in it are loaded first and the provided properties are then set on top of them, so a provided value replaces a loaded value with the same key.
|
|
76
61
|
|
|
77
62
|
The `with` syntax can be used to initialize the graph and ensure it is saved once the block is exited.
|
|
78
63
|
|
|
79
64
|
```
|
|
80
65
|
from edgeable import GraphDatabase
|
|
81
66
|
|
|
82
|
-
with
|
|
67
|
+
with GraphDatabase(filename="mygraph.db") as graph:
|
|
83
68
|
A = graph.put_node('A', {'type': 'building'})
|
|
84
69
|
B = graph.put_node('B', {'type': 'classroom'})
|
|
85
70
|
A.attach(B, {'relationship': 'contains'})
|
|
86
71
|
```
|
|
87
72
|
|
|
88
73
|
##### Graph Persistance
|
|
89
|
-
- `reload()` - Reload the graph from the file system. The persisted file is loaded automatically when the `GraphDatabase` instance is initialized, calling `
|
|
90
|
-
- `save()` - Save the graph to the file system. When using the `with` syntax, this is called automatically. Save operations are done in a way to be thread-safe and avoid corruption if the application terminates during a write.
|
|
74
|
+
- `reload()` - Reload the graph from the file system. The persisted file is loaded automatically when the `GraphDatabase` instance is initialized, calling `reload()` is only neccessary to reload it, overwriting any changes to nodes, edges and database properties. Registered callbacks are kept, and apply to the reloaded nodes and edges.
|
|
75
|
+
- `save()` - Save the graph to the file system. When using the `with` syntax, this is called automatically. Save operations are done in a way to be thread-safe and avoid corruption if the application terminates during a write: the content is written and synced to a temporary file in the same directory, which then replaces the database file. The directory must already exist.
|
|
76
|
+
|
|
77
|
+
Nodes, edges, their properties and the database properties are persisted. Callbacks are not.
|
|
78
|
+
|
|
79
|
+
Property values (on the database, nodes and edges) must be made up of the following types to be persisted: `None`, `bool`, `int`, `float`, `complex`, `str`, `bytes`, `bytearray`, `list`, `tuple`, `dict`, `set`, `frozenset`, `range`, `slice`, `datetime.datetime`, `datetime.date`, `datetime.time`, `datetime.timedelta`, `datetime.timezone`, `decimal.Decimal`, `fractions.Fraction`, `uuid.UUID`, `collections.OrderedDict`, `collections.deque` and `collections.Counter`. Other values, such as instances of your own classes, can be held in memory but `save()` raises `pickle.PicklingError` for them and leaves the existing file untouched.
|
|
80
|
+
|
|
81
|
+
The file is a gzip compressed pickle. When loading, anything other than Edgeable's own classes and the types above is refused with `pickle.UnpicklingError` rather than imported, so loading a file does not run code embedded in it. This is a safeguard and not a guarantee: a crafted file can still contain a misleading or very large graph, so only load database files from sources you trust. Files written by earlier releases can still be loaded, and are written in the current format on the next `save()`; earlier releases cannot read files in the current format.
|
|
91
82
|
|
|
92
83
|
##### Graph Nodes and Edges
|
|
93
84
|
|
|
94
85
|
- `put_node(id, properties={})` - Creates or retrieves the instance of `GraphNode` with the provided identifier. The optionally provided properties are set or updated on the node.
|
|
95
|
-
- `has_node(id)` - Taking a node identifier,
|
|
86
|
+
- `has_node(id)` - Taking a node identifier, returns a boolean indicating whether a node with that identifier exists in the database.
|
|
96
87
|
- `get_node(id)` - Taking a node identifier, return an instance of type `GraphNode` if it exists in the database. Returns `None` otherwise.
|
|
97
88
|
- `get_nodes(filter_fn=lambda node: True)` - Retrieve a list of `GraphNode` instances from the database. If the optional filter function is not provided, all nodes are returned, otherwise the filter function is used to return only matching nodes.
|
|
98
|
-
- `
|
|
89
|
+
- `get_edges(edge_filter_fn=lambda edge: True, node_filter_fn=lambda node: True)` - Retrieve a list of `GraphEdge` instances from the database. If the optional filter functions are not provided, all edges are returned, otherwise only edges matching `edge_filter_fn` whose source node matches `node_filter_fn` are returned. Filters can be any callable.
|
|
99
90
|
- `get_node_count()` - Return the number of nodes in the database.
|
|
100
91
|
- `get_edge_count()` - Return the number of edges in the database.
|
|
101
92
|
|
|
102
93
|
##### Graph Properties
|
|
103
|
-
|
|
94
|
+
Database properties are saved to and loaded from the file system together with the graph. Property keys must be strings.
|
|
95
|
+
|
|
96
|
+
- `set_property(key, value)` - Set a property on the database with the provided key and value.
|
|
104
97
|
- `set_properties(properties)` - Provide a dict to set multiple properites on the database.
|
|
105
|
-
- `get_property(key)` - Retrieve the
|
|
106
|
-
- `get_properties()` - Retrieve a `dict` containing all properties set on the
|
|
98
|
+
- `get_property(key)` - Retrieve the database's property value for the provided key.
|
|
99
|
+
- `get_properties()` - Retrieve a `dict` containing all properties set on the database.
|
|
107
100
|
- `has_property(key)` - Returns a boolean indicating whether the property key is defined.
|
|
108
101
|
- `delete_property(key)` - Removes a property.
|
|
109
102
|
|
|
110
103
|
##### Graph Callbacks
|
|
111
104
|
|
|
112
|
-
Event callbacks can be provided that will have the opportunity to process objects in the graph. Multiple callbacks can be defined for an event type. Each callbacks has an identifier, this can be specified when created or one will automatically be generated and returned. The id can be later used to overwrite or remove (set to `None`) the callback.
|
|
105
|
+
Event callbacks can be provided that will have the opportunity to process objects in the graph. Multiple callbacks can be defined for an event type. Each callbacks has an identifier, this can be specified when created or one will automatically be generated and returned. The id can be later used to overwrite or remove (set to `None`) the callback. Removing an id which is not registered does nothing. Callbacks can be any callable; anything else raises a `RuntimeError`.
|
|
113
106
|
|
|
114
107
|
- `on_create_node(fn, id=None)` - Sets or changes a callback that is called when a node is added to the graph.
|
|
115
108
|
- `on_create_edge(fn, id=None)` - Sets or changes a callback that is called when a edge is added to the graph.
|
|
116
109
|
- `on_delete_node(fn, id=None)` - Sets or changes a callback that is called when a node is deleted from the graph.
|
|
117
110
|
- `on_delete_edge(fn, id=None)` - Sets or changes a callback that is called when a edge is deleted from the graph.
|
|
118
111
|
|
|
119
|
-
Callback functions that return
|
|
112
|
+
Callback functions that return `False` will cancel the event; any other return value, including `None` and `0`, does not. Every callback registered for an event is called, even after one of them has cancelled it. Callbacks, like filter functions, can themselves read and modify the graph. Callback functions are not persisted with the database.
|
|
120
113
|
|
|
121
114
|
### Node Class
|
|
122
115
|
The `GraphNode` class represent nodes and associated properties within the graph. Nodes can be connected through directed or non-directed edges.
|
|
@@ -139,8 +132,8 @@ The `GraphNode` class represent nodes and associated properties within the graph
|
|
|
139
132
|
- `delete_property(key)` - Removes a property.
|
|
140
133
|
|
|
141
134
|
##### Node Routes
|
|
142
|
-
- `
|
|
143
|
-
- `
|
|
135
|
+
- `find_route_to(end, skip=[])` - Find a shortest route (by number of edges) from the current node to the `end` node, returned as a list of `GraphNode` instances starting with the current node and ending with `end`. Returns `None` if there is no route. Nodes in the optional `skip` list are not travelled through.
|
|
136
|
+
- `find_routes_to(end, effort=5)` - Find alternative routes from the current node to the `end` node, returned as a list of routes with the shortest first. After the shortest route, further routes are found by searching again while avoiding nodes used by the routes found so far. `effort` bounds how many nodes may be avoided at once: higher values find more, less direct routes and take longer.
|
|
144
137
|
|
|
145
138
|
##### Node Neighbors
|
|
146
139
|
- `find_neighbors(distance=1, distance_fn=lambda edge: 1)` - Find all nodes within a specified distance. By default, each edge is considered a distance of one. A custom function can be provided to provide a custom distance calculation.
|
|
@@ -162,7 +155,8 @@ The `GraphEdge` class representes the connections between `GraphNode` instances
|
|
|
162
155
|
|
|
163
156
|
## Resources
|
|
164
157
|
|
|
165
|
-
Build process: https://
|
|
158
|
+
Build process: https://github.com/LeeAdcock/edgeable/actions
|
|
166
159
|
|
|
167
|
-
|
|
160
|
+
Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
168
161
|
|
|
162
|
+
PyPi: https://pypi.org/project/edgeable/
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
1
3
|
from edgeable.threadlock import GraphModifyLock, GraphReadLock
|
|
2
4
|
|
|
3
5
|
from edgeable.edge import GraphEdge
|
|
4
6
|
from edgeable.node import GraphNode
|
|
5
7
|
from edgeable.database import GraphDatabase
|
|
8
|
+
|
|
9
|
+
# A library must not configure logging for the application using it.
|
|
10
|
+
logging.getLogger("edgeable").addHandler(logging.NullHandler())
|