Build Status Documentation Status Latest Version Latest Version License

PyGraphistry: Explore Relationships

PyGraphistry is a Python visual graph analytics library to extract, transform, and load big graphs into Graphistry's visual graph analytics platform. It is typically used by data scientists, developers, and operational analysts on problems like visually mapping the behavior of devices and users.

The Python client makes it easy to go from your existing data to a Graphistry server. Through strong notebook support, data scientists can quickly go from data to accelerated visual explorations, and developers can quickly prototype stunning solutions with their users.

Graphistry supports unusually large graphs for interactive visualization. The client's custom WebGL rendering engine renders up to 8MM nodes and edges at a time, and most older client GPUs smoothly support somewhere between 100K and 1MM elements. The serverside GPU analytics engine supports even bigger graphs.

  1. Interactive Demo
  2. Graph Gallery
  3. Installation
  4. Tutorial
  5. API Reference

Demo of Friendship Communities on Facebook

Click to open interactive version! (For server-backed interactive analytics, use an API key) Source data: SNAP

PyGraphistry is...

Gallery

Twitter Botnet
Edit Wars on Wikipedia
Source: SNAP
100,000 Bitcoin Transactions
Port Scan Attack
Protein Interactions
Source: BioGRID
Programming Languages
Source: Socio-PLT project

Installation

You need to install the PyGraphistry client somewhere and connect it to a Graphistry server. We recommend the following options:

  1. Private Graphistry Server: One-click launch with Graphistry, PyGraphistry, and Jupyter Notebooks preinstalled and ready to go out-of-the-box (AWS and Azure)
  2. pip install graphistry: If you already have Jupyter Notebook installed or are using a system like Google Colab, install the PyGraphistry pip package. Connect it to a free Graphistry Hub account or a private Graphistry server.

Option 1: New users - Private Graphistry AWS/Azure Server with Preinstalled PyGraphistry client

For new users who have AWS accounts, simply launch the self-serve Graphistry AMI. See GrNaphistr.com for additional quick launch modes.

A private server provides several benefits for getting started:

The server gracefully stops/starts: Control potential server utility fees by simply stopping the server when not using it.

Option 2: PyGraphistry pip package - With Graphistry Hub or a private server

Install PyGraphistry into your own Python app or data science notebook environment such as Jupyter and Google Colab. Connect it to a Graphistry server such as the self-serve Graphistry AMI or a free Graphistry Hub account.

Install PyGraphistry with Python's pip package manager:

The latter two can be skipped if you already have the third-party Python packages at the appropriate versions installed.

Jupyter Notebook Integration

API Credentials

Provide your API credentials to upload data to your Graphistry GPU server:

import graphistry
#graphistry.register(key='Your key') # 1.0 API
#graphistry.register(api=3, username='your name', password='your pwd') # 2.0 API, logged out after 1hr
#graphistry.register(api=3, token='your JWT token') # 2.0 API, expires after 1hr

For the 2.0 API, your username/password are the same as your Graphistry account, and your session expires after 1hr. The temporary JWT token (1hr) can be generated via the REST API using your login credentials, or by visiting your landing page.

Optionally, for convenience, you may set your API key in your system environment and thereby skip the register step in all your notebooks. In your .profile or .bash_profile, add the following and reload your environment:

export GRAPHISTRY_API_KEY="Your key"

Server

Specify which Graphistry to reach:

graphistry.register(protocol='https', server='hub.graphistry.com')

Preconfigure private Graphistry servers to fill in this data for you.

Tutorial: Les Misérables

Let's visualize relationships between the characters in Les Misérables. For this example, we'll choose Pandas to wrangle data and IGraph to run a community detection algorithm. You can view the Jupyter notebook containing this example.

Our dataset is a CSV file that looks like this:

source target value
Cravatte Myriel 1
Valjean Mme.Magloire 3
Valjean Mlle.Baptistine 3

Source and target are character names, and the value column counts the number of time they meet. Parsing is a one-liner with Pandas:

import pandas
links = pandas.read_csv('./lesmiserables.csv')

Quick Visualization

If you already have graph-like data, use this step. Otherwise, try the Hypergraph Transform

PyGraphistry can plot graphs directly from Pandas dataframes, IGraph graphs, or NetworkX graphs. Calling plot uploads the data to our visualization servers and return an URL to an embeddable webpage containing the visualization.

To define the graph, we bind source and destination to the columns indicating the start and end nodes of each edges:

import graphistry
graphistry.register(protocol='https', server='hub.graphistry.com', token='YOUR_JWT_TOKEN_HERE')

plotter = graphistry.bind(source="source", destination="target")
plotter.plot(links)

You should see a beautiful graph like this one: Graph of Miserables

Adding Labels

Let's add labels to edges in order to show how many times each pair of characters met. We create a new column called label in edge table links that contains the text of the label and we bind edge_label to it.

links["label"] = links.value.map(lambda v: "#Meetings: %d" % v)
plotter = plotter.bind(edge_label="label")
plotter.plot(links)

Controlling Node Title, Size, Color, and Location

Let's size nodes based on their PageRank score and color them using their community. IGraph already has these algorithms implemented for us. If IGraph is not already installed, fetch it with pip install python-igraph. Warning: pip install igraph will install the wrong package!

We start by converting our edge dateframe into an IGraph. The plotter can do the conversion for us using the source and destination bindings. Then we create two new node attributes (pagerank & community).

ig = plotter.pandas2igraph(links)
ig.vs['pagerank'] = ig.pagerank()
ig.vs['community'] = ig.community_infomap().membership

plotter.bind(point_color='community', point_size='pagerank').plot(ig)

To control the location, add x and y columns to the node tables (see demos). You may also want to bind point_title.

Second Graph of Miserables

Next Steps

  1. If you don't have an API key to a Graphistry server, one-click launch Graphistry in AWS
  2. Check out the analyst and developer introductions, or try your own CSV
  3. Explore the demos folder for your favorite file format, database, API, or kind of analysis

References