Skip to main content

A lightweight RDF toolkit for Python

Project description

pocket-rdf

CI Python 3.10+ License: MIT

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 and GRAPH-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pocket_rdf-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pocket_rdf-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

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

Hashes for pocket_rdf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b753125eb0bf9ef3a6007e28f82d64ff68a85e64a870db2d111638b9e00e42e0
MD5 eb8506523ce0777c85e8540c7a11cae0
BLAKE2b-256 38144bbc3b69e031053a86d2a25421bdff459fdb4e10e606dc6b384cfd298b58

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocket_rdf-0.1.0.tar.gz:

Publisher: publish.yml on EHegyi-Sphericity/pocket-rdf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pocket_rdf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bddb1ac8e150338e165bdec0e319423db040397409e32e6ee9d3c3607787d22a
MD5 5cad2eb63a38ad02474d8cc3579180e8
BLAKE2b-256 1f93781ec983c989e5207fa2496ab9e97827cf38c1733adcf409951a721ac09b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page