![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A simple base implementation of a Directed Acyclic Graph, intended to be subclassed for more specific functionality.
A simple base implementation of a DAG. Users should feel free to subclass this DAG class to provide their desired functionality. The API is intended to be similar to the NetworkX API, though not an exact replica. Note that multiple edges between the same two nodes are not supported by this package.
from base_dag import DAG
# Initialize the DAG
dag = DAG()
# Add nodes and edges
dag.add_nodes_from([1, 2])
dag.add_node(3)
dag.add_edge((1, 2))
dag.add_edge((2, 3))
# Remove nodes and edges
dag.remove_edge((2, 3))
dag.remove_node(3)
# Re-add a third node.
dag.add_node(3)
# Extract the subgraph of nodes 1 and 2.
sub_dag = dag.subgraph([1, 2])
all_nodes = dag.nodes() # (1, 2, 3)
all_edges = dag.edges() # ( (1, 2), (2, 3) )
successors = dag.successors(1) # [2]
predecessors = dag.predecessors(2) # [1]
descendants = dag.descendants(1) # [2, 3]
ancestors = dag.ancestors(2) # [1]
in_degree = dag.indegree(2) # 1
out_degree = dag.outdegree(1) # 1
# Reverse the direction of the edges in the graph in place, without affecting the nodes at all.
dag.reverse()
sorted_nodes = dag.topological_sort()
generations = dag.topological_generations()
sorted_generations = dag.sorted_topological_generations()
has_path = dag.has_path(1, 3) # True
is_acyclic = dag.is_acyclic() # True
FAQs
A simple base implementation of a Directed Acyclic Graph, intended to be subclassed for more specific functionality.
We found that base-dag demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.