event
event
¶
Immutable Nostr event wrapper with database serialization.
Accepts a nostr_sdk.Event at construction, eagerly extracts all fields
into Python-native types, and releases the FFI reference. The underlying
NostrEvent is consumed during construction and NOT retained, preventing
Rust-side memory from accumulating across event processing pipelines.
See Also
bigbrotr.models.event_relay: Junction model linking an Event to the Relay where it was observed. bigbrotr.services.synchronizer: The service that collects events from relays and persists them via this model.
Classes¶
EventDbParams
¶
Bases: NamedTuple
Positional parameters for the event database insert procedure.
Produced by Event.to_db_params()
and consumed by the event_insert stored procedure in PostgreSQL.
Attributes:
-
id(bytes) –Event ID as 32-byte binary (SHA-256 of the serialized event).
-
pubkey(bytes) –Author public key as 32-byte binary.
-
created_at(int) –Unix timestamp of event creation.
-
kind(int) –Integer event kind (e.g., 1 for text notes, 10002 for relay lists).
-
tags(str) –JSON-encoded array of tag arrays.
-
content(str) –Raw event content string.
-
sig(bytes) –Schnorr signature as 64-byte binary.
See Also
Event: The model that produces these parameters. EventRelayDbParams: Extends these fields with relay and junction data for cascade inserts.
Event
dataclass
¶
Immutable Nostr event with database conversion.
Accepts a nostr_sdk.Event at construction, validates it for
database compatibility, extracts all fields into Python-native types,
and releases the FFI reference. The underlying NostrEvent is NOT
retained after construction -- all domain data lives in regular Python
fields, consistent with every other model in this package.
Validation is performed eagerly at construction time:
- Content and tag values are checked for null bytes, which PostgreSQL TEXT columns reject.
- to_db_params() is called to ensure the event can be serialized before it leaves the constructor (fail-fast).
Parameters:
-
event(InitVar[Event]) –The
nostr_sdk.Eventto extract data from. Consumed during construction and not retained.
Raises:
-
ValueError–If content or tags contain null bytes, or if database parameter conversion fails.
Note
Domain fields store protocol-native representations: hex strings
for id, pubkey, and sig; integer seconds for
created_at; integer kind; raw content string; and an
immutable tuple-of-tuples for tags. Binary conversions
(bytes.fromhex) and JSON serialization (json.dumps)
happen once in _compute_db_params and are cached.
Equality and hashing are based on the domain fields
(id, pubkey, created_at, kind). Fields with
compare=False (tags, content, sig) are excluded
because id is already the SHA-256 of the full event content.
See Also
EventDbParams: Database parameter container produced by to_db_params(). EventRelay: Junction linking this event to the Relay where it was observed. EventKind: Well-known Nostr event kinds used across services.
Functions¶
to_db_params
¶
to_db_params() -> EventDbParams
Return cached positional parameters for the database insert procedure.
The result is computed once during construction and cached for the lifetime of the (frozen) instance, avoiding repeated hex conversions and tag serialization.
Returns:
-
EventDbParams–EventDbParams with binary
-
EventDbParams–id/pubkey/sig, integer timestamps, JSON-encoded tags, and raw
-
EventDbParams–content string.