Socket
Socket
Sign inDemoInstall

propgraph

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    propgraph

A graph structure that can take arbitrary properties.


Maintainers
1

Readme

prop-graph

A graph structure that can take arbitrary properties.

Usage

In the examples that follow, I'll be working with a graph that looks as follows:

                a                               g
            /       \                       /       \
        b               c               h               i
    /       \       /       \       /
d               e               f

Build graph

graph = Graph([
    ("a", "b"),
    ("a", "c"),
    ("b", "d"),
    ("b", "e"),
    ("c", "e"),
    ("c", "f"),
    ("g", "h"),
    ("g", "i"),
    ("h", "f"),
])

graph.print()
# a 
#         b 
#                 d 
#                 e 
#         c 
#                 e 
#                 f 
# g 
#         h 
#                 f 
#         i

Add properties

props = {
    "c": "interesting",
    "g": "interesting",
}
graph.add_property("type", props)

Finding nodes

parent_ids = graph.find_by(lambda n: len(n.children) > 0)
print(parent_ids)
# ['a', 'b', 'c', 'g', 'h']

root_ids = graph.find_by(lambda n: len(n.parents) == 0)
print(root_ids)
# ['a', 'g']

interesting_ids = graph.find_by(lambda n: n["type"] == "interesting")
print(interesting_ids)
# ['c', 'g']

Deleting nodes

graph.delete_by(lambda n: n["type"] == "interesting")
graph.print()
# a 
#         b 
#                 d 
#                 e 
#         e 
#         f 
# h 
#         f 
# i

Keywords

FAQs


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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc