Skip to main content

Python package bridging the gap between the KONECT project and networkx

Project description

KONECT2NetworkX

Bridging the gap between KONECT and NetworkX

The KONECT project (Koblenz Network Collection) has

the 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 into NetworkX graph 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.

Example

Suppose 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.

import networkx as nx
import konect2networkx as k2n
import matplotlib.pyplot as plt

G = k2n.get('ucidata-zachary') # get the Zachary karate club network
nx.draw(G)
plt.savefig('karate.png', format = 'PNG')

For reference, the Zachary karate club network can be found here.

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 built

Installation

Clone this repository:

git clone https://github.com/jkudla/konect2networkx

Navigate 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 :)

Note: This package will shortly be published on PyPI.

Documentation

All features are encapsulated in just two functions.

Downloading Networks

download_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. A RetrieveException is raised if

  • HTTP request failed (e. g. cannot connect to the KONECT website), or
  • Network with specific ID does not exist, or
  • Archive cannot be unpacked due to IO issues.

The RetrieveException comes with a message stating the scenario that applies.

Getting Networks into NetworkX

get(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_network is 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:

  • LoadException if the network file cannot read or is too short such that it cannot contain a network.
  • ParseException if the network file is malformed, i. e., does not follow the specification outlined in the KONECT Handbook.

Both exceptions will contain a message describing the circumstances.

Contributing

This project has just been launched and any kind of contribution is warmly welcomed. Have a look at the issue tracker for bug reports and feature requests.

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

konect2networkx-0.1.0.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

konect2networkx-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file konect2networkx-0.1.0.tar.gz.

File metadata

  • Download URL: konect2networkx-0.1.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for konect2networkx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 372773bc617392e3b09476c5238a64a31c590dc909e9d8e02a6417cc223337db
MD5 e49556b457e75f9c99fdf44f38373a06
BLAKE2b-256 f0164283a4f59d25866348d11a050cfabdbc0f1691210c65194cf5b9b16e7169

See more details on using hashes here.

File details

Details for the file konect2networkx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: konect2networkx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for konect2networkx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7afdebdc4ae962a804f68ad30fddb11933db26f5a23d4536561c30405a06f6f6
MD5 a2a99b07f1ea390efdc3585a27b27e23
BLAKE2b-256 73b39859705f5937f94931617d0611d5f30e6bef6fa51dcffbc5922d69a995a9

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