Skip to main content

A wrapper of Gephi toolkit for Python

Project description

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")

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

gephipy-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

gephipy-0.0.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file gephipy-0.0.2.tar.gz.

File metadata

  • Download URL: gephipy-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.11 Linux/6.8.0-71-generic

File hashes

Hashes for gephipy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 af7847703117d7b48dafd9789bda04557024cb4df048601b1339d5eab3c431fd
MD5 ea6075bb1b35438dee8332840b75196f
BLAKE2b-256 c1411fde9718fea2e4a245140d1fdc384ddbad3251d94451067cd45a19be68bf

See more details on using hashes here.

File details

Details for the file gephipy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gephipy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.11 Linux/6.8.0-71-generic

File hashes

Hashes for gephipy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9a686729ebf6a4791dfa515f85d74a208849b316e8d5efba2c425d7002270ff0
MD5 57c0de7e656b55be9b6d8b791e079ca9
BLAKE2b-256 5e63367c51e84423ad3a71a9426a94ff7de631a703980b86d04275e83c13f2c8

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