from morphik import Morphik
db = Morphik()
# Get a graph by name
graph = db.get_graph("finance_graph")
if graph.is_processing:
print("Graph still processing, waiting...")
graph = db.wait_for_graph_completion("finance_graph")
# Now safe to access entities and relationships
print(f"Graph has {len(graph.entities)} entities and {len(graph.relationships)} relationships")
# Access entities and relationships
for entity in graph.entities:
print(f"Entity: {entity.label} ({entity.type})")
for relationship in graph.relationships:
source_entity = next((e for e in graph.entities if e.id == relationship.source_id), None)
target_entity = next((e for e in graph.entities if e.id == relationship.target_id), None)
if source_entity and target_entity:
print(f"Relationship: {source_entity.label} --{relationship.type}--> {target_entity.label}")