TypeDB graph utils for python
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file typedb_graph_utils-3.7.0.tar.gz.
File metadata
- Download URL: typedb_graph_utils-3.7.0.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f9a1230adb268a3af5c3ee31ba0d82a4dd95d257e300344789b24893d2a7d52
|
|
| MD5 |
7cde9bd53f97b2bbe550a5a4924ad2a9
|
|
| BLAKE2b-256 |
5f554411c8d62de00df90caf456f622350be74d61daee8a94bc84c88739d281a
|
File details
Details for the file typedb_graph_utils-3.7.0-py3-none-any.whl.
File metadata
- Download URL: typedb_graph_utils-3.7.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6357ffdd69f2456e8925b63f189cca40ccb57d8830e823e54552e1e44204b120
|
|
| MD5 |
dc181aea0475520b6b679b0091ffe21c
|
|
| BLAKE2b-256 |
e831f0c87c361f6d6b50bd3731b165053b131bb98db600ccb6a5b2b63f227adc
|