Skip to content

Relay

The Relay class represents a NOSTR relay server.

NameTypeDescription
urlstrURL of the relay, must begin with ws:// or wss://.
networkstrThe network type of the relay, either "clearnet" or "tor".

Initialize a Relay object.

  • url (str): URL of the relay.
>>> url = "wss://relay.nostr.com"
>>> relay = Relay(url)
  • Relay: Relay object initialized with the provided parameters.
  • TypeError: If url is not a string.
  • ValueError: If url does not start with "wss://" or "ws://".

Return a string representation of the Relay object.

  • None
>>> relay = Relay("wss://relay.nostr.com")
>>> relay
Relay(url=wss://relay.nostr.com, network=clearnet)
  • str: A string that shows the url and network of the relay.
  • None

Create a Relay object from a dictionary.

  • data (dict): A dictionary with the key "url".
>>> data = {"url": "wss://relay.nostr.com"}
>>> relay = Relay.from_dict(data)
>>> relay
Relay(url=wss://relay.nostr.com, network=clearnet)
  • Relay: Relay object created from the dictionary.
  • TypeError: If data is not a dictionary.
  • KeyError: If "url" key is missing in the dictionary.

Return a dictionary representation of the Relay object.

  • None
>>> relay = Relay("wss://relay.nostr.com")
>>> relay.to_dict()
{'url': 'wss://relay.nostr.com', 'network': 'clearnet'}
  • dict: Dictionary representation of the Relay object.
  • None