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

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()

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.11.tar.gz (9.3 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.11-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dgraph_flex-0.1.11.tar.gz
Algorithm Hash digest
SHA256 5f12848c71746ee5e90be0e5dbcd9e004c78386462444348ce9cc6b8a7eaac60
MD5 0fadf0e51442610c1149d85f21d89671
BLAKE2b-256 cca2d980ca7c1ccdba5ddd479527de3bb673cdb5db16323f740db87468cc4c60

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dgraph_flex-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c549cca3f2f435427f347142371400be902a878ff0e9e23cf0384d180154daeb
MD5 3a1cdc0e745032455853fe78b12a93ba
BLAKE2b-256 90b284a3fe18a09aff32c55734fbba308ed79617cdbcf3a3127ec29d11763bb3

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