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
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/*
Metadata
Release files for dgraph-flex 0.1.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dgraph_flex-0.1.12.tar.gz | 15.4 kB | Without provenance | Details for dgraph_flex-0.1.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dgraph_flex-0.1.12-py3-none-any.whl | Python 3 | none | any | Details for dgraph_flex-0.1.12-py3-none-any.whl |
Total release size: 29.9 kB
Release files / dgraph_flex-0.1.12.tar.gz
| Download URL | dgraph_flex-0.1.12.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c82ad7249c9b2e6a9ebbf3e66254726043e0f76b74738a8a44cc0fdfceaab84d
|
|
BLAKE2b-256 checksum How to use checksums |
a9d52e61fe520b9474724e953d50f8e56e53a51b5e016202e5e6e26e6330b310
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / dgraph_flex-0.1.12-py3-none-any.whl
| Download URL | dgraph_flex-0.1.12-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fc6a681ececaca94295c17e16870c635542d5bbadf2a102fae218e6498b376a
|
|
BLAKE2b-256 checksum How to use checksums |
0eca435fb5d54b8f924ffc4d1e1297a6e182df57014d2781dff2be8addde1abb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for dgraph-flex 0.1.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.