This package consists of a set of command-line tools that do interesting things with RDF and SPARQL.
The functionality is provided by RDFLib, and while that provides a set of commands those provided here are somewhat more extensive and also based upon a common command framework that can be extended easily for more cases.
[](https://travis-ci.org/johnstonskj/rdftools)
[](https://coveralls.io/github/johnstonskj/rdftools?branch=master)
[](https://codeclimate.com/github/johnstonskj/rdftools/maintainability)
[](https://requires.io/github/johnstonskj/rdftools/requirements/?branch=master)
<!--
[](https://readthedocs.org/projects/rdftools)
-->
[](https://github.com/johnstonskj/rdftools/stargazers)
[](https://pypi.python.org/pypi/rdftools)
[](https://pypi.python.org/pypi/rdftools)
[](https://pypi.python.org/pypi/tdftools)
## Usage
The tooling uses a common starting command, `rdf`, that then executes sub-commands. As expected, the command has a help function and lists the supported sub-commands as _positional arguments_. These sub-commands also have their own help.
```
$ rdf -h
usage: rdf [-h] [-v] {validate,convert,select,query} ...
RDF tool
positional arguments:
{validate,convert,select,shell,query}
subargs
optional arguments:
-h, --help show this help message and exit
-v, --verbose
```
The currently supported sub-commands are as follows.
* `convert` - convert files between different RDF representations (NTriples, Notation3, XML, ...).
* `query` - execute SPARQL queries over RDF files.
* `select` - simple projections from RDF files.
* `shell` - run an interactive shell session.
* `validate` - validate an RDF file.
An example, running a SPARQL query over a downloaded file is shown below.
```
$ rdf query -i ~/social.n3 -r n3 -q "SELECT DISTINCT ?person ?topic WHERE { ?person <http://example.org/social/relationship/1.0/likes> ?topic. }"
person topic
============================================== =============================================
http://amazon.com/cprm/customers/1.0/Alice http://amazon.com/cprm/entities/1.0/Diving
http://amazon.com/cprm/customers/1.0/Bob http://amazon.com/cprm/entities/1.0/Diving
http://amazon.com/cprm/customers/1.0/Alice http://amazon.com/cprm/entities/1.0/Shoes
3 rows returned in 1.629622 seconds.
```
## Debugging
The `-v` parameter to either `rdf` or one of the sub-commands controls the standard Python logging level. It can be stated multiple times to increase the logging; `-v` for warnings, `-vv` for informational, `-vvv` for debug.
## Interactive Shell
For a more interactive exploration of RDF data you can run `rdf shell` which gives you access to a lot of the same functions in the separate tools. The shell has a single common graph into which you can load data from external files (and stores in the future), and run SPARQL queries. The shell also has a default initialization file, so commonly used prefixes, common data, etc. can be loaded before you start your session.
```
$ rdf shell
RDF Shell, v0.1.0.
reading commands from file /Users/simonjo/.rdfshrc
Graph updated with 40 statements.
>
```
As you might expect, the shell supports a `help` function and command completion as well as a persistent history.
### Initialization File
The default location for this is `~/.rdfshrc`, all commands are read as if you typed them into the shell.
### History File
The default location for this is `~/.rdfsh_hist`, it will be read at startup and updated on closing the shell.
## Extending
New commands are added as modules in the `rdftools/scripts` folder and have the following structure.
```python
import rdftools
def main():
(LOG, cmd) = rdftools.startup('Tool description.', add_args=None)
...
```
The `add_args` parameter is used to add additional command-line arguments to the common `argparse` structure. The function, if required, takes in a parser object and returns it. The common command line arguments include verbosity, help, and reading files.
```python
def add_args(parser):
return parser
```
The results from `startup` are a standard logger and an (`ArgumentParser`) `Namespace` object. The tool can then use the functions `read`, `read_into`, `read_all`, `write`, and `query` to perform common operations on RDF files.
Extending the shell is also pretty simple, you add a function of the following form, it always takes a context object first, and the doc string will be used by default as the displayed help for your command. Arguments may be parsed for more structure, and `print()` is used extensively for user feedback. Note that you must always return the context, whether you updated it or not. The `add_command` function will install it into the shell, enabling help and command completion.
```python
def echo(context, args):
""" echo text
Echo back the following text."""
print(args)
return context
add_command(echo)
```
## References
* [RDF Working Group](https://www.w3.org/2011/rdf-wg/wiki/Main_Page)
* [SPARQL Overview](https://www.w3.org/TR/sparql11-overview/)
* [RDFLib](https://github.com/RDFLib/rdflib)
* [Travis Project](https://travis-ci.org/johnstonskj/rdftools)
* [Coveralls Project](https://coveralls.io/github/johnstonskj/rdftools)
Metadata
Release files for rdftools 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rdftools-0.2.0a.tar.gz | 13.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rdftools-0.2.0a-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.5 kB
Release files / rdftools-0.2.0a.tar.gz
| Download URL | rdftools-0.2.0a.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c398154c86de1e29fe3916dd26397ebbd7101c05672459b13124e6bc4e674b1
|
|
BLAKE2b-256 checksum How to use checksums |
496e61bc38e3016108628895b7eaaab2f6690b8bf97d8e6a9b5af9d3117e4cc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / rdftools-0.2.0a-py3-none-any.whl
| Download URL | rdftools-0.2.0a-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2439008929ee3acb5c7bb8eecfd5b9eb96173887695592168be33ef7b235898
|
|
BLAKE2b-256 checksum How to use checksums |
e4649c721450cfca13795d8412595cd37cae0cd8b55a667bbcaa89b596e2e9bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for rdftools 0.2.0
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.