Skip to main content

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:

  1. Ensure you have build
    • python3 -m pip install build
  2. Build (creates files under dist/)
    • python3 -m build # Creates files under dist/
  3. 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".

  1. Manually install the library dependencies
    • python3 -m pip install -e .
  2. Manually install the dev dependencies
    • python3 -m pip install -e '.[dev]'
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typedb_graph_utils-3.7.0.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typedb_graph_utils-3.7.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

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

Hashes for typedb_graph_utils-3.7.0.tar.gz
Algorithm Hash digest
SHA256 5f9a1230adb268a3af5c3ee31ba0d82a4dd95d257e300344789b24893d2a7d52
MD5 7cde9bd53f97b2bbe550a5a4924ad2a9
BLAKE2b-256 5f554411c8d62de00df90caf456f622350be74d61daee8a94bc84c88739d281a

See more details on using hashes here.

File details

Details for the file typedb_graph_utils-3.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for typedb_graph_utils-3.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6357ffdd69f2456e8925b63f189cca40ccb57d8830e823e54552e1e44204b120
MD5 dc181aea0475520b6b679b0091ffe21c
BLAKE2b-256 e831f0c87c361f6d6b50bd3731b165053b131bb98db600ccb6a5b2b63f227adc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page