The open-source adapter for working with RDF databases and SPARQL queries in Jupyter notebooks leveraging the yFiles Graphs for Jupyter plugin.
Project description
yFiles Jupyter Graphs for SPARQL
Easily visualize a SPARQL query for RDF graphs in a Jupyter Notebook.
This packages provides an easy-to-use interface to the yFiles Graphs for Jupyter widget to directly visualize queries.
Installation
Just install it from the Python Package Index
pip install yfiles_jupyter_graphs_for_sparql==0.9.0rc1
or see README_DEV.md to build it yourself.
Usage
from SPARQLWrapper import SPARQLWrapper
from yfiles_jupyter_graphs_for_sparql import SparqlGraphWidget
g = SparqlGraphWidget(wrapper=SPARQLWrapper("http://dbpedia.org/sparql"))
q = """
SELECT ?sub ?p ?ob
WHERE {
?sub ?p ?ob .
}
"""
g.show_query(q)
See examples
Supported Environments
The widget uses yFiles Graphs for Jupyter at its core, and therefore runs in any environment that is supported by it, see supported environments.
Documentation
The main class SparqlGraphWidget provides the following API:
Constructor
SparqlGraphWidget: Creates a new class instance with the following arguments
| Argument | Description | Default |
|---|---|---|
limit |
The node limit which is added to all queries | 50 |
wrapper |
A SPARQL wrapper, that is used to send queries to | None |
layout |
Can be used to specify a general default node and edge layout. Available algorithms are: "circular", "hierarchic", "organic", "interactive_organic_layout", "orthogonal", "radial", "tree", "map", "orthogonal_edge_router", "organic_edge_router" | organic |
For all arguments, there is a set_[arg] and get_[arg] method.
Methods
[!IMPORTANT]
If you want to use SELECT query types, ensure you select all three triple components—subject, predicate, and object. Otherwise, a graph cannot be constructed from the selected data. For an example look at the Getting Started notebook
show_query(query, layout: Optional[str] = None)query: The query that should be visualized.layout (Optional[str]): The graph layout that is used. This overwrites the general layout in this specific graph instance. The following arguments are supported:hierarchicorganicinteractive_organic_layoutcircularcircular_straight_lineorthogonaltreeradialmaporthogonal_edge_routerorganic_edge_router
To get an overview of the data structure, you can use the following function.
The output is constrained by the limit property, meaning
only a partial schema may be displayed depending on the dataset.
show_schema()
The graph visualization can be adjusted by adding configurations to each node label or edge type with the following functions:
-
add_subject_configuration(predicate: Union[str, list[str]], **kwargs: Dict[str, Any])predicate: The predicate of the subject this configuration should be used for.**kwargs: Visualization configuration for the given node label. The following arguments are supported:text: The text that displayed at the node. By default, the node's label is used.color: A convenience color binding for the node (see alsostylesargument).size: The size of the node.styles: A dictionary that may contain the following attributescolor,shape(one of 'ellipse', ' hexagon', 'hexagon2', 'octagon', 'pill', 'rectangle', 'round-rectangle' or 'triangle'),image.property: Allows to specify additional properties on the node, which may be bound by other bindings.type: Defines a specific "type" for the node as described in yFiles Graphs for Jupyter which affects the automatic positioning of nodes (same "type"s are preferred to be placed next to each other).parent_configuration: Configure grouping for this node label. See configurations_example.ipynb for examples.heat: A heat value in between 0 and 1.
-
add_object_configuration(predicate: Union[str, list[str]], **kwargs: Dict[str, Any])predicate: The predicate of the object this configuration should be used for.**kwargs: Visualization configuration for the given node label. The following arguments are supported:text: The text that displayed at the node. By default, the node's label is used.color: A convenience color binding for the node (see alsostylesargument).size: The size of the node.styles: A dictionary that may contain the following attributescolor,shape(one of 'ellipse', ' hexagon', 'hexagon2', 'octagon', 'pill', 'rectangle', 'round-rectangle' or 'triangle'),image.property: Allows to specify additional properties on the node, which may be bound by other bindings.type: Defines a specific "type" for the node as described in yFiles Graphs for Jupyter which affects the automatic positioning of nodes (same "type"s are preferred to be placed next to each other).parent_configuration: Configure grouping for this node label. See configurations_example.ipynb for examples.heat: A heat value in between 0 and 1.
-
add_predicate_configuration(type: Union[str, list[str]], **kwargs: Dict[str, Any])type: The predicate type(s) for which this configuration should be used. Supports*to address all types.**kwargs: Visualization configuration for the given predicate type. The following arguments are supported:text: The text that displayed at the edge. By default, the predicate's type is used.color: The edge's color.thickness_factor: The edge's stroke thickness factor. By default,1.property: Allows to specify additional properties on the edge, which may be bound by other bindings.heat: A heat value in between 0 and 1.
-
add_parent_relationship_configuration(type: Union[str, list[str]], reverse: Optional[bool] = False) -> Nonetype: The predicate type that should be visualized as node grouping hierarchy instead of the actual relationship.reverse: By default the target node is considered as parent. This can be reverted with this argument.
For a detailed documentation look at the core widget
To remove a configuration use the following functions:
del_object_configuration(type): Deletes configuration for the given object predicate type.del_subject_configuration(type): Deletes configuration for the given subject predicate type.del_edge_configurations(type): Deletes configuration for the given predicate type.del_parent_predicate_configuration(type: Union[str, list[str]]) -> None: Deletes configuration for the given parent predicate type(s).
How configuration bindings are resolved
The configuration bindings (see add_object_configuration, add_subject_configuration or add_predicate_configuration) are resolved as follows:
If the configuration binding is a string, the package first tries to resolve it against the item's properties and uses the property value if available. If there is no property with the given key, the string value itself is used as a constant binding.
In case you want to create a constant string value as binding, which also happens to be a property key, use a binding function with a constant string as return value instead.
If the configuration binding is a function, the return value of the function is used as value for the respective configuration.
yFiles Graphs for Jupyter
The graph visualization is provided by yFiles Graphs for Jupyter, a versatile graph visualization widget for Jupyter Notebooks.
It can import and visualize graphs from various popular Python packages (e.g. NetworkX, PyGraphviz, igraph) or just structured node and edge lists.
And provides a rich set of visualization options to bring your data to life (see the example notebooks).
Feature Highlights
For a detailed feature guide, check out the main widget example notebooks
Code of Conduct
This project and everyone participating in it is governed by the Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to contact@yworks.com.
Feedback
This widget is by no means perfect. If you find something is not working as expected we are glad to receive an issue report from you. Please make sure to search for existing issues first and check if the issue is not an unsupported feature or known issue. If you did not find anything related, report a new issue with necessary information. Please also provide a clear and descriptive title and stick to the issue templates. See issues.
Dependencies
License
See LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yfiles_jupyter_graphs_for_sparql-1.0.0.tar.gz.
File metadata
- Download URL: yfiles_jupyter_graphs_for_sparql-1.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5e74e08cc76d859331b4ed08f0e579c1d043e972f304f2762dbe362a28b0dae
|
|
| MD5 |
55eb7a40d075258c0fb5600dd68dbc56
|
|
| BLAKE2b-256 |
4f577824be26b1f9afda06bc4dc53bc698274857497be5d92c5bec5e9537bf1f
|
Provenance
The following attestation bundles were made for yfiles_jupyter_graphs_for_sparql-1.0.0.tar.gz:
Publisher:
publish.yml on yWorks/yfiles-jupyter-graphs-for-sparql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yfiles_jupyter_graphs_for_sparql-1.0.0.tar.gz -
Subject digest:
a5e74e08cc76d859331b4ed08f0e579c1d043e972f304f2762dbe362a28b0dae - Sigstore transparency entry: 191819276
- Sigstore integration time:
-
Permalink:
yWorks/yfiles-jupyter-graphs-for-sparql@95c96ce1fdaf23047083cbfbf2ac97f9eacd0048 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/yWorks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95c96ce1fdaf23047083cbfbf2ac97f9eacd0048 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file yfiles_jupyter_graphs_for_sparql-1.0.0-py3-none-any.whl.
File metadata
- Download URL: yfiles_jupyter_graphs_for_sparql-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e259f3fb6140f9833267d1ca2f84a32f9a2d9de184668c8579ca24a6534e68f
|
|
| MD5 |
32fd6d3cb5ed4f166f312d976f2aab04
|
|
| BLAKE2b-256 |
56a7b9faf7bc407a3c18cc01528695001d94b50c67ba909a62cee785a24280ab
|
Provenance
The following attestation bundles were made for yfiles_jupyter_graphs_for_sparql-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on yWorks/yfiles-jupyter-graphs-for-sparql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
yfiles_jupyter_graphs_for_sparql-1.0.0-py3-none-any.whl -
Subject digest:
3e259f3fb6140f9833267d1ca2f84a32f9a2d9de184668c8579ca24a6534e68f - Sigstore transparency entry: 191819277
- Sigstore integration time:
-
Permalink:
yWorks/yfiles-jupyter-graphs-for-sparql@95c96ce1fdaf23047083cbfbf2ac97f9eacd0048 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/yWorks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@95c96ce1fdaf23047083cbfbf2ac97f9eacd0048 -
Trigger Event:
workflow_dispatch
-
Statement type: