Skip to main content

A package for working with directed graphs

Project description

dgraph_flex

Package to support flexible storage of directed graphs, specifically for the support of directed graphs and causal structure analysis.

Changed edges from a list to a dict using the edge name src --> tar to make it easier to address, query and set

sample usage

from dgraph_flex import DgraphFlex

# create the graph object
obj = DgraphFlex()
# add edges to graph object
obj.add_edge('A', '-->', 'B', color='green', strength=-0.5, pvalue=0.01)
obj.add_edge('B', '-->', 'C', color='red', strength=-.5, pvalue=0.001)
obj.add_edge('C', 'o->', 'E', color='green', strength=0.5, pvalue=0.005)
obj.add_edge('B', 'o-o', 'D')
obj.add_edge('F', '<->', 'B')

# to modify an existing edge
obj.modify_existing_edge('A', 'B', color='green', strength=0.2, pvalue=0.0001)

# Save the graph to a file 'sample_graph' with a default format of png and  resolution of 300
# The format suffix is automatically added to the provided filename.  A graphviz source 'dot'
# file is also generated. This can be edited and rerendered with the 'dot' command.

obj.save_graph('sample_graph')

Here is the generated graph

Example Graph

for use in jupyter notebook

Graphviz (static)

from dgraph_flex import DgraphFlex

obj = DgraphFlex()
# add edges to graph object
obj.add_edge('A', '-->', 'B', color='green', strength=-0.5, pvalue=0.01)
obj.add_edge('B', '-->', 'C', color='red', strength=-.5, pvalue=0.001)
obj.add_edge('C', 'o->', 'E', color='green', strength=0.5, pvalue=0.005)
obj.add_edge('D', 'o-o', 'B')
obj.add_edge('F', '<->', 'B')

# render to window
obj.show_graph()

Excalidraw (interactive)

show_excalidraw() renders the graph as an interactive SVG canvas inline in the notebook. You can pan, zoom, and drag nodes. No additional dependencies or CDN access required — the visualization is fully self-contained.

from dgraph_flex import DgraphFlex

obj = DgraphFlex()
obj.add_edge('A', '-->', 'B', color='green', strength=-0.5, pvalue=0.01)
obj.add_edge('B', '-->', 'C', color='red', strength=-.5, pvalue=0.001)
obj.add_edge('C', 'o->', 'E', color='green', strength=0.5, pvalue=0.005)
obj.add_edge('D', 'o-o', 'B')

# interactive canvas in notebook
obj.show_excalidraw()

# read-only view with custom height
obj.show_excalidraw(view_mode=True, height="400px")

# only show directed edges (-->, o->)
obj.show_excalidraw(directed_only=True)

You can also export the graph to Excalidraw format:

# save as .excalidraw file (can be opened at excalidraw.com)
obj.save_excalidraw('my_graph')

# get raw Excalidraw JSON dict
data = obj.to_excalidraw()

sample yaml file

Here is a sample yaml file describing a graph

GENERAL:
  version: 2.0
  framework: dgraph_flex
  gvinit:  # global graphviz initialization
    nodes:
      shape: oval
      color: black

GRAPH:
  edges: # Use indentation for the dictionary under 'edges'
    "A --> B": # Key for the first edge
      properties: # Indent for the 'properties' dictionary
        strength: 0.5
        pvalue: 0.01
      gvprops: # Indent for the 'gvprops' dictionary
        color: green
    "B --> C": # Key for the second edge
      properties: # Indent for 'properties'
        strength: -0.5
        pvalue: 0.001
      gvprops: # Indent for 'gvprops'
        color: red
    "C o-> E": # Key for the third edge
      properties: # Indent for 'properties'
        strength: 0.5
        pvalue: 0.0005
      gvprops: # Indent for 'gvprops'
        color: green
    "B o-o D": # Key for the fourth edge
      properties: # Indent for 'properties'
        strength: 0.5
        pvalue: 0.0005
      gvprops: # Indent for 'gvprops'
        color: black

Here is python code that reads in the graph and outputs a png

from dgraph_flex import DgraphFlex

obj = DgraphFlex(yamlpath='graph_sample.yaml')
obj.read_yaml(self.config['yamlpath'])
obj.load_graph()

unit tests

python -m unittest tests/*.py

build

python -m build

# upload
twine upload dist/*

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

dgraph_flex-0.1.12.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

dgraph_flex-0.1.12-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file dgraph_flex-0.1.12.tar.gz.

File metadata

  • Download URL: dgraph_flex-0.1.12.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dgraph_flex-0.1.12.tar.gz
Algorithm Hash digest
SHA256 c82ad7249c9b2e6a9ebbf3e66254726043e0f76b74738a8a44cc0fdfceaab84d
MD5 f0f4f11e9e97f56889bbad777089c6da
BLAKE2b-256 a9d52e61fe520b9474724e953d50f8e56e53a51b5e016202e5e6e26e6330b310

See more details on using hashes here.

File details

Details for the file dgraph_flex-0.1.12-py3-none-any.whl.

File metadata

  • Download URL: dgraph_flex-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for dgraph_flex-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 0fc6a681ececaca94295c17e16870c635542d5bbadf2a102fae218e6498b376a
MD5 406dc62a358a1fa37da122e839697312
BLAKE2b-256 0eca435fb5d54b8f924ffc4d1e1297a6e182df57014d2781dff2be8addde1abb

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