A lightweight RDF toolkit for Python
Project description
pocket-rdf
A lightweight RDF toolkit for Python, providing command-line utilities for loading, serializing, querying, and validating RDF data.
Features
- Load RDF Data: Support for Turtle (
.ttl), RDF/XML (.xml,.rdf), JSON-LD (.json,.jsonld), N-Triples (.nt), TriG (.trig), and N-Quads (.nq) - Named Graph Support: Load each file into its own named graph with
--dataset, enabling provenance tracking andGRAPH-aware SPARQL queries - Serialization: Convert between any supported format; use TriG or N-Quads to preserve named graphs
- SPARQL Querying: Execute SPARQL queries on single graphs or datasets
- SHACL Validation: Validate RDF data against SHACL shapes (including SPARQL-based constraints)
- CLI Interface: Easy-to-use command-line tools built with Typer
Installation
Prerequisites
- Python 3.10 or higher
Install from Source
Clone the repository and install:
git clone https://github.com/EHegyi-Sphericity/pocket-rdf.git
cd pocket-rdf
pip install .
Or install directly from the directory:
pip install .
Usage
pocket-rdf provides three main commands: serialize, query, and validate.
Serialize RDF Data
Load and serialize RDF data to different formats.
pocket-rdf serialize data.ttl --out output.xml
Arguments:
- Input RDF files (supports patterns like
*.xml)
Options:
--out,-o: Output file (format inferred from extension)--dataset,-d: Load each input file into its own named graph (enables TriG/N-Quads output)
Query RDF Data
Execute SPARQL queries on RDF files.
pocket-rdf query data.ttl --query query.sparql --out results.json
Arguments:
- Input RDF files (supports patterns like
*.xml)
Options:
--query,-q: SPARQL query file--out,-o: Output file for results--dataset,-d: Load each input file into its own named graph
Validate RDF Data
Validate RDF files against SHACL shapes.
pocket-rdf validate file1.ttl file2.xml --shapes shapes.ttl --out report.ttl
Arguments:
- Input RDF files (supports patterns like
*.xml)
Options:
--shapes,-s: SHACL shapes file--out,-o: Output file for validation report--dataset,-d: Load each input file into its own named graph
Examples
The examples/ directory contains three progressive sets of
working examples, each with its own README, sample data, SPARQL queries, and
SHACL shapes:
| Directory | Scope | Key concepts |
|---|---|---|
examples/simple/ |
Single graph | Load, serialize, query, and validate a small library dataset |
examples/advanced/ |
Named graphs (--dataset) |
Multiple catalogs, GRAPH queries, TriG/N-Quads, SPARQL-based SHACL |
examples/cgmes/ |
CGMES power system data | Multi-profile datasets, ENTSO-E SHACL shapes, RDFS-enhanced querying |
Development
Running Tests
python -m pytest tests/
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contact
Emil Hegyi - EHegyi@sphericity.eu
Project Link: https://github.com/EHegyi-Sphericity/pocket-rdf
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 pocket_rdf-0.1.0.tar.gz.
File metadata
- Download URL: pocket_rdf-0.1.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b753125eb0bf9ef3a6007e28f82d64ff68a85e64a870db2d111638b9e00e42e0
|
|
| MD5 |
eb8506523ce0777c85e8540c7a11cae0
|
|
| BLAKE2b-256 |
38144bbc3b69e031053a86d2a25421bdff459fdb4e10e606dc6b384cfd298b58
|
Provenance
The following attestation bundles were made for pocket_rdf-0.1.0.tar.gz:
Publisher:
publish.yml on EHegyi-Sphericity/pocket-rdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pocket_rdf-0.1.0.tar.gz -
Subject digest:
b753125eb0bf9ef3a6007e28f82d64ff68a85e64a870db2d111638b9e00e42e0 - Sigstore transparency entry: 1243514443
- Sigstore integration time:
-
Permalink:
EHegyi-Sphericity/pocket-rdf@78f0bbbd4e94019c2cae60eab5540b4cc927b5f9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/EHegyi-Sphericity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78f0bbbd4e94019c2cae60eab5540b4cc927b5f9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pocket_rdf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pocket_rdf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bddb1ac8e150338e165bdec0e319423db040397409e32e6ee9d3c3607787d22a
|
|
| MD5 |
5cad2eb63a38ad02474d8cc3579180e8
|
|
| BLAKE2b-256 |
1f93781ec983c989e5207fa2496ab9e97827cf38c1733adcf409951a721ac09b
|
Provenance
The following attestation bundles were made for pocket_rdf-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on EHegyi-Sphericity/pocket-rdf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pocket_rdf-0.1.0-py3-none-any.whl -
Subject digest:
bddb1ac8e150338e165bdec0e319423db040397409e32e6ee9d3c3607787d22a - Sigstore transparency entry: 1243514444
- Sigstore integration time:
-
Permalink:
EHegyi-Sphericity/pocket-rdf@78f0bbbd4e94019c2cae60eab5540b4cc927b5f9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/EHegyi-Sphericity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78f0bbbd4e94019c2cae60eab5540b4cc927b5f9 -
Trigger Event:
release
-
Statement type: