Skip to main content

Create D3 visualization networks with Python

Project description

PyNetworkD3

Create D3 visualization networks with Python

PyPI - Version Tests Linters

Installation

Install using pip!

$ pip install pynetworkd3

Input JSON syntax

{
    "nodes": [
        {
          "id": "id1",
          "attribute 1": "value attribute 1",
          "attribute 2": "value attribute 2",
          (...)
          "attribute N": "value attribute N",
        },
        {
          "id": "id2",
          "attribute 1": "value attribute 1",
          "attribute 2": "value attribute 2",
          (...)
          "attribute N": "value attribute N",
        },
        (...)
    ],
    "links": [
        {
            "source": "id1",
            "target": "id2",
            "attribute 1": "value attribute 1",
            "attribute 2": "value attribute 2",
            (...)
            "attribute N": "value attribute N",
        },
        (...)
    ]
}
  • Every dictionary in "nodes" must have the id key. The other keys are optionals.

  • Every dictionary in "links" must have the source and target key. The other keys are optionals. Also, each id in source and target must redirect to an existing node in "nodes".

Usage

To use the library, import the Graph object directly and use the export method to create a .html with the visualization.

from PyNetworkD3 import Graph

dataset = {
    "nodes": [{"id": 1},{"id": 2},{"id": 3},{"id": 4},{"id": 5}],
    "links": [
        {"source": 1, "target": 3},
        {"source": 2, "target": 3},
        {"source": 1, "target": 3},
        {"source": 5, "target": 3},
        {"source": 4, "target": 1},
    ]
}

graph = Graph(dataset, width=300, height=200, radio=10, tooltip=["id"])

graph.export("output.html)

Also you can write the instance in the last line of the notebook's cell (ckeck the example in colab) to view the visualization.

Developing

This library uses PyTest as the test suite runner, and PyLint, Flake8, Black, ISort and MyPy as linters. It also uses Poetry as the default package manager.

The library includes a Makefile that has every command you need to start developing. If you don't have it, install Poetry using:

make get-poetry

Then, create a virtualenv to use throughout the development process, using:

make build-env

Activate the virtualenv using:

. .venv/bin/activate

Deactivate it using:

deactivate

To add a new package, use Poetry:

poetry add <new-package>

To run the linters, you can use:

# The following commands auto-fix the code
make black!
make isort!

# The following commands just review the code
make black
make isort
make flake8
make mypy
make pylint

To run the tests, you can use:

make tests

Releasing

To make a new release of the library, git switch to the master branch and execute:

make bump! minor

The word minor can be replaced with patch or major, depending on the type of release. The bump! command will bump the versions of the library, create a new branch, add and commit the changes. Then, just merge that branch to master. Finally, execute a merge to the stable branch. Make sure to update the version before merging into stable, as PyPi will reject packages with duplicated versions.

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

PyNetworkD3-0.0.9.tar.gz (14.7 kB view hashes)

Uploaded Source

Built Distribution

PyNetworkD3-0.0.9-py3-none-any.whl (20.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page