edgeable 0.1.79__tar.gz → 0.2.1__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.
Files changed (37) hide show
  1. edgeable-0.2.1/LICENSE +21 -0
  2. {edgeable-0.1.79/edgeable.egg-info → edgeable-0.2.1}/PKG-INFO +56 -32
  3. edgeable-0.1.79/PKG-INFO → edgeable-0.2.1/README.md +31 -36
  4. {edgeable-0.1.79 → edgeable-0.2.1}/edgeable/__init__.py +5 -0
  5. edgeable-0.2.1/edgeable/database.py +425 -0
  6. {edgeable-0.1.79 → edgeable-0.2.1}/edgeable/edge.py +18 -8
  7. edgeable-0.2.1/edgeable/node.py +430 -0
  8. edgeable-0.2.1/edgeable/threadlock.py +57 -0
  9. edgeable-0.1.79/README.md → edgeable-0.2.1/edgeable.egg-info/PKG-INFO +61 -19
  10. edgeable-0.2.1/edgeable.egg-info/SOURCES.txt +29 -0
  11. edgeable-0.2.1/edgeable.egg-info/requires.txt +7 -0
  12. edgeable-0.2.1/pyproject.toml +39 -0
  13. edgeable-0.2.1/tests/test_database.py +99 -0
  14. edgeable-0.2.1/tests/test_database_events.py +189 -0
  15. edgeable-0.2.1/tests/test_database_persistance.py +56 -0
  16. edgeable-0.2.1/tests/test_database_properties.py +44 -0
  17. edgeable-0.2.1/tests/test_edge.py +46 -0
  18. edgeable-0.2.1/tests/test_edge_properties.py +107 -0
  19. edgeable-0.2.1/tests/test_fix_db_callbacks_validation.py +214 -0
  20. edgeable-0.2.1/tests/test_fix_db_persistence.py +399 -0
  21. edgeable-0.2.1/tests/test_fix_db_threadlock.py +337 -0
  22. edgeable-0.2.1/tests/test_fix_node_edges.py +481 -0
  23. edgeable-0.2.1/tests/test_fix_node_routing.py +256 -0
  24. edgeable-0.2.1/tests/test_node.py +134 -0
  25. edgeable-0.2.1/tests/test_node_neighbors.py +49 -0
  26. edgeable-0.2.1/tests/test_node_properties.py +55 -0
  27. edgeable-0.2.1/tests/test_node_route.py +72 -0
  28. edgeable-0.2.1/tests/test_threadlock.py +107 -0
  29. edgeable-0.1.79/edgeable/database.py +0 -213
  30. edgeable-0.1.79/edgeable/node.py +0 -279
  31. edgeable-0.1.79/edgeable/threadlock.py +0 -73
  32. edgeable-0.1.79/edgeable.egg-info/SOURCES.txt +0 -12
  33. edgeable-0.1.79/edgeable.egg-info/requires.txt +0 -1
  34. edgeable-0.1.79/setup.py +0 -31
  35. {edgeable-0.1.79 → edgeable-0.2.1}/edgeable.egg-info/dependency_links.txt +0 -0
  36. {edgeable-0.1.79 → edgeable-0.2.1}/edgeable.egg-info/top_level.txt +0 -0
  37. {edgeable-0.1.79 → edgeable-0.2.1}/setup.cfg +0 -0
edgeable-0.2.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Lee Adcock
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.
@@ -1,25 +1,37 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: edgeable
3
- Version: 0.1.79
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
3
+ Version: 0.2.1
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.6
13
- Classifier: Programming Language :: Python :: 3.7
14
- Classifier: Programming Language :: Python :: 3.8
15
- Classifier: Programming Language :: Python :: 3.9
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
+ License-File: LICENSE
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest; extra == "dev"
24
+ Requires-Dist: coverage; extra == "dev"
25
+ Requires-Dist: black~=26.0; extra == "dev"
26
+ Requires-Dist: build; extra == "dev"
27
+ Requires-Dist: twine; extra == "dev"
28
+ Dynamic: license-file
17
29
 
18
30
  <img src="https://raw.githubusercontent.com/LeeAdcock/edgeable/master/assets/logo.png" alt="Edgeable" width="300"/>
19
31
 
20
- *Edgeable is an easy to use, in memory, peristable graph database. It is perfect for prototyping, exploring, and quick implementation in Python applications.* The library is written completely in Python, supporting 3.6+.
32
+ *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
33
 
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.
34
+ 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
35
 
24
36
  ## Installation
25
37
 
@@ -32,7 +44,7 @@ The Edgeable database library can easily be installed with pip using `pip instal
32
44
  ```
33
45
  from edgeable import GraphDatabase
34
46
 
35
- graph = new GraphDatabase()
47
+ graph = GraphDatabase()
36
48
  A = graph.put_node('A', {'type': 'building'})
37
49
  B = graph.put_node('B', {'type': 'classroom'})
38
50
  A.attach(B, {'relationship': 'contains'})
@@ -50,7 +62,7 @@ with open('edges.csv') as csvfile:
50
62
  for row in reader:
51
63
  node_a = graph.put_node(row[0].strip())
52
64
  node_b = graph.put_node(row[1].strip())
53
- node_1.attach(node_b)
65
+ node_a.attach(node_b)
54
66
  ```
55
67
 
56
68
  ### Write a csv file of edges
@@ -72,51 +84,61 @@ with open('edges.csv', 'w') as csvfile:
72
84
  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
85
 
74
86
  ##### 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.
87
+ 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.
88
+
89
+ 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
90
 
77
91
  The `with` syntax can be used to initialize the graph and ensure it is saved once the block is exited.
78
92
 
79
93
  ```
80
94
  from edgeable import GraphDatabase
81
95
 
82
- with new GraphDatabase(filename="mygraph.db") as graph:
96
+ with GraphDatabase(filename="mygraph.db") as graph:
83
97
  A = graph.put_node('A', {'type': 'building'})
84
98
  B = graph.put_node('B', {'type': 'classroom'})
85
99
  A.attach(B, {'relationship': 'contains'})
86
100
  ```
87
101
 
88
102
  ##### Graph Persistance
89
- - `reload()` - Reload the graph from the file system. The persisted file is loaded automatically when the `GraphDatabase` instance is initialized, calling `load()` is only neccessary to reload it, overwriting any changes.
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.
103
+ - `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.
104
+ - `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.
105
+
106
+ Nodes, edges, their properties and the database properties are persisted. Callbacks are not.
107
+
108
+ 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.
109
+
110
+ 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
111
 
92
112
  ##### Graph Nodes and Edges
93
113
 
94
114
  - `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, return an instance of type `GraphNode`.
115
+ - `has_node(id)` - Taking a node identifier, returns a boolean indicating whether a node with that identifier exists in the database.
96
116
  - `get_node(id)` - Taking a node identifier, return an instance of type `GraphNode` if it exists in the database. Returns `None` otherwise.
97
117
  - `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
- - `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 the function is used to return only matching edges.
118
+ - `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
119
  - `get_node_count()` - Return the number of nodes in the database.
100
120
  - `get_edge_count()` - Return the number of edges in the database.
101
121
 
102
122
  ##### Graph Properties
103
- - `set_property(key, value)` - Set a property on the node with the provided key and value.
123
+ Database properties are saved to and loaded from the file system together with the graph. Property keys must be strings.
124
+
125
+ - `set_property(key, value)` - Set a property on the database with the provided key and value.
104
126
  - `set_properties(properties)` - Provide a dict to set multiple properites on the database.
105
- - `get_property(key)` - Retrieve the node's property value for the provided key.
106
- - `get_properties()` - Retrieve a `dict` containing all properties set on the node.
127
+ - `get_property(key)` - Retrieve the database's property value for the provided key.
128
+ - `get_properties()` - Retrieve a `dict` containing all properties set on the database.
107
129
  - `has_property(key)` - Returns a boolean indicating whether the property key is defined.
108
130
  - `delete_property(key)` - Removes a property.
109
131
 
110
132
  ##### Graph Callbacks
111
133
 
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.
134
+ 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
135
 
114
136
  - `on_create_node(fn, id=None)` - Sets or changes a callback that is called when a node is added to the graph.
115
137
  - `on_create_edge(fn, id=None)` - Sets or changes a callback that is called when a edge is added to the graph.
116
138
  - `on_delete_node(fn, id=None)` - Sets or changes a callback that is called when a node is deleted from the graph.
117
139
  - `on_delete_edge(fn, id=None)` - Sets or changes a callback that is called when a edge is deleted from the graph.
118
140
 
119
- Callback functions that return a `False` value will cancel the event. Callback functions are not persisted with the database.
141
+ 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
142
 
121
143
  ### Node Class
122
144
  The `GraphNode` class represent nodes and associated properties within the graph. Nodes can be connected through directed or non-directed edges.
@@ -139,8 +161,8 @@ The `GraphNode` class represent nodes and associated properties within the graph
139
161
  - `delete_property(key)` - Removes a property.
140
162
 
141
163
  ##### Node Routes
142
- - `find_routes_to(end, effort=5)`
143
- - `find_route_to(end, skip=[])`
164
+ - `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.
165
+ - `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
166
 
145
167
  ##### Node Neighbors
146
168
  - `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 +184,9 @@ The `GraphEdge` class representes the connections between `GraphNode` instances
162
184
 
163
185
  ## Resources
164
186
 
165
- Build process: https://app.travis-ci.com/github/LeeAdcock/edgeable
187
+ Build process: https://github.com/LeeAdcock/edgeable/actions
166
188
 
167
- PyPi: https://pypi.org/project/edgeable/
189
+ Changelog: [CHANGELOG.md](CHANGELOG.md)
168
190
 
191
+ PyPi: https://pypi.org/project/edgeable/
192
+ License: [MIT](LICENSE)
@@ -1,25 +1,8 @@
1
- Metadata-Version: 2.1
2
- Name: edgeable
3
- Version: 0.1.79
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, peristable graph database. It is perfect for prototyping, exploring, and quick implementation in Python applications.* The library is written completely in Python, supporting 3.6+.
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 = new GraphDatabase()
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
- node_1.attach(node_b)
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 new GraphDatabase(filename="mygraph.db") as graph:
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 `load()` is only neccessary to reload it, overwriting any changes.
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, return an instance of type `GraphNode`.
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
- - `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 the function is used to return only matching edges.
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
- - `set_property(key, value)` - Set a property on the node with the provided key and value.
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 node's property value for the provided key.
106
- - `get_properties()` - Retrieve a `dict` containing all properties set on the node.
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 a `False` value will cancel the event. Callback functions are not persisted with the database.
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
- - `find_routes_to(end, effort=5)`
143
- - `find_route_to(end, skip=[])`
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,9 @@ The `GraphEdge` class representes the connections between `GraphNode` instances
162
155
 
163
156
  ## Resources
164
157
 
165
- Build process: https://app.travis-ci.com/github/LeeAdcock/edgeable
158
+ Build process: https://github.com/LeeAdcock/edgeable/actions
166
159
 
167
- PyPi: https://pypi.org/project/edgeable/
160
+ Changelog: [CHANGELOG.md](CHANGELOG.md)
168
161
 
162
+ PyPi: https://pypi.org/project/edgeable/
163
+ License: [MIT](LICENSE)
@@ -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())