# nostralink
*nostralink* is a Rust crate that allows you to transform [nostr](https://nostr.how)
events to linked data and save them to an [RDF](https://www.w3.org/RDF) triple store.
It also offers APIs to write events as linked data (using JSON-LD) and make queries.
- Uses the great [oxigraph](https://crates.io/crates/oxigraph) with
[oxjsonld](https://crates.io/crates/oxjsonld) for fast conversion to RDF.
- Provides a [nostr-database](https://crates.io/crates/nostr-database) adapter so that
you can easily hook a [nostr client](https://crates.io/crates/nostr-sdk) to an
events store. Checkout the [client example](examples/client.rs).
- Uses [SparQL](https://www.w3.org/TR/sparql11-query/) to make queries on the
events graph.
JSON-LD contexts for various content types are provided, as well as
SparQL queries for common operations.
## Discuss
*IRC*: **#nostralink** channel on [libera.chat](https://libera.chat/).
# Usage
```rust
use nostralink::prelude::*;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<(), RdfStoreError> {
let keys = Keys::generate();
let store = RdfEventsStore::open(PathBuf::from("store")).expect("Cannot open store");
let client = Client::builder().database(store).signer(keys).build();
client.add_relay("wss://relay.damus.io").await?;
client
.subscribe(
Filter::new()
.kind(Kind::TextNote)
.limit(50)
.since(Timestamp::now() - 3600),
None,
)
.await?;
Ok(())
}
```
# Projects using nostralink
- [paz](https://codeberg.org/nostralink/paz) is an experimental nostr client built
with nostralink and egui.
# Examples
## Client
This example fetches recent notes to a store, and shows each incoming event in
the [ttl (Turtle)](https://www.w3.org/TR/turtle/) format.
```sh
cargo run -r --example client
```
# Resources
- [Book](https://nostralink.codeberg.page) (mirror [here](https://nostralink.gitlab.io))