Skip to main content

Python bindings for Rudof

Project description

pyrudof — Python bindings for Rudof

PyPI Docs

pyrudof provides Python bindings for rudof, a Rust library for working with RDF data validation and related Semantic Web technologies.

Key features:

  • ShEx & SHACL validation — validate RDF graphs against Shape Expressions and SHACL shapes.
  • DCTAP conversion — read Dublin Core Tabular Application Profiles and convert them to ShEx.
  • SPARQL queries — run SELECT / CONSTRUCT queries against local data or remote endpoints.
  • Schema comparison — compare two schemas for structural equivalence.
  • UML visualization — generate PlantUML diagrams from schemas and data.
  • Synthetic data generation — create RDF data from ShEx or SHACL schemas via rudof_generate.

Links: PyPI · Documentation · Tutorials (Jupyter)

Building from source

pyrudof is built with PyO3 and maturin.

# Clone the repository
git clone https://github.com/rudof-project/rudof.git
cd rudof/python

# (Optional) create a virtual environment
python3 -m venv .venv
source .venv/bin/activate   # Linux/macOS
# .venv\Scripts\Activate.ps1  # Windows PowerShell

# Install maturin and build
pip install maturin
pip install -e .

For a release-optimised wheel:

maturin build --release
pip install --force-reinstall target/wheels/pyrudof-*.whl

Testing

Run the full test suite

cd python/tests
python -m unittest discover -vvv

Run only the example tests

python -m unittest test_examples -v

Run a specific category or test

# All ShEx examples
python -m unittest test_examples.TestShexExamples -v

# A single example
python -m unittest test_examples.TestShexExamples.test_shex_validate -v

# SHACL API tests
python -m unittest test_shacl -v

# Data generation tests
python -m unittest test_generate -v

Test architecture

Tests are auto-generated from examples/examples.toml. When test_examples.py is loaded, it reads the manifest and dynamically creates one unittest.TestCase class per category, with one test method per example. Each test:

  1. Launches the .py file as a subprocess (exactly as a user would run it).
  2. Asserts a zero exit code and non-empty stdout.
  3. Checks any expected_output substrings declared in the manifest.

Examples that require network access, a PlantUML JAR, or special runtimes are marked with skip_test = true in the TOML and are automatically skipped.

Test file What it covers
test_examples.py All examples from the manifest
test_shacl.py SHACL validation API
test_generate.py GeneratorConfig / DataGenerator API

Examples and documentation

Single source of truth

The example system is designed to eliminate duplication. Code lives in one place only:

  • examples/*.py: the executable code (authoritative)
  • examples/examples.toml: metadata: title, description, category, files, expected_output, skip_test

Both the test suite and the documentation generator read from these two sources. There is no inline code in the registry or in the RST file.

Adding a new example

  1. Create a .py file in python/examples/ (it must be a runnable script that prints output).

  2. Register it in examples/examples.toml:

    [[example]]
    key = "my_example"
    source_file = "my_example.py"
    title = "My Example"
    description = "What this example demonstrates"
    category = "shex"          # shex | shacl | rdf | dctap | sparql | endpoint | generate | uml | utility
    files = {data = "my_data.ttl"}   # optional: referenced files
    expected_output = ["some expected string"]  # optional: substrings to check
    # skip_test = true         # uncomment if it needs network, PlantUML, etc.
    
  3. Run tests to verify:

    cd python/tests
    python -m unittest test_examples -v
    
  4. Regenerate the documentation:

    python python/docs/generate_examples_doc.py --update
    
  5. Verify the docs are in sync:

    python python/docs/generate_examples_doc.py --check
    

Available categories

Category Description
shex ShEx validation
shacl SHACL validation
rdf RDF parsing and serialization
dctap DCTAP profiles and conversion
sparql SPARQL queries (local data)
endpoint Remote endpoints (skipped in CI)
generate Synthetic data generation
uml PlantUML visualization (skipped in CI)
utility Module introspection and testing

Building the documentation locally

cd python/docs
python -m sphinx -b html . _build/html

Then open _build/html/index.html in a browser.

Using rudof_generate

pyrudof includes bindings for synthetic RDF data generation.

Basic usage

import pyrudof

config = pyrudof.GeneratorConfig()
config.set_entity_count(100)
config.set_seed(42)
config.set_output_path("output.ttl")
config.set_output_format(pyrudof.OutputFormat.Turtle)

generator = pyrudof.DataGenerator(config)
generator.run("schema.shex")

Configuration options

config = pyrudof.GeneratorConfig()

# Generation
config.set_entity_count(1000)
config.set_seed(42)
config.set_schema_format(pyrudof.SchemaFormat.ShEx)   # or .Shacl
config.set_cardinality_strategy(pyrudof.CardinalityStrategy.Balanced)
# Strategies: Minimum, Maximum, Random, Balanced

# Output
config.set_output_path("data.ttl")
config.set_output_format(pyrudof.OutputFormat.Turtle)  # or .NTriples
config.set_compress(False)
config.set_write_stats(True)

# Parallelism
config.set_worker_threads(4)
config.set_batch_size(100)
config.set_parallel_writing(True)
config.set_parallel_file_count(4)

Configuration files

# Load / save TOML
config = pyrudof.GeneratorConfig.from_toml_file("config.toml")
config.to_toml_file("saved.toml")

# Load / save JSON
config = pyrudof.GeneratorConfig.from_json_file("config.json")

See the advanced examples in examples/advanced_generate_example.py and examples/config_file_example.py for more patterns.

Project details


Release history Release notifications | RSS feed

This version

0.2.7

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pyrudof-0.2.7-cp37-abi3-win_amd64.whl (8.6 MB view details)

Uploaded CPython 3.7+Windows x86-64

pyrudof-0.2.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.9 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

pyrudof-0.2.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

pyrudof-0.2.7-cp37-abi3-macosx_11_0_arm64.whl (8.9 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

pyrudof-0.2.7-cp37-abi3-macosx_10_12_x86_64.whl (9.3 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file pyrudof-0.2.7-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: pyrudof-0.2.7-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pyrudof-0.2.7-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 67636ffb867a8af443dc20e12a91d19bce8194d124130c99a7fc93c16114a485
MD5 ea99a94a6952113f7785959022b0bf30
BLAKE2b-256 721262cadbb6f87d4a28bb33579fb3ce5467b1feab0c1713f4b0d1123ac4ced0

See more details on using hashes here.

File details

Details for the file pyrudof-0.2.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyrudof-0.2.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cdcaeaf34a2c1a212cd29f48aecdcc3c0f91cc5fbbc6c14a633fee203173c18d
MD5 0044732e3000d7e08f6b4cd5849fa263
BLAKE2b-256 f846be36c8310404f6611aa5d31532ec0ba6e8dfcc6321f1c6148bfc864b4522

See more details on using hashes here.

File details

Details for the file pyrudof-0.2.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyrudof-0.2.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b3bbcbd9b520b2b59ae258d1b9c7880306b4f08ae6a5c9bcfedcf8c3387a3755
MD5 6f666901896866b1f8bac323de0e94e7
BLAKE2b-256 94251d81e1a606ec7544b912daac2afb1621fa171274316c78a327370505f46c

See more details on using hashes here.

File details

Details for the file pyrudof-0.2.7-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyrudof-0.2.7-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f2be22b7ce9c5d884be7273e4d883d961cde747a4cec7f3e436849fbdaf5a20
MD5 1e63b8f1aca84b92889cecc4df9121db
BLAKE2b-256 41bd1902cdefe4d38dc8c2e8fba99e84527591a0f195ffef45f3bed0c0a8fb9f

See more details on using hashes here.

File details

Details for the file pyrudof-0.2.7-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyrudof-0.2.7-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d079db85095f772e76aff0a4dd9df64a501353b543c5b39dfe2ed05202942747
MD5 544c0ee9892c0ee23b4936d9c3428b5a
BLAKE2b-256 58d2fffdeaf57ca9f19389bb273f2dc289c4fbfb6b18e00a2561daee059bd59b

See more details on using hashes here.

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