pysparql-anything


Namepysparql-anything JSON
Version 0.9.0.3 PyPI version JSON
download
home_pageNone
SummaryThe SPARQL Anything Python library.
upload_time2024-09-11 12:18:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords rdf sparql knowledge graphs linked data rdflib sematic web
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![How to](https://img.shields.io/badge/How%20to-use-green.svg)](#basic_usage)
[![How to](https://img.shields.io/badge/How%20to-join-blue.svg)](https://forms.gle/t1paTLz7jVu3RYnu8)
[![Live demo](https://img.shields.io/badge/Live-demo-yellow.svg)](https://tinyurl.com/ybj4vxzt)

# PySPARQL Anything
###### The SPARQL Anything Python Library

## Table of Contents
1. [Introduction](#intro)
   1. [Façade-X](#fx)
   2. [Querying Anything](#query_anything)
2. [User Guide](#user_guide)
   1. [Installation](#installation)
   2. [Basic Usage](#basic_usage)
   3. [Tutorial](#tutorial)
3. [API](#api)
   1. [Methods](#methods)
4. [Development & Maintanance](#dev_guide)
   1. [Building PySPARQL Anything](#build)
   2. [SPARQL Anything Updates](#sa_updates)

## 1. Introduction <a name="intro"></a>

SPARQL Anything is a data integration and Semantic Web re-engineering system that implements the Façade-X meta-model, resolving the heterogeneity of sources by structurally mapping them onto a set of RDF components, upon
which semantic mappings can be constructed.

PySPARQL Anything is a python wrapper for the SPARQL Anything tool. It purports to offer to Python users dealing with tasks of data integration and RDF data construction and analysis access to the capabilities offered by SPARQL Anything.
Furthermore, it enables developers to inject RDF graphs into their Python RDFlib, NetworkX  or pandas-powered data science processes, opening new opportunities for developing complex, data- intensive pipelines for generating and manipulating RDF data.

### 1.1. Façade-X <a name="fx"></a>
Facade-X is a simplistic meta-model used by SPARQL Anything transformers to generate RDF data from diverse data sources. Intuitively, Facade-X uses a subset of RDF as a general approach to represent the source content as-it-is but in RDF. The model combines two types of elements: containers and literals. Facade-X always has a single root container. Container members are a combination of key-value pairs, where keys are either RDF properties or container membership properties. Instead, values can be either RDF literals or other containers. 

This is a generic example of a Facade-X data object (more examples below):
```sparql
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
[] a fx:root ; rdf:_1 [
    xyz:someKey "some value" ;
    rdf:_1 "another value with unspecified key" ;
    rdf:_2 [
        rdf:type xyz:MyType ;
        rdf:_1 "another value"
    ]
] .
```
More details on the Facade-X metamodel can be found [here](https://github.com/SPARQL-Anything/sparql.anything/blob/v1.0-DEV/Facade-X.md).

### 1.2. Querying anything <a name="query_anything"></a>
SPARQL Anything extends the Apache Jena ARQ processors by overloading the SERVICE operator, as in the following example:

Suppose having this JSON file as input (also available at https://sparql-anything.cc/example1.json)
```json
[
  {
    "name": "Friends",
    "genres": [
      "Comedy",
      "Romance"
    ],
    "language": "English",
    "status": "Ended",
    "premiered": "1994-09-22",
    "summary": "Follows the personal and professional lives of six twenty to thirty-something-year-old friends living in Manhattan.",
    "stars": [
      "Jennifer Aniston",
      "Courteney Cox",
      "Lisa Kudrow",
      "Matt LeBlanc",
      "Matthew Perry",
      "David Schwimmer"
    ]
  },
  {
    "name": "Cougar Town",
    "genres": [
      "Comedy",
      "Romance"
    ],
    "language": "English",
    "status": "Ended",
    "premiered": "2009-09-23",
    "summary": "Jules is a recently divorced mother who has to face the unkind realities of dating in a world obsessed with beauty and youth. As she becomes older, she starts discovering herself.",
    "stars": [
      "Courteney Cox",
      "David Arquette",
      "Bill Lawrence",
      "Linda Videtti Figueiredo",
      "Blake McCormick"
    ]
  }
]
```
With SPARQL Anything you can select the TV series starring "Courteney Cox" with the SPARQL query
```sparql
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>

SELECT ?seriesName
WHERE {

    SERVICE <x-sparql-anything:https://sparql-anything.cc/example1.json> {
        ?tvSeries xyz:name ?seriesName .
        ?tvSeries xyz:stars ?star .
        ?star fx:anySlot "Courteney Cox" .
    }

}
```
and get this result without caring of transforming JSON to RDF.
```powershell
seriesName
"Cougar Town"
"Friends"
```
      
## 2. User Guide <a name="user_guide"></a>

### 2.1. Installation <a name="installation"></a>

PySPARQL Anything is released on PyPI. To install it on your machine type the following in your command prompt:
```
$ pip install pysparql-anything 
```

To remove PySPARQL Anything from your machine, do the following.

In your command prompt execute
```python
$ python
>>> import pysparql_anything as sa
>>> sa.utilities.remove_sparql_anything()
>>> exit()
$ pip uninstall pysparql-anything
```

### 2.2. Basic Usage <a name="basic_usage"></a>

PySPARQL Anything comes equipped with a CLI tool. Its functionalities can therefore either be accessed through the
command prompt or by importing the library into your scripts. Choosing the latter method will also enable the user
to return the results of their SPARQL queries as specific Python objects.

Below we show a few basic steps to illustrate usage.

1) To use the CLI tool, pen the command prompt with the current working directory set to the main folder of a SPARQL Anything project.
The CLI tool is accessed with the ```sparql-anything``` command. Executing
```
$ sparql-anything -h
```
will pull up the instructions on how to use the CLI:
```
Welcome to the PySPARQL Anything CLI. For the optional flags see below.

options:
  -h, --help            show this help message and exit
  -j [JAVA ...], --java [JAVA ...]
                        The JVM initialisation options.
  -q QUERY, --query QUERY
                        The path to the file storing the query to execute or the query itself.
  -o OUTPUT, --output OUTPUT
                        The path to the output file. [Default: STDOUT]
  -f FORMAT, --format FORMAT
                        Format of the output file. Supported values: JSON, XML, CSV, TEXT, TTL,
                        NT, NQ. [Default:TEXT or TTL]
  -l LOAD, --load LOAD  The path to one RDF file or a folder including a set of files to be
                        loaded. When present, the data is loaded in memory and the query executed
                        against it.
  -v [VALUES ...], --values [VALUES ...]
                        Values passed as input parameter to a query template. When present, the
                        query is pre-processed by substituting variable names with the values
                        provided. The argument can be used in two ways: (1) Providing a single
                        SPARQL ResultSet file. In this case, the query is executed for each set of
                        bindings in the input result set. Only 1 file is allowed. (2) Named
                        variable bindings: the argument value must follow the syntax:
                        var_name=var_value. The argument can be passed multiple times and the
                        query repeated for each set of values.
```

2) To import PySPARQL Anything in one's scripts simply import the library and initialise a ```pysparql_anything.sparql_anything.SparqlAnything``` object
```python
import pysparql_anything as sa
engine = sa.SparqlAnything()
```

Note that in both cases, if the SPARQL Anything jar isn't installed in the API's folder it will be downloaded there automatically the first time the module is imported or the CLI command has been executed.

3) As an example, to execute the following query from the SPARQL Anything MusicXML showcase with PySPARQL Anything,
```
java -jar sparql-anything-0.8.0-SNAPSHOT.jar -q queries/populateOntology.sparql -v filePath="./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml" -v fileName="AltDeu10-017" -f TTL
```

one does
```
$ sparql-anything -q queries/populateOntology.sparql -v filePath=./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml fileName=AltDeu10-017 -f TTL
```

or
```python
import pysparql_anything as sa
engine = sa.SparqlAnything()
engine.run(
    	query="queries/populateOntology.sparql",
    	format="ttl",
    	values={
            "filePath" : "./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml",
            "fileName" : "AltDeu10-017"
    	}
    )
```

### 2.3. Tutorial <a name="tutorial"></a>
A live Google Colab demo demonstrating how to download, install and access the functionalities of PySPARQL Anything through its CLI and 
API can be found at the following link:

https://bit.ly/pysa-demo

## 3. API <a name="api"></a>

All of PySPARQL Anything functionalities can be accessed via the following four methods of the class 
``` pysparql_anything.sparql_anything.SparqlAnything ```.

The constructor for this class is
``` python
pysparql_anything.SparqlAnything(*jvm_options: str) -> pysparql_anything.sparql_anything.SparqlAnything
```
where ```*jvm_options``` are the optional string arguments representing the user's preferred JVM options.

As an example, one may have
```python
engine = sa.SparqlAnything("-Xrs", "-Xmx6g")
```
NOTE: the ```*jvm_options``` are final. Once they are set they cannot be changed without starting a new process.
This limitation is unfortunately due to the nature of the interaction between the JVM and the Python environment.
Please see [#6](https://github.com/SPARQL-Anything/PySPARQL-Anything/issues/6) for more information on this issue.

The keyword arguments to be passed to any of the PySPARQL Anything methods mirror the flags of SPARQL Anything CLI (See [here](https://github.com/SPARQL-Anything/sparql.anything#command-line-interface-cli) for more info).

All of the keyword arguments except for ```values```, requires to be assigned a ```dict```, must be assigned a string literal. 

Currently, the following arguments are supported:

```
 query: str - The path to the file storing the query to execute or the query itself.

 output: str - OPTIONAL - The path to the output file. [Default: STDOUT]

 load: str - OPTIONAL - The path to one RDF file or a folder including a set of
          files to be loaded. When present, the data is loaded in memory and
          the query executed against it.

 format: str - OPTIONAL -  Format of the output file. Supported values: JSON, XML,
          CSV, TEXT, TTL, NT, NQ. [Default:TEXT or TTL]

 values: dict[str, str] - OPTIONAL - Values passed as input parameter to a query template.
                     When present, the query is pre-processed by substituting variable
                     names with the values provided.
                     The argument can be used in two ways:
                     (1) Providing a single SPARQL ResultSet file. In this case,
                     the query is executed for each set of bindings in the input result set.
                     Only 1 file is allowed.
                     (2) Named variable bindings: the argument value must follow the syntax:
                     var_name=var_value. The argument can be passed multiple times and
                     the query repeated for each set of values.
```

### 3.1. Methods <a name="methods"></a>
``` python
SparqlAnything.run(**kwargs) -> None
```

Mirrors the functionalities of the CLI. This can be used to run a query the output of
which is to be printed on the command line or saved to a file. (See example above)

```python
SparqlAnything.ask(**kwargs) -> bool
```

Executes an ASK query and returns a Python boolean True or False.

```python
SparqlAnything.construct(graph_type: type=rdflib.graph.Graph, **kwargs) -> rdflib.graph.Graph | networkx.MultiDiGraph
```

Executes a CONSTRUCT query and returns a Python representation of a graph. 
The ```graph_type``` argument accepts ```rdflib.graph.Graph``` (default) or ```networkx.MultiDiGraph```.

```python
SparqlAnything.select(output_type: type=dict, **kwargs) -> dict | pandas.DataFrame
```

Executes a SELECT query and returns the result as a Python object.
The ```output_type``` argument accepts ```dict``` (default) or ```pandas.DataFrame```.

## 4. Development & Maintenance <a name="dev_guide"></a>

### 4.1. Building PySPARQL Anything <a name="build"></a>

To build the source distribution and binary distribution we proceed as follows. 

First, the tools we require are ```hatch``` as the build frontend (which comes with ```hatchling``` as its backend tool) and ```twine``` to upload the distribution files to PyPI.

All of these can be installed via ```pip install hatch``` or ```pip install twine``` if required.

Once the tools are ready, the build metadata can be configured in the ```pyproject.toml``` file. 

NOTE: it is not needed to amend anything in this file for versioning the software, as this is set dynamically (see below for how to perform this).

After the build metadata has been defined, one can proceed to build the distribution archives.

To do this, open the command prompt on the directory containing the ```pyproject.toml``` file and run
```
hatch build ./dist
```
This command should output some text and once completed should generate a ```dist``` directory containing two files:
```
dist/
├── pysparql_anything-0.8.1.2-py3-none-any.whl
└── pysparql_anything-0.8.1.2.tar.gz
```
for example. Here the ```tar.gz``` file is a source distribution whereas the ```.whl``` file is a binary distribution.

To upload the distributions one does 
```
twine upload dist/*
```
and enter the relevant PyPI credentials for this project. 

NOTE: this process is not exclusive, and other frontend tools like ```build``` together with ```hatchling``` may be similarly used to generate the distributions. The only limit currently is on sticking with ```hatchling``` as the build backend.

### 4.2. SPARQL Anything Updates <a name="sa_updates"></a>

Each version of PySPARQL Anything is tied to a released version of SPARQL Anything. Therefore, when a new version of the latter is released a new release of PySPARQL Anything should follow. 

This process simply involves updating the ```__about__.py``` module of the source code. To do this, set the ```__version__```, ```__SparqlAnything__```  and ```__jarMainPath__``` variables to the new values following the given structure.

As an example, to update from ```0.9.0``` to say ```0.9.1``` of SPARQL Anything, we would have
```python
# PySPARQL ANYTHING METADATA
# PySPARQL version for the build process:
__version__ = "0.9.0.1" # --> "0.9.1.1"

# SPARQL ANYTHING METADATA
# Version of SPARQL Anything to download:
__SparqlAnything__ = "0.9.0"  # --> "0.9.1"
# Path to the SPARQL Anything main class within the executable jar:
__jarMainPath__ = "io.github.sparqlanything.cli.SPARQLAnything"  # Check is this path is still valid for 0.9.1
# SPARQL Anything GitHub URI:
__uri__ = "SPARQL-Anything/sparql.anything"
```
After this build the new distribution files and upload them to PyPI.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pysparql-anything",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "RDF, SPARQL, knowledge graphs, linked data, rdflib, sematic web",
    "author": null,
    "author_email": "Marco Ratta <marco.ratta1@open.ac.uk>, Enrico Daga <enrico.daga@open.ac.uk>",
    "download_url": "https://files.pythonhosted.org/packages/ba/18/e1378fc9f75578b0c8ddfcc543d66278da7a8e65b57e5447f8b5890e1b33/pysparql_anything-0.9.0.3.tar.gz",
    "platform": null,
    "description": "[![How to](https://img.shields.io/badge/How%20to-use-green.svg)](#basic_usage)\n[![How to](https://img.shields.io/badge/How%20to-join-blue.svg)](https://forms.gle/t1paTLz7jVu3RYnu8)\n[![Live demo](https://img.shields.io/badge/Live-demo-yellow.svg)](https://tinyurl.com/ybj4vxzt)\n\n# PySPARQL Anything\n###### The SPARQL Anything Python Library\n\n## Table of Contents\n1. [Introduction](#intro)\n   1. [Fa\u00e7ade-X](#fx)\n   2. [Querying Anything](#query_anything)\n2. [User Guide](#user_guide)\n   1. [Installation](#installation)\n   2. [Basic Usage](#basic_usage)\n   3. [Tutorial](#tutorial)\n3. [API](#api)\n   1. [Methods](#methods)\n4. [Development & Maintanance](#dev_guide)\n   1. [Building PySPARQL Anything](#build)\n   2. [SPARQL Anything Updates](#sa_updates)\n\n## 1. Introduction <a name=\"intro\"></a>\n\nSPARQL Anything is a data integration and Semantic Web re-engineering system that implements the Fa\u00e7ade-X meta-model, resolving the heterogeneity of sources by structurally mapping them onto a set of RDF components, upon\nwhich semantic mappings can be constructed.\n\nPySPARQL Anything is a python wrapper for the SPARQL Anything tool. It purports to offer to Python users dealing with tasks of data integration and RDF data construction and analysis access to the capabilities offered by SPARQL Anything.\nFurthermore, it enables developers to inject RDF graphs into their Python RDFlib, NetworkX  or pandas-powered data science processes, opening new opportunities for developing complex, data- intensive pipelines for generating and manipulating RDF data.\n\n### 1.1. Fa\u00e7ade-X <a name=\"fx\"></a>\nFacade-X is a simplistic meta-model used by SPARQL Anything transformers to generate RDF data from diverse data sources. Intuitively, Facade-X uses a subset of RDF as a general approach to represent the source content as-it-is but in RDF. The model combines two types of elements: containers and literals. Facade-X always has a single root container. Container members are a combination of key-value pairs, where keys are either RDF properties or container membership properties. Instead, values can be either RDF literals or other containers. \n\nThis is a generic example of a Facade-X data object (more examples below):\n```sparql\n@prefix fx: <http://sparql.xyz/facade-x/ns/> .\n@prefix xyz: <http://sparql.xyz/facade-x/data/> .\n@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n[] a fx:root ; rdf:_1 [\n    xyz:someKey \"some value\" ;\n    rdf:_1 \"another value with unspecified key\" ;\n    rdf:_2 [\n        rdf:type xyz:MyType ;\n        rdf:_1 \"another value\"\n    ]\n] .\n```\nMore details on the Facade-X metamodel can be found [here](https://github.com/SPARQL-Anything/sparql.anything/blob/v1.0-DEV/Facade-X.md).\n\n### 1.2. Querying anything <a name=\"query_anything\"></a>\nSPARQL Anything extends the Apache Jena ARQ processors by overloading the SERVICE operator, as in the following example:\n\nSuppose having this JSON file as input (also available at https://sparql-anything.cc/example1.json)\n```json\n[\n  {\n    \"name\": \"Friends\",\n    \"genres\": [\n      \"Comedy\",\n      \"Romance\"\n    ],\n    \"language\": \"English\",\n    \"status\": \"Ended\",\n    \"premiered\": \"1994-09-22\",\n    \"summary\": \"Follows the personal and professional lives of six twenty to thirty-something-year-old friends living in Manhattan.\",\n    \"stars\": [\n      \"Jennifer Aniston\",\n      \"Courteney Cox\",\n      \"Lisa Kudrow\",\n      \"Matt LeBlanc\",\n      \"Matthew Perry\",\n      \"David Schwimmer\"\n    ]\n  },\n  {\n    \"name\": \"Cougar Town\",\n    \"genres\": [\n      \"Comedy\",\n      \"Romance\"\n    ],\n    \"language\": \"English\",\n    \"status\": \"Ended\",\n    \"premiered\": \"2009-09-23\",\n    \"summary\": \"Jules is a recently divorced mother who has to face the unkind realities of dating in a world obsessed with beauty and youth. As she becomes older, she starts discovering herself.\",\n    \"stars\": [\n      \"Courteney Cox\",\n      \"David Arquette\",\n      \"Bill Lawrence\",\n      \"Linda Videtti Figueiredo\",\n      \"Blake McCormick\"\n    ]\n  }\n]\n```\nWith SPARQL Anything you can select the TV series starring \"Courteney Cox\" with the SPARQL query\n```sparql\nPREFIX xyz: <http://sparql.xyz/facade-x/data/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\nPREFIX fx: <http://sparql.xyz/facade-x/ns/>\n\nSELECT ?seriesName\nWHERE {\n\n    SERVICE <x-sparql-anything:https://sparql-anything.cc/example1.json> {\n        ?tvSeries xyz:name ?seriesName .\n        ?tvSeries xyz:stars ?star .\n        ?star fx:anySlot \"Courteney Cox\" .\n    }\n\n}\n```\nand get this result without caring of transforming JSON to RDF.\n```powershell\nseriesName\n\"Cougar Town\"\n\"Friends\"\n```\n      \n## 2. User Guide <a name=\"user_guide\"></a>\n\n### 2.1. Installation <a name=\"installation\"></a>\n\nPySPARQL Anything is released on PyPI. To install it on your machine type the following in your command prompt:\n```\n$ pip install pysparql-anything \n```\n\nTo remove PySPARQL Anything from your machine, do the following.\n\nIn your command prompt execute\n```python\n$ python\n>>> import pysparql_anything as sa\n>>> sa.utilities.remove_sparql_anything()\n>>> exit()\n$ pip uninstall pysparql-anything\n```\n\n### 2.2. Basic Usage <a name=\"basic_usage\"></a>\n\nPySPARQL Anything comes equipped with a CLI tool. Its functionalities can therefore either be accessed through the\ncommand prompt or by importing the library into your scripts. Choosing the latter method will also enable the user\nto return the results of their SPARQL queries as specific Python objects.\n\nBelow we show a few basic steps to illustrate usage.\n\n1) To use the CLI tool, pen the command prompt with the current working directory set to the main folder of a SPARQL Anything project.\nThe CLI tool is accessed with the ```sparql-anything``` command. Executing\n```\n$ sparql-anything -h\n```\nwill pull up the instructions on how to use the CLI:\n```\nWelcome to the PySPARQL Anything CLI. For the optional flags see below.\n\noptions:\n  -h, --help            show this help message and exit\n  -j [JAVA ...], --java [JAVA ...]\n                        The JVM initialisation options.\n  -q QUERY, --query QUERY\n                        The path to the file storing the query to execute or the query itself.\n  -o OUTPUT, --output OUTPUT\n                        The path to the output file. [Default: STDOUT]\n  -f FORMAT, --format FORMAT\n                        Format of the output file. Supported values: JSON, XML, CSV, TEXT, TTL,\n                        NT, NQ. [Default:TEXT or TTL]\n  -l LOAD, --load LOAD  The path to one RDF file or a folder including a set of files to be\n                        loaded. When present, the data is loaded in memory and the query executed\n                        against it.\n  -v [VALUES ...], --values [VALUES ...]\n                        Values passed as input parameter to a query template. When present, the\n                        query is pre-processed by substituting variable names with the values\n                        provided. The argument can be used in two ways: (1) Providing a single\n                        SPARQL ResultSet file. In this case, the query is executed for each set of\n                        bindings in the input result set. Only 1 file is allowed. (2) Named\n                        variable bindings: the argument value must follow the syntax:\n                        var_name=var_value. The argument can be passed multiple times and the\n                        query repeated for each set of values.\n```\n\n2) To import PySPARQL Anything in one's scripts simply import the library and initialise a ```pysparql_anything.sparql_anything.SparqlAnything``` object\n```python\nimport pysparql_anything as sa\nengine = sa.SparqlAnything()\n```\n\nNote that in both cases, if the SPARQL Anything jar isn't installed in the API's folder it will be downloaded there automatically the first time the module is imported or the CLI command has been executed.\n\n3) As an example, to execute the following query from the SPARQL Anything MusicXML showcase with PySPARQL Anything,\n```\njava -jar sparql-anything-0.8.0-SNAPSHOT.jar -q queries/populateOntology.sparql -v filePath=\"./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml\" -v fileName=\"AltDeu10-017\" -f TTL\n```\n\none does\n```\n$ sparql-anything -q queries/populateOntology.sparql -v filePath=./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml fileName=AltDeu10-017 -f TTL\n```\n\nor\n```python\nimport pysparql_anything as sa\nengine = sa.SparqlAnything()\nengine.run(\n    \tquery=\"queries/populateOntology.sparql\",\n    \tformat=\"ttl\",\n    \tvalues={\n            \"filePath\" : \"./musicXMLFiles/AltDeu10/AltDeu10-017.musicxml\",\n            \"fileName\" : \"AltDeu10-017\"\n    \t}\n    )\n```\n\n### 2.3. Tutorial <a name=\"tutorial\"></a>\nA live Google Colab demo demonstrating how to download, install and access the functionalities of PySPARQL Anything through its CLI and \nAPI can be found at the following link:\n\nhttps://bit.ly/pysa-demo\n\n## 3. API <a name=\"api\"></a>\n\nAll of PySPARQL Anything functionalities can be accessed via the following four methods of the class \n``` pysparql_anything.sparql_anything.SparqlAnything ```.\n\nThe constructor for this class is\n``` python\npysparql_anything.SparqlAnything(*jvm_options: str) -> pysparql_anything.sparql_anything.SparqlAnything\n```\nwhere ```*jvm_options``` are the optional string arguments representing the user's preferred JVM options.\n\nAs an example, one may have\n```python\nengine = sa.SparqlAnything(\"-Xrs\", \"-Xmx6g\")\n```\nNOTE: the ```*jvm_options``` are final. Once they are set they cannot be changed without starting a new process.\nThis limitation is unfortunately due to the nature of the interaction between the JVM and the Python environment.\nPlease see [#6](https://github.com/SPARQL-Anything/PySPARQL-Anything/issues/6) for more information on this issue.\n\nThe keyword arguments to be passed to any of the PySPARQL Anything methods mirror the flags of SPARQL Anything CLI (See [here](https://github.com/SPARQL-Anything/sparql.anything#command-line-interface-cli) for more info).\n\nAll of the keyword arguments except for ```values```, requires to be assigned a ```dict```, must be assigned a string literal. \n\nCurrently, the following arguments are supported:\n\n```\n query: str - The path to the file storing the query to execute or the query itself.\n\n output: str - OPTIONAL - The path to the output file. [Default: STDOUT]\n\n load: str - OPTIONAL - The path to one RDF file or a folder including a set of\n          files to be loaded. When present, the data is loaded in memory and\n          the query executed against it.\n\n format: str - OPTIONAL -  Format of the output file. Supported values: JSON, XML,\n          CSV, TEXT, TTL, NT, NQ. [Default:TEXT or TTL]\n\n values: dict[str, str] - OPTIONAL - Values passed as input parameter to a query template.\n                     When present, the query is pre-processed by substituting variable\n                     names with the values provided.\n                     The argument can be used in two ways:\n                     (1) Providing a single SPARQL ResultSet file. In this case,\n                     the query is executed for each set of bindings in the input result set.\n                     Only 1 file is allowed.\n                     (2) Named variable bindings: the argument value must follow the syntax:\n                     var_name=var_value. The argument can be passed multiple times and\n                     the query repeated for each set of values.\n```\n\n### 3.1. Methods <a name=\"methods\"></a>\n``` python\nSparqlAnything.run(**kwargs) -> None\n```\n\nMirrors the functionalities of the CLI. This can be used to run a query the output of\nwhich is to be printed on the command line or saved to a file. (See example above)\n\n```python\nSparqlAnything.ask(**kwargs) -> bool\n```\n\nExecutes an ASK query and returns a Python boolean True or False.\n\n```python\nSparqlAnything.construct(graph_type: type=rdflib.graph.Graph, **kwargs) -> rdflib.graph.Graph | networkx.MultiDiGraph\n```\n\nExecutes a CONSTRUCT query and returns a Python representation of a graph. \nThe ```graph_type``` argument accepts ```rdflib.graph.Graph``` (default) or ```networkx.MultiDiGraph```.\n\n```python\nSparqlAnything.select(output_type: type=dict, **kwargs) -> dict | pandas.DataFrame\n```\n\nExecutes a SELECT query and returns the result as a Python object.\nThe ```output_type``` argument accepts ```dict``` (default) or ```pandas.DataFrame```.\n\n## 4. Development & Maintenance <a name=\"dev_guide\"></a>\n\n### 4.1. Building PySPARQL Anything <a name=\"build\"></a>\n\nTo build the source distribution and binary distribution we proceed as follows. \n\nFirst, the tools we require are ```hatch``` as the build frontend (which comes with ```hatchling``` as its backend tool) and ```twine``` to upload the distribution files to PyPI.\n\nAll of these can be installed via ```pip install hatch``` or ```pip install twine``` if required.\n\nOnce the tools are ready, the build metadata can be configured in the ```pyproject.toml``` file. \n\nNOTE: it is not needed to amend anything in this file for versioning the software, as this is set dynamically (see below for how to perform this).\n\nAfter the build metadata has been defined, one can proceed to build the distribution archives.\n\nTo do this, open the command prompt on the directory containing the ```pyproject.toml``` file and run\n```\nhatch build ./dist\n```\nThis command should output some text and once completed should generate a ```dist``` directory containing two files:\n```\ndist/\n\u251c\u2500\u2500 pysparql_anything-0.8.1.2-py3-none-any.whl\n\u2514\u2500\u2500 pysparql_anything-0.8.1.2.tar.gz\n```\nfor example. Here the ```tar.gz``` file is a source distribution whereas the ```.whl``` file is a binary distribution.\n\nTo upload the distributions one does \n```\ntwine upload dist/*\n```\nand enter the relevant PyPI credentials for this project. \n\nNOTE: this process is not exclusive, and other frontend tools like ```build``` together with ```hatchling``` may be similarly used to generate the distributions. The only limit currently is on sticking with ```hatchling``` as the build backend.\n\n### 4.2. SPARQL Anything Updates <a name=\"sa_updates\"></a>\n\nEach version of PySPARQL Anything is tied to a released version of SPARQL Anything. Therefore, when a new version of the latter is released a new release of PySPARQL Anything should follow. \n\nThis process simply involves updating the ```__about__.py``` module of the source code. To do this, set the ```__version__```, ```__SparqlAnything__```  and ```__jarMainPath__``` variables to the new values following the given structure.\n\nAs an example, to update from ```0.9.0``` to say ```0.9.1``` of SPARQL Anything, we would have\n```python\n# PySPARQL ANYTHING METADATA\n# PySPARQL version for the build process:\n__version__ = \"0.9.0.1\" # --> \"0.9.1.1\"\n\n# SPARQL ANYTHING METADATA\n# Version of SPARQL Anything to download:\n__SparqlAnything__ = \"0.9.0\"  # --> \"0.9.1\"\n# Path to the SPARQL Anything main class within the executable jar:\n__jarMainPath__ = \"io.github.sparqlanything.cli.SPARQLAnything\"  # Check is this path is still valid for 0.9.1\n# SPARQL Anything GitHub URI:\n__uri__ = \"SPARQL-Anything/sparql.anything\"\n```\nAfter this build the new distribution files and upload them to PyPI.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "The SPARQL Anything Python library.",
    "version": "0.9.0.3",
    "project_urls": {
        "Documentation": "https://github.com/SPARQL-Anything/PySPARQL-Anything/blob/main/README.md",
        "Issues": "https://github.com/SPARQL-Anything/PySPARQL-Anything/issues",
        "Source": "https://github.com/SPARQL-Anything/PySPARQL-Anything"
    },
    "split_keywords": [
        "rdf",
        " sparql",
        " knowledge graphs",
        " linked data",
        " rdflib",
        " sematic web"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79fbd4db6fb4af8c22dcb0db532c5cdcf1874b90239987cd994b830116b50f2e",
                "md5": "884bd664076f1aaf119ee0dfcb8c4b1a",
                "sha256": "de6dafe2dab2f28bbd82c88f8175bee935281755fe22086a92be51cc6511211d"
            },
            "downloads": -1,
            "filename": "pysparql_anything-0.9.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "884bd664076f1aaf119ee0dfcb8c4b1a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 20975,
            "upload_time": "2024-09-11T12:18:11",
            "upload_time_iso_8601": "2024-09-11T12:18:11.498397Z",
            "url": "https://files.pythonhosted.org/packages/79/fb/d4db6fb4af8c22dcb0db532c5cdcf1874b90239987cd994b830116b50f2e/pysparql_anything-0.9.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba18e1378fc9f75578b0c8ddfcc543d66278da7a8e65b57e5447f8b5890e1b33",
                "md5": "cc228419127d5512f4046242da06c24e",
                "sha256": "a67a6077fb6a888d0c558f11c04ead3b804a9b9e42458eae3cb2de7389f0ec1b"
            },
            "downloads": -1,
            "filename": "pysparql_anything-0.9.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "cc228419127d5512f4046242da06c24e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 31653,
            "upload_time": "2024-09-11T12:18:13",
            "upload_time_iso_8601": "2024-09-11T12:18:13.290155Z",
            "url": "https://files.pythonhosted.org/packages/ba/18/e1378fc9f75578b0c8ddfcc543d66278da7a8e65b57e5447f8b5890e1b33/pysparql_anything-0.9.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-11 12:18:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SPARQL-Anything",
    "github_project": "PySPARQL-Anything",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pysparql-anything"
}
        
Elapsed time: 4.76792s