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
  • --context, -c: Additional RDF files loaded for reference resolution only (not validated)
  • --allow-infos: Treat sh:Info severity results as non-failing
  • --allow-warnings: Treat sh:Warning and sh:Info severity results as non-failing

When a file references entities defined in another file, use --context to load the referenced file for reference resolution without validating it:

pocket-rdf validate EQ.xml --shapes shapes.ttl --out report.ttl --context EQBD.xml

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.3.0.tar.gz (24.6 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.3.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pocket_rdf-0.3.0.tar.gz
  • Upload date:
  • Size: 24.6 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.3.0.tar.gz
Algorithm Hash digest
SHA256 4b3a317172ba810426732458ecc1a0e7495c24a2dab5b5c794723b7e16b4c4c4
MD5 4bd5a3d16280be47375033c835f88260
BLAKE2b-256 77349de56395bf13f1483775589fc98373bb8c4926e6ef138ca8c4835c7a70a2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pocket_rdf-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ab265f68006b85ceaf8d096743ede7bd0d36daa34eabc01733bf824c9c0d9de
MD5 c419da062d93163b5da2a915b1583fc4
BLAKE2b-256 8beffb1454c9ff4ef8f6f300704c009fc554b5177913a2135f8edfa19c6cec6b

See more details on using hashes here.

Provenance

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