Relay
The Relay class represents a NOSTR relay server.
Attributes
Section titled “Attributes”| Name | Type | Description |
|---|---|---|
url | str | URL of the relay, must begin with ws:// or wss://. |
network | str | The network type of the relay, either "clearnet" or "tor". |
Methods
Section titled “Methods”__init__
Section titled “__init__”Initialize a Relay object.
Parameters
Section titled “Parameters”url(str): URL of the relay.
Example
Section titled “Example”>>> url = "wss://relay.nostr.com">>> relay = Relay(url)Returns
Section titled “Returns”Relay: Relay object initialized with the provided parameters.
Raises
Section titled “Raises”TypeError: Ifurlis not a string.ValueError: Ifurldoes not start with"wss://"or"ws://".
__repr__
Section titled “__repr__”Return a string representation of the Relay object.
Parameters
Section titled “Parameters”None
Example
Section titled “Example”>>> relay = Relay("wss://relay.nostr.com")>>> relayRelay(url=wss://relay.nostr.com, network=clearnet)Returns
Section titled “Returns”str: A string that shows theurlandnetworkof the relay.
Raises
Section titled “Raises”None
from_dict
Section titled “from_dict”Create a Relay object from a dictionary.
Parameters
Section titled “Parameters”data(dict): A dictionary with the key"url".
Example
Section titled “Example”>>> data = {"url": "wss://relay.nostr.com"}>>> relay = Relay.from_dict(data)>>> relayRelay(url=wss://relay.nostr.com, network=clearnet)Returns
Section titled “Returns”Relay: Relay object created from the dictionary.
Raises
Section titled “Raises”TypeError: Ifdatais not a dictionary.KeyError: If"url"key is missing in the dictionary.
to_dict
Section titled “to_dict”Return a dictionary representation of the Relay object.
Parameters
Section titled “Parameters”None
Example
Section titled “Example”>>> relay = Relay("wss://relay.nostr.com")>>> relay.to_dict(){'url': 'wss://relay.nostr.com', 'network': 'clearnet'}Returns
Section titled “Returns”dict: Dictionary representation of the Relay object.
Raises
Section titled “Raises”None