Metadata-Version: 2.4
Name: pocket-rdf
Version: 0.2.0
Summary: A lightweight RDF toolkit for Python
Author-email: Emil Hegyi <EHegyi@sphericity.eu>
License: The MIT License (MIT)
        
        Copyright (c) 2026 Emil Hegyi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the “Software”), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        
Project-URL: Repository, https://github.com/EHegyi-Sphericity/pocket-rdf
Keywords: rdf,sparql,shacl,semantic-web,linked-data,python,cim,cgmes,power-system-modeling,serialization,querying,validation
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rdflib>=7.6.0
Requires-Dist: pyshacl>=0.31.0
Requires-Dist: typer>=0.24.1
Provides-Extra: dev
Requires-Dist: pytest==8.1.1; extra == "dev"
Requires-Dist: pytest-cov==4.1.0; extra == "dev"
Requires-Dist: pre-commit==3.7.0; extra == "dev"
Requires-Dist: pre-commit-hooks==4.0.1; extra == "dev"
Requires-Dist: black==26.3.1; extra == "dev"
Requires-Dist: isort==8.0.1; extra == "dev"
Requires-Dist: flake8==7.3.0; extra == "dev"
Requires-Dist: flake8-pyproject==1.2.4; extra == "dev"
Requires-Dist: pyright==1.1.408; extra == "dev"
Dynamic: license-file

# pocket-rdf

[![CI](https://github.com/EHegyi-Sphericity/pocket-rdf/actions/workflows/tests.yml/badge.svg)](https://github.com/EHegyi-Sphericity/pocket-rdf/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/pocket-rdf)](https://pypi.org/project/pocket-rdf/)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

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

```bash
pip install pocket-rdf
```

### Install from Source

```bash
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.

```bash
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.

```bash
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.

```bash
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/`](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/`](examples/simple/) | Single graph | Load, serialize, query, and validate a small library dataset |
| [`examples/advanced/`](examples/advanced/) | Named graphs (`--dataset`) | Multiple catalogs, `GRAPH` queries, TriG/N-Quads, SPARQL-based SHACL |
| [`examples/cgmes/`](examples/cgmes/) | CGMES power system data | Multi-profile datasets, ENTSO-E SHACL shapes, RDFS-enhanced querying |

## Development

### Running Tests

```bash
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
