Skip to main content

Gephipy

This project is Python wrapper of Gephi toolkit, thanks to Jpype which does the bindings between Java and Python.

It provides helpers to easy the use of Gephy toolkit for Pythonist, even if you still ned to know the Java API.

How to use

  • Install the lib pip install gephipy

  • Import gephipy

from gephipy import gephipy

Then you can use the Gephi toolkit or the GephiPy features.

Example

from gephipy import gephipy

# Java imports must be after the gephipy import
from org.gephi.layout.plugin.forceAtlas2 import ForceAtlas2Builder
from org.gephi.layout.plugin.random import Random
from org.gephi.layout.plugin.noverlap import NoverlapLayoutBuilder
from org.gephi.statistics.plugin import Modularity, GraphDistance
from org.openide.util import Lookup
from org.gephi.appearance.api import AppearanceController
from org.gephi.appearance.plugin import RankingNodeSizeTransformer, PartitionElementColorTransformer
from org.gephi.appearance.plugin.palette import PaletteManager
from org.gephi.statistics.plugin import GraphDistance, Modularity

#
# Create a workspace
#
workspace = gephipy.create_workspace()

#
# Import a GEXF file
#
gephipy.import_gexf(workspace, "./graph.gexf")
graphModel = gephipy.get_graph_model(workspace)

#
# Compute some metrics
#

# Louvain
modularity = Modularity()
modularity.execute(graphModel)

# Betweeness centrality
centrality = GraphDistance()
centrality.setDirected(True)
centrality.execute(graphModel)

#
# Apply appearance
# Here it is really looks like java code
#

appearanceController = Lookup.getDefault().lookup(AppearanceController)
appearanceModel = appearanceController.getModel()

# Size Make node size based on centrality
centralityColumn = graphModel.getNodeTable().getColumn(GraphDistance.BETWEENNESS)
centralityRanking = appearanceModel.getNodeFunction(centralityColumn, RankingNodeSizeTransformer)
centralityTransformer = centralityRanking.getTransformer()
centralityTransformer.setMinSize(10)
centralityTransformer.setMaxSize(100)
appearanceController.transform(centralityRanking)


# Color by community
communityColumn = graphModel.getNodeTable().getColumn(Modularity.MODULARITY_CLASS)
colorPartition = appearanceModel.getNodeFunction(communityColumn, PartitionElementColorTransformer)
partition = colorPartition.getPartition()
palette = PaletteManager.getInstance().generatePalette(partition.size(graphModel.getGraph()))
partition.setColors(graphModel.getGraph(), palette.getColors())
appearanceController.transform(colorPartition)


#
# Run Layouts
#

# Random layout
random = Random().buildLayout()
random.setGraphModel(gephipy.get_graph_model(workspace))
random.initAlgo();
random.goAlgo()
random.endAlgo();

# FA2 layout
fa2 = ForceAtlas2Builder().buildLayout()
fa2.setGraphModel(gephipy.get_graph_model(workspace))
fa2.resetPropertiesValues();
fa2.initAlgo();
for x in range(1000):
  fa2.goAlgo()

# Noverlap layout
noverlap = NoverlapLayoutBuilder().buildLayout()
noverlap.setGraphModel(gephipy.get_graph_model(workspace))
noverlap.initAlgo()
noverlap.endAlgo()

#
# Export your graph
#

gephipy.export_gexf(workspace, "my-gephi-graph.gexf")

Metadata

Release files for Gephipy 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Gephipy 0.0.2
File Size Uploaded
gephipy-0.0.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Gephipy 0.0.2
File Interpreter ABI Platform
gephipy-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / gephipy-0.0.2.tar.gz

Download URL gephipy-0.0.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
af7847703117d7b48dafd9789bda04557024cb4df048601b1339d5eab3c431fd
BLAKE2b-256 checksum
How to use checksums
c1411fde9718fea2e4a245140d1fdc384ddbad3251d94451067cd45a19be68bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.11 Linux/6.8.0-71-generic

Release files / gephipy-0.0.2-py3-none-any.whl

Download URL gephipy-0.0.2-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a686729ebf6a4791dfa515f85d74a208849b316e8d5efba2c425d7002270ff0
BLAKE2b-256 checksum
How to use checksums
5e63367c51e84423ad3a71a9426a94ff7de631a703980b86d04275e83c13f2c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.11.11 Linux/6.8.0-71-generic

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page