NostrAccess (nostr_access v0.3.3)

View Source

nostr_access - Elixir library for querying Nostr relays with caching and deduplication.

Features

  • Query multiple Nostr relays simultaneously
  • Automatic event deduplication following NIP-01 rules
  • In-memory caching with configurable TTL
  • Connection pooling with automatic reconnection
  • Both synchronous (fetch/3) and asynchronous (stream/3) APIs

Quick Start

# Fetch events from a single relay
{:ok, events} = Nostr.Client.fetch(["wss://relay.example.com"], %{kinds: [1]})

# Stream events from multiple relays
{:ok, ref} = Nostr.Client.stream(["wss://relay1.com", "wss://relay2.com"], %{authors: ["pubkey"]})

# Receive events
receive do
  {:nostr_event, ^ref, event} -> event
  {:nostr_eose, ^ref, true} -> :done
end

Configuration

config :nostr_access,
  idle_ms: 5000,
  overall_timeout: 30_000,
  cache?: true,
  dedup_strategy: Nostr.Dedup.Default

Architecture

The library uses a supervision tree with:

  • Connection pools (≤3 connections per relay)
  • Subscription limits (≤10 subscriptions per connection)
  • Automatic idle timeout after REQs are sent (5000ms default)
  • Cache with TTL (2h for events, 10min for misses)

Summary

Functions

cancel(query_ref)

See Nostr.Client.cancel/1.

fetch(relays, filter, opts \\ [])

See Nostr.Client.fetch/3.

publish(relays, event, opts \\ [])

See Nostr.Client.publish/3.

stream(relays, filter, opts \\ [])

See Nostr.Client.stream/3.

version()

Returns the version of nostr_access.