Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Knowledge Graph Exchange

Python Run testsDocumentation Status Quality Gate Status Maintainability Rating Coverage PyPI Docker

KGX (Knowledge Graph Exchange) is a Python library and set of command line utilities for exchanging Knowledge Graphs (KGs) that conform to or are aligned to the Biolink Model.

The core datamodel is a Property Graph (PG), represented internally in Python using a networkx MultiDiGraph model.

KGX allows conversion to and from:

KGX will also provide validation, to ensure the KGs are conformant to the Biolink Model: making sure nodes are categorized using Biolink classes, edges are labeled using valid Biolink relationship types, and valid properties are used.

Internal representation is a property graph, specifically a networkx MultiDiGraph.

The structure of this graph is expected to conform to the Biolink Model standard, as specified in the KGX format specification.

In addition to the main code-base, KGX also provides a series of command line operations.

Example usage

Validate:

poetry run kgx validate -i tsv tests/resources/merge/test2_nodes.tsv tests/resources/merge/test2_edges.tsv

Merge:

poetry run kgx merge —merge-config tests/resources/test-merge.yaml 

Graph Summary:

poetry run kgx graph-summary -i tests/resources/graph_nodes.tsv  -o summary.txt

Transform:

poetry run kgx transform —transform-config tests/resources/test-transform-tsv-rdf.yaml

Error Detection and Reporting

Non-redundant JSON-formatted structured error logging is now provided in KGX Transformer, Validator, GraphSummary and MetaKnowledgeGraph operations. See the various unit tests for the general design pattern (using the Validator as an example here):

from kgx.validator import Validator
from kgx.transformer import Transformer

Validator.set_biolink_model("2.11.0")

# Validator assumes the currently set Biolink Release
validator = Validator()

transformer = Transformer(stream=True)

transformer.transform(
    input_args = {
        "filename": [
            "graph_nodes.tsv",
            "graph_edges.tsv",
        ],
        "format": "tsv",
    },
    output_args={
        "format": "null"
    },
    inspector=validator,
)

# Both the Validator and the Transformer can independently capture errors

# The Validator, from the overall semantics of the graph...
# Here, we just report severe Errors from the Validator (no Warnings)
validator.write_report(open("validation_errors.json", "w"), "Error")

# The Transformer, from the syntax of the input files... 
# Here, we catch *all* Errors and Warnings (by not providing a filter)
transformer.write_report(open("input_errors.json", "w"))

The JSON error outputs will look something like this:

{
    "ERROR": {
        "MISSING_EDGE_PROPERTY": {
            "Required edge property 'id' is missing": [
                "A:123->X:1",
                "B:456->Y:2"
            ],
            "Required edge property 'object' is missing": [
                "A:123->X:1"
            ],
            "Required edge property 'predicate' is missing": [
                "A:123->X:1"
            ],
            "Required edge property 'subject' is missing": [
                "A:123->X:1",
                "B:456->Y:2"
            ]
        }
    },
    "WARNING": {
        "DUPLICATE_NODE": {
          "Node 'id' duplicated in input data": [
            "MONDO:0010011",
            "REACT:R-HSA-5635838"
          ]
        }
    }
}

This system reduces the significant redundancies of earlier line-oriented KGX logging text output files, in that graph entities with the same class of error are simply aggregated in lists of names/identifiers at the leaf level of the JSON structure.

The top level JSON tags originate from the MessageLevel class and the second level tags from the ErrorType class in the error_detection module, while the third level messages are hard coded as log_error method messages in the code.

It is likely that additional error conditions within KGX can be efficiently captured and reported in the future using this general framework.

Installation

Installing from PyPI

KGX is available on PyPI and can be installed using pip as follows,

pip install kgx

To install a particular version of KGX, be sure to specify the version number,

pip install kgx==0.5.0

Installing from GitHub

Clone the GitHub repository and then install,

git clone https://github.com/biolink/kgx
cd kgx
poetry install

Setting up a testing environment for Neo4j

This release of KGX supports graph source and sink transactions with Neo4j 4.4.

KGX has a suite of tests that rely on Docker containers to run Neo4j specific tests.

To set up the required containers, first install Docker on your local machine.

Once Docker is up and running, run the following commands:

docker run -d --name kgx-neo4j-integration-test -p 7474:7474 -p 7687:7687 --env NEO4J_AUTH=neo4j/test neo4j:4.4
docker run -d --name kgx-neo4j-unit-test -p 7474:7474 -p 7687:7687 --env NEO4J_AUTH=neo4j/test neo4j:4.4

Note: The integration and unit test containers use the same ports and cannot run simultaneously. Setting up the Neo4j container is optional. If there is no container set up then the tests that rely on them are skipped.

Setting up a testing environment for ArangoDB

KGX also has a suite of tests that rely on a running ArangoDB instance. A single container serves both unit and integration tests:

docker run -d -p 8529:8529 --env ARANGO_NO_AUTH=1 arangodb/arangodb:latest

Note: Setting up the ArangoDB container is optional. If ArangoDB is not reachable on localhost:8529 then the tests that rely on it are skipped.

Metadata

Release files for kgx 2.8.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kgx 2.8.0rc2
File Size Uploaded Provenance Actions
kgx-2.8.0rc2.tar.gz 3.1 MB Without provenance Details for kgx-2.8.0rc2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kgx 2.8.0rc2
File Interpreter ABI Platform Actions
kgx-2.8.0rc2-py3-none-any.whl Python 3 none any Details for kgx-2.8.0rc2-py3-none-any.whl

Total release size: 4.5 MB

Release files / kgx-2.8.0rc2.tar.gz

Download URL kgx-2.8.0rc2.tar.gz
Size 3.1 MB
Tags Source
SHA-256 checksum
How to use checksums
86f0d133435699dd9c999e0c50a397d89114471c2a307c8e2aefe407dd7747c1
BLAKE2b-256 checksum
How to use checksums
352def18d286cb489752176b5345648410641ad7d9b5ac9bf8af00e643f60c47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / kgx-2.8.0rc2-py3-none-any.whl

Download URL kgx-2.8.0rc2-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ed8263c048dcbab1bf73703effae0f14785dd1872d5903263519bbd2868bbb88
BLAKE2b-256 checksum
How to use checksums
5c9f4556481d3cf3dfd454544e03a8e98bf8d443b2fc80e8e82cf8ef3a0885b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for kgx 2.8.0rc2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page