Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!--
## [unreleased]
-->

### Added

- `algorithms` module
- `bfs()`, `shortest_path()`, `all_shortest_paths()`, `connected_components()`, `neighborhood()` algorithms with engine wrapper

## [0.5] - 2026-06-10

Expand Down
3 changes: 2 additions & 1 deletion docs/query-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ engine.query.Person.outgoing("WORKS_AT")
Equivalent to:

```python
engine.query.Person.traverse("WORKS_AT", direction="outgoing")
from graphite import Direction
engine.query.Person.traverse("WORKS_AT", direction=Direction.OUTGOING)
```

---
Expand Down
2 changes: 1 addition & 1 deletion docs/references/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Filter nodes based on type

Filter nodes with given fields

## `traverse(relation_type: Optional[str] = None, direction: str = 'outgoing') -> QueryResult`
## `traverse(relation_type: Optional[str] = None, direction: Direction = Direction.OUTGOING) -> QueryResult`

Traverse relations from current nodes
Returns a new query result with connected nodes and traversed relations
Expand Down
42 changes: 42 additions & 0 deletions examples/basic_algorithms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Example of usage of basic graph algorithms including BFS, etc. in Graphite with internal
`algorithms` module.
"""

from random import randint

from src.graphite import Direction, GraphiteEngine
from src.graphite.algorithms import bfs, neighborhood
# Use this in your code instead:
#from graphite import GraphiteEngine
#from graphite.algorithms import bfs, neighborhood

engine = GraphiteEngine()
engine.define_node("""
node Object
""")
for i in range(30):
engine.create_node("Object", f"node{i}")

engine.define_relation("""
relation Edge
Object -> Object
""")

for i in range(100):
engine.create_relation(f"node{i % 30}", f"node{(i + randint(0, 100)) % 30}", "Edge")

# Find ALL possible paths to node10 with less than 6 steps
print(bfs(
engine,
"node0",
"node10",
stop_at_first=False,
max_depth=5,
direction=Direction.BOTH,
allow_direction_switch=True
))

print(neighborhood(engine, "node0", 4))
# Important algorithms are available directly in engine, so this has same result:
#print(engine.neighborhood("node0", 4))
7 changes: 4 additions & 3 deletions examples/example_suite.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
Example usages of Graphite in separate functions. You can run a function to see its result.
"""
# noinspection PyPackageRequirements
import graphite
# import src.graphite as graphite # Just for test dev version

from src import graphite
# Use this in your code instead:
#import graphite

# =============== EXAMPLE COMPLETE DSL LOADING ===============

Expand Down
7 changes: 4 additions & 3 deletions examples/generic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Runs a generic example for Graphite module.
"""
from datetime import date
# noinspection PyPackageRequirements
import graphite
# import src.graphite as graphite # Just for test dev version

from src import graphite
# Use this in your code instead:
#import graphite

engine = graphite.engine()

Expand Down
13 changes: 8 additions & 5 deletions src/graphite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
from .instances import Node, Relation
from .migration import Migration
from .parser import GraphiteParser
from .query import QueryBuilder, QueryResult
from .query import QueryBuilder, QueryResult, Direction
from .serialization import GraphiteJSONEncoder
from .types import DataType, Field, NodeType, RelationType
from .utils import SecurityWarning, engine, node, relation

simplefilter('always', SecurityWarning)

__all__ = [
'GraphiteEngine',
'Node', 'Relation',
'Migration',
'GraphiteParser',
'QueryBuilder', 'QueryResult', 'Direction',
'GraphiteJSONEncoder',
'DataType', 'Field', 'NodeType', 'RelationType',
'Node', 'Relation', 'GraphiteJSONEncoder',
'GraphiteParser', 'QueryResult', 'QueryBuilder',
'GraphiteEngine', 'Migration', 'SecurityWarning',
'node', 'relation', 'engine'
'SecurityWarning', 'engine', 'node', 'relation',
]
Loading
Loading