python (pyrudof)

Overview

The python crate (published as pyrudof) is the Python bindings layer for the Rudof ecosystem. It exposes the Rust APIs from rudof_lib and rudof_generate to Python users through PyO3 and maturin.

Scope of exposed functionality

pyrudof currently exposes Python APIs for:

  • Loading and serializing RDF and PG data.
  • Loading, checking, serializing and validating ShEx schemas.
  • Loading, serializing and validating SHACL shapes.
  • Loading, serializing and validating PGSchemas.
  • Loading, running and serializing SPARQL queries and query results.
  • Converting and comparing schemas between supported formats.
  • Loading and serializing DCTAP and Service Descriptions.
  • Generating synthetic data from schemas.

Architecture and Package Structure

Package structure map

PathRoleNotes
src/lib.rsPyO3 module declaration and exportsCentral export surface via #[pymodule_export]
src/pyrudof_lib.rsMain Rudof class and core enums/errorsLargest binding unit
src/pyrudof_config.rsRudofConfig wrapperDefault config and from_path
src/pyrudof_generate.rsGenerator API wrappersIncludes Tokio runtime bridge
stubs/pyrudof/__init__.pyiRe-export typing surfacePublic typing entrypoint
stubs/pyrudof/pyrudof.pyiDetailed type stubsMethod signatures and enum values
examples/examples.tomlExamples manifestCategories, order, metadata, test policy
examples/**Executable Python examplesOrganized by domain folders
tests/test_examples.pyDynamic test class generationSubprocess execution of examples
tests/examples_registry.pyManifest parsing and validationValidates source files and metadata
docs/generate_examples_doc.pyAuto-generates examples docsReuses registry logic from tests

Test architecture

The test system is manifest-driven and intentionally avoids duplicate test logic.

Components

ComponentResponsibility
examples/examples.tomlDeclares categories, order, examples, files, expected_output, skip_test
tests/examples_registry.pyValidates manifest entries and builds in-memory catalog
tests/test_examples.pyDynamically creates one unittest.TestCase class per category
examples/**.pyExecutable scripts run exactly as end users would run them

Execution model

For each manifest entry, the generated test:

  1. Checks skip_test policy.
  2. Runs the script as a subprocess (python <source_file>) with cwd set to python/examples.
  3. Asserts exit code is zero.
  4. Verifies configured expected_output substrings if provided.

Docs generation architecture

docs/generate_examples_doc.py reuses tests/examples_registry.py to avoid dual parsing logic.

This creates a single-source pipeline:

  • Manifest + example files -> tests
  • Manifest + example files -> docs/examples.rst

Benefits:

  • Lower drift risk between docs and runnable examples.
  • Uniform category ordering and metadata usage.

Dependencies

This crate primarily depends on:

  • pyo3 — Rust/Python interop layer used to expose module classes, enums, and exceptions.
  • pythonize — Conversion helpers between Rust values and Python-friendly representations.
  • rudof_lib — Core Rudof semantic web facade wrapped by the Rudof Python class.
  • rudof_generate — Data generation engine wrapped by GeneratorConfig and DataGenerator.
  • tokio — Async runtime used by generation wrappers to run async Rust operations from synchronous Python APIs.

For packaging and developer workflows, it also uses:

  • maturin — Build backend for Python wheels and editable installs.
  • mypy — Static type checking for Python stubs.
  • ruff — Linting and formatting.
  • sphinx — Documentation generation.
  • sphinx-lint — Documentation lint checks.
  • sphinxawesome-theme — Sphinx theme used by the crate docs.