Skip to main content

A lightweight RDF toolkit for Python

Project description

pocket-rdf

CI PyPI 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 PyPI

pip install pocket-rdf

Install from Source

git clone https://github.com/EHegyi-Sphericity/pocket-rdf.git
cd pocket-rdf
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.2.0.tar.gz (21.2 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.2.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file pocket_rdf-0.2.0.tar.gz.

File metadata

  • Download URL: pocket_rdf-0.2.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pocket_rdf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3665adccb87064749c5ff2b311158499dbb5a9806b2766994f49ae27c8db664a
MD5 a91ff237d2eac19eaff8430dba356d8d
BLAKE2b-256 033c0455444951b493f1ac527ebbead6029c21b2ad7a178bc994464d11e753c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocket_rdf-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: pocket_rdf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pocket_rdf-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd9bc695dcfd95d672fe2ae370807e6c496f9d13cea8466b9aa1129f8fae931c
MD5 c590e4aec6a5d0b2e17fc8c80b2e64b3
BLAKE2b-256 28261000c12fd9a71e2b7a59de92794a79a87bb4409b9902c33d7d57fce8ee20

See more details on using hashes here.

Provenance

The following attestation bundles were made for pocket_rdf-0.2.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