Skip to main content

sgraph hierarchic graph data structure, format and algorithms

Project description

sgraph

sgraph contains data format, structures and algorithms to work with hierachic graph structures. Typically it is suitable for representing software structures.

Documentation: https://softagram.github.io/sgraph/

See also sgraph-mcp-server for enabling AI agents to utilize sgraph information.

Install

pip install sgraph

Contributions

The project is welcoming all contributions.

Core Ontology

A model, SGraph consists of a root SElement, which may have children of the same type (as in XML). Attribute information can be stored via key-value pairs into them. The SElement objects can be connected together via SElementAssociation objects.

Example model

nginx model has an nginx root element that represents the main directory. Inside it, there is a src element. And inside src, there is core.

https://github.com/nginx/nginx/tree/master/src inside core, there are several elements, e.g. nginx.c and nginx.h

https://github.com/nginx/nginx/blob/master/src/core/nginx.c

Because nginx.c contains #include directive to nginx.h, in the model it is formulated so that there is a relationship (also called as association) from nginx.c element to nginx.h

To make model more explicit, that particular relationship should be annotated with type "inc" to describe the dependency type.

It is also possible to have other attributes assigned to relationships other than type but typically this is rare.

XML format

In XML dataformat, minimalism is the goal to make it simple and clean. Integers are used as unique identifiers for the elements. In the example case, the nginx.h element is assigned with ID 2 and the relationship that is inside nginx.c refers this way to nginx.h

This integer reference system has been designed to make the data format highly performing even with 10 million element models.

Deps data format - line based simple format for easy scripting

In Deps data format (usually a .txt file), the above model can be described minimally this way:

/nginx/src/core/nginx.c:/nginx/src/core/nginx.h:inc

Although this might seem very compelling data format to use, it is not recommended for very large models, e.g. 10 million elements.

Using the API

Creating a simple model:

>>> from sgraph import SGraph
>>> from sgraph import SElement
>>> from sgraph import SElementAssociation
>>> x = SGraph(SElement(None, ''))
>>> x
<sgraph.sgraph.SGraph object at 0x7f2efae9ad30>

>>> x.to_deps(fname=None)

>>> e1 = x.createOrGetElementFromPath('/path/to/file.x')
>>> e2 = x.createOrGetElementFromPath('/path/to/file.y')
>>> x.to_deps(fname=None)
/path
/path/to
/path/to/file.x
/path/to/file.y

>>> x.to_xml(fname=None)
<model version="2.1">
  <elements>
  <e n="path" >
    <e n="to" >
      <e n="file.x" >
      </e>
      <e n="file.y" >
      </e>
    </e>
  </e>
</elements>
</model>

>>> ea = SElementAssociation(e1, e2, 'use')
>>> ea.initElems()  # ea is not connected to the model before this call.
>>> x.to_deps(fname=None)
/path/to/file.x:/path/to/file.y:use
/path
/path/to
>>>

>>> x.to_xml(fname=None)
<model version="2.1">
  <elements>
  <e n="path" >
    <e n="to" >
      <e n="file.x" >
        <r r="2" t="use" />
      </e>
      <e i="2" n="file.y" >
      </e>
    </e>
  </e>
 </elements>
</model>

Current utilization

Softagram uses it for building up the information model about the analyzed software.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgraph-1.2.3.tar.gz (66.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sgraph-1.2.3-py3-none-any.whl (78.2 kB view details)

Uploaded Python 3

File details

Details for the file sgraph-1.2.3.tar.gz.

File metadata

  • Download URL: sgraph-1.2.3.tar.gz
  • Upload date:
  • Size: 66.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for sgraph-1.2.3.tar.gz
Algorithm Hash digest
SHA256 7340d2f3d11aef7d58d127416115af1cf3bce271cce72b832e108944441c5c04
MD5 19ba3a4bca44901047c98c84736b12e9
BLAKE2b-256 0365356bbb169b399095ad01d31778af44d2d822c559d89552a3236d3b08458f

See more details on using hashes here.

File details

Details for the file sgraph-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: sgraph-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for sgraph-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cfc44ebdaf906a6724573de423e5698ce8141a444d29261cb08a26834d0a803b
MD5 701cf77555557b3a5569de098e9d1a59
BLAKE2b-256 19d25b903c6342009d59d5864e5b9986cfd771c745263acdab64b479772e70a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page