Metadata-Version: 2.4
Name: linkml-runtime-rust
Version: 0.4.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Libraries
Classifier: License :: OSI Approved :: Apache Software License
Summary: Rust-backed LinkML runtime for Python: schema loading, instance validation, diff/patch, Turtle import/export
Keywords: linkml,rdf,turtle,schema,validation
Author: Jonny Saunders
Author-email: Frank Dekervel <frank@kapernikov.com>
License: Apache-2.0
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Documentation, https://github.com/Kapernikov/rust-linkml-core#readme
Project-URL: Repository, https://github.com/Kapernikov/rust-linkml-core

# linkml-core

core linkml schema operations written in rust

## Showcase

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Kapernikov/rust-linkml-core/blob/main/notebooks/showcase.ipynb)

The [showcase notebook](notebooks/showcase.ipynb) demonstrates the Python bindings (`linkml-runtime-rust` on PyPI): schema loading without I/O, multi-schema namespace support with cross-schema slot disambiguation, instance loading/validation, diffing & patching, and Turtle export.

## Crates

- linkml_meta (`src/metamodel`): Autogenerated LinkML metamodel types and helpers. Optional Serde/PyO3 features for serialization and Python interop.
- schemaview (`src/schemaview`): Schema loading, CURIE/URI conversion, resolution (feature-gated), and view utilities: `SchemaView`, `ClassView`, `SlotView`, `EnumView`.
- linkml_runtime (`src/runtime`): Core runtime: `LinkMLInstance` parsing (YAML/JSON), basic validation, diff/patch, and Turtle serialization. Pure Rust library.
- linkml_tools (`src/tools`): CLI tools wrapping the runtime and schemaview:
  - `linkml-validate`, `linkml-convert`, `linkml-diff`, `linkml-patch`, `linkml-schema-validate`.
- linkml_runtime_python (`src/python`): PyO3 bindings and Python package (`linkml_runtime_rust._native`) exposing SchemaView and LinkMLInstance to Python; includes small Python helpers.
- linkml_wasm (`src/wasm`): WASM build target (experimental).

### SchemaView snapshots

`SchemaView` instances can be serialized into a **snapshot**—a self-contained YAML payload that carries
every loaded schema definition along with the resolved-import lineage and primary-schema pointer. The
snapshot can be reconstructed into an equivalent `SchemaView` without contacting remote import targets,
making it ideal for building views server-side and shipping them to Python, WASM, or browser clients.

- Rust: `SchemaView::to_snapshot_yaml()` / `SchemaView::from_snapshot_yaml(...)`
- Python: `SchemaView.to_snapshot_yaml()`, `SchemaView.from_snapshot_yaml(...)`
- WASM/JS: `JsSchemaView::toSnapshotYaml()`, `schemaview_from_snapshot_yaml(...)`

## Regenerating the metamodel

In order to regenerate the metamodel:

* Make sure you have a python virtual env with linkml_runtime (python!) installed, and that its active
* In the `../linkml` folder there should be a linkml checkout that is on a branch with the rust generator
* run the `regen.sh` script from the root of this repo

Note that now the metamodel is generated from src/schemaview/tests/data/meta.yaml.

### TODOs

* generate the metamodel directly from the linkml meta repository

## Development on the Python bindings

1. Create a virtual env and activate it
2. Install maturin (pip install maturin)
3. From repo root, run: `maturin develop -m src/python/Cargo.toml` (or use your venv: `../env/bin/maturin develop -m src/python/Cargo.toml`)

Now the `linkml_runtime_rust` module should be accessible.

## Building and testing

- Build all crates: `cargo build --workspace`
- Run all tests: `cargo test --workspace`
- Format: `cargo fmt --all` (check: `cargo fmt --all -- --check`)
- Lint: `cargo clippy --workspace --all-targets --all-features --exclude linkml_meta -- -D warnings --no-deps` (excludes autogenerated `linkml_meta`)

