Metadata-Version: 2.4
Name: rdfcanon
Version: 1.0.0
Home-page: https://github.com/YoucTagh/rdf-canon/
Download-URL: https://pypi.org/project/rdfcanon/
Author: Yousouf Taghzouti
Author-email: yousouf.taghzouti@gmail.com
License: MIT
Keywords: semantics,canonicalisation,RDF
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rdflib==7.5.0
Requires-Dist: sortedcontainers==2.4.0
Dynamic: author
Dynamic: author-email
Dynamic: description
Dynamic: description-content-type
Dynamic: download-url
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python

# RDF Canonicalisation

[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![PyPI](https://img.shields.io/pypi/v/rdfcanon)](https://pypi.org/project/rdfcanon/)
[![Downloads](https://img.shields.io/pypi/dm/rdfcanon)](https://pypi.org/project/rdfcanon/)

A Python library for **RDF canonicalisation** based on the [W3C RDF Canonicalisation specification](https://www.w3.org/TR/rdf-canon/).
This library allows you to deterministically canonicalise RDF datasets, making it easier to compare, sign, or hash RDF graphs.

## Features

* Deterministic RDF blank node canonicalisation
* Support for multiple hash algorithms (e.g., `sha256`)
* Integration with `rdflib` `Dataset` objects
* Time-based ticker for controlling the maximum duration of the canonicalisation task.

## Installation

```bash
pip install rdfcanon
```

## Usage

```python
from rdfcanon import RDFCanon, RDFCanonTimeTicker
from rdflib import BNode, Dataset, URIRef

# Create a sample RDF dataset
dataset = Dataset()
dataset.add(
    (
        BNode("e0"),
        URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),
        URIRef("http://example.org/vocab#Foo"),
        BNode("g0")
    )
)

# Initialise RDF canonicalisation
rdf_canon = RDFCanon(
    hash_algorithm="sha256",
    dataset=dataset,
    ticker=RDFCanonTimeTicker(3000)  # Optional time ticker
)

# Canonicalise the RDF dataset
print(rdf_canon.canonize())
```

This will output:

```
_:c14n1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/vocab#Foo> _:c14n0 .
```

## Development

### Build the library

```bash
python setup.py sdist bdist_wheel
```

### Run tests

```bash
pytest
```

## Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub.

## License

MIT License © 2025 YoucTagh
