Package: konect2networkx
KONECT2NetworkXBridging the gap between KONECT and NetworkXTheKONECT project(Koblenz Network Collection) hasthe goal to collect network datasets, analyse them, and make available all analyses online.This project, KONECT2NetworkX, aims to make these network datasets even more accessible and easier to use by providing a Python package that transforms them intoNetworkXgraph objects. To this end, KONECT2NetworkX features functions to download networks by their names given on the KONECT website and parse them into NetworkX graph objects.ExampleSuppose we want to download a network, use NetworkX to draw it and save the figure to a PNG file. This merely requires three lines of essential code, each line doing of the steps.importnetworkxasnximportkonect2networkxask2nimportmatplotlib.pyplotaspltG=k2n.get('ucidata-zachary')# get the Zachary karate club networknx.draw(G)plt.savefig('karate.png',format='PNG')For reference, the Zachary karate club network can be foundhere.With logging enabled, the console output will look like this:[KONECT2NetworkX] Downloading network ucidata-zachary
[KONECT2NetworkX] Attemping to download network to ucidata-zachary.tar.bz2
[KONECT2NetworkX] HTTP request successful, writing network to ucidata-zachary.tar.bz2
[KONECT2NetworkX] Network successfully unpacked!
[KONECT2NetworkX] Seeking main network file
[KONECT2NetworkX] Main network file found under standard name ucidata-zachary/out.ucidata-zachary
[KONECT2NetworkX] Main network file successfully read, launching parser
[KONECT2NetworkX] Network metadata parsed: unipartite, undirected, unweighted, no multigraph
[KONECT2NetworkX] Parsing size information
[KONECT2NetworkX] Network has 34 nodes and 78 edges in total
[KONECT2NetworkX] Building NetworkX graph object
[KONECT2NetworkX] NetworkX graph object builtInstallationThe easiest way is to install KONECT2NetworkX from PyPI:pip install konect2networkxThat's it!Alternatively, clone this repository:git clone https://github.com/jkudla/konect2networkxNavigate into the resulting directory and install the package using pip:pip install -e .Voilà – now you should be able to use KONECT2NetworkX just like in the example above :)DocumentationAll features are encapsulated in just two functions.Downloading Networksdownload_network(id,logging=True)This will download a network from the KONECT website and unpack the archive file. The logging option toggles printing status messages to the standard output. ARetrieveExceptionis raised ifHTTP request failed (e. g. cannot connect to the KONECT website), orNetwork with specific ID does not exist, orArchive cannot be unpacked due to IO issues.TheRetrieveExceptioncomes with a message stating the scenario that applies.Getting Networks into NetworkXget(id,download=True,logging=True)This is where the magic happens! It will parse the specific network from KONECT format to a NetworkX graph object, which is returned upon success. If the download option is enabled (as by default),download_networkis invoked to first download the network. If the download option is disabled, the function assumes an unpacked network directory is present. The logging option toggles printing status messages to the standard output.Two exceptions may be raised:LoadExceptionif the network file cannot read or is too short such that it cannot contain a network.ParseExceptionif the network file is malformed, i. e., does not follow the specification outlined in theKONECT Handbook.Both exceptions will contain a message describing the circumstances.ContributingThis project has just been launched and any kind of contribution is warmly welcomed. Have a look at theissue trackerfor bug reports and feature requests.