This is a utility library to help construct graphs & other structures from TypeQL query results.
typedb-graph-utils is available on pip.
pip install typedb-graph-utils- Ensure you have build
python3 -m pip install build
- Build (creates files under dist/)
python3 -m build# Creates files under dist/
- Install from the wheel created in the previous step:
python3 -m pip install dist/typedb_graph_utils-<version>-py3-none-any.whl
The main component of the library is the TypeDBAnswerConverter abstract class, which you must implement.
A sample implementation is provided in networkx_builder.py.
Example usage:
from typedb.driver import TransactionType, Credentials, DriverOptions, TypeDB, QueryOptions
from typedb_graph_utils import NetworkXBuilder, MatplotlibVisualizer
driver = TypeDB.driver("127.0.0.1:1729", Credentials("admin", "password"), DriverOptions(is_tls_enabled=False))
DB_NAME = "typedb_graph_utils_readme"
if DB_NAME in [db.name for db in driver.databases.all()]:
driver.databases.get(DB_NAME).delete()
driver.databases.create(DB_NAME)
with driver.transaction(DB_NAME, TransactionType.READ) as tx:
answers = list(tx.query("match let $x = 1;", QueryOptions(include_query_structure=True)).resolve())
builder = NetworkXBuilder(answers[0].query_structure())
for (i, answer) in enumerate(answers):
builder.add_answer(i, answer)
graph = builder.finish()
MatplotlibVisualizer.draw(graph)A longer tutorial is at tutorial.ipynb
You don't have to "install from source".
- Manually install the library dependencies
python3 -m pip install -e .
- Manually install the dev dependencies
python3 -m pip install -e '.[dev]'
- Run tests:
python3 -m pytest
I created a 'main' in the tests file to visualise the graphs created by the tests. Run it:
python3 -m tests.test_simple