sgraph

Hierarchical Graph Data Structures for Software Analysis

PyPI version License: MIT Python 3.8+

sgraph is a powerful Python library that provides data formats, structures, and algorithms for working with hierarchical graph structures. It’s particularly suited for representing and analyzing software architectures, dependencies, and complex system relationships.

πŸš€ Quick Start

pip install sgraph
from sgraph import SGraph, SElement, SElementAssociation

# Create a model
model = SGraph(SElement(None, ''))

# Add elements
file1 = model.createOrGetElementFromPath('/project/src/main.py')
file2 = model.createOrGetElementFromPath('/project/src/utils.py')

# Create relationships
dependency = SElementAssociation(file1, file2, 'imports')
dependency.initElems()

# Export to various formats
print(model.to_deps())  # Simple text format
print(model.to_xml())   # Rich XML format

✨ Key Features

πŸ—οΈ Flexible Data Structures

πŸ“Š Multiple Data Formats

πŸ” Powerful Analysis Tools

πŸ› οΈ Rich Ecosystem

🎯 Use Cases

Software Architecture Analysis

Analyze codebases to understand:

System Documentation

Generate up-to-date documentation:

Code Quality Assessment

Track and improve:

πŸ“– Documentation

🌟 Example: Analyzing a Real Project

from sgraph.modelapi import ModelApi

# Load a model from XML
api = ModelApi(filepath='project_model.xml')

# Find specific elements
functions = api.getElementsByName('authenticate')
for func in functions:
    print(f"Function: {func.name} at {func.getPath()}")

# Analyze dependencies
main_func = functions[0]
called = api.getCalledFunctions(main_func)
callers = api.getCallingFunctions(main_func)

print(f"Calls {len(called)} functions")
print(f"Called by {len(callers)} functions")

🏒 Production Usage

sgraph powers Softagram, a software analytics platform used by development teams worldwide to:

🀝 Contributing

We welcome contributions! Whether you’re:

Check out our contribution guidelines to get started.

πŸ“Š Performance

sgraph is designed for performance:


Ready to start analyzing your software architecture?
pip install sgraph