New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

leafy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leafy

Another fast graph algorithms library

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

Leafy Graph Library

Leafy is a python graph library written in cython. This mix gives the speed of writing the library in c with the benefit of python bindings.

Usage

Graph Objects

Leafy supports Sparse Graphs, these create Adjacencey lists underneath.

To instantiate a graph object we need to know the number of nodes (verticies) in the graph, and if the graph is directed. Graphs defualt to undirected.

from leafy import Graph
g = Graph(4, True)
g.add_edge(0, 1)
g.add_edge(2, 3)
g.add_edge(2, 1)
g.list

Leafy can run Depth First Search (DFS) and Breadth First Search (BFS) on a graph and return the graph search properties.

To run a search we need to define the graph to search and the node to start from. Before you can view the properties we must call .run().

from leafy.search import DFS
dfs = DFS(g, 0)
dfs.run()
dfs.simple_path(12)
dfs.bridges

Digraphs

For diagraphs leafy supports DFS which can be imported from leafy.digraph

from leafy.digraph import DFS
dfs = DFS(g, 0)
dfs.run()
dfs.is_dag
dfs.topological_order()

Shortest Distance

For network shortest path leafy supports single source Dijkstra which can be imported from leafy.shortest_path

from leafy.shortest_path import Dijkstra
dij = Dijkstra(g, 0)
dij.run()
dij.path(3)

Keywords

FAQs


Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc