Graph visualisation with TypeDB
This is a utility library to help construct graphs & other structures from TypeQL query results.
Install from source:
- 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
Using the library
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
Testing
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
Run the sample
I created a 'main' in the tests file to visualise the graphs created by the tests. Run it:
python3 -m tests.test_simple
Metadata
Release files for typedb-graph-utils 3.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| typedb_graph_utils-3.7.0.tar.gz | 19.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typedb_graph_utils-3.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.9 kB
Release files / typedb_graph_utils-3.7.0.tar.gz
| Download URL | typedb_graph_utils-3.7.0.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f9a1230adb268a3af5c3ee31ba0d82a4dd95d257e300344789b24893d2a7d52
|
|
BLAKE2b-256 checksum How to use checksums |
5f554411c8d62de00df90caf456f622350be74d61daee8a94bc84c88739d281a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.18
|
Release files / typedb_graph_utils-3.7.0-py3-none-any.whl
| Download URL | typedb_graph_utils-3.7.0-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6357ffdd69f2456e8925b63f189cca40ccb57d8830e823e54552e1e44204b120
|
|
BLAKE2b-256 checksum How to use checksums |
e831f0c87c361f6d6b50bd3731b165053b131bb98db600ccb6a5b2b63f227adc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.18
|