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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sgraph-0.7.1.tar.gz
.
File metadata
- Download URL: sgraph-0.7.1.tar.gz
- Upload date:
- Size: 58.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 435675c30182868fd1010c10fdf78cb91168e5a69fa14a004f5823aae13b7fa7 |
|
MD5 | c1cf1c280abf781a2c5a1fa66adf5180 |
|
BLAKE2b-256 | 1e17ec3a27953664f8d4e20cf99c9ba0efbe39fe8947882a8e170e1659433a9a |
File details
Details for the file sgraph-0.7.1-py3-none-any.whl
.
File metadata
- Download URL: sgraph-0.7.1-py3-none-any.whl
- Upload date:
- Size: 67.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c458690d3d8471e99d9a0a77f1a4c47170906af0fe7f3b95b766db01cd40a1d2 |
|
MD5 | 0aca422545bf8818cf9555949ff63a4c |
|
BLAKE2b-256 | abdaf54d4b3830bbfabc87d3ea030306774b5c1c1574aadbae5e765a5932979b |