Skip to content

Relay Metadata

The RelayMetadata class represents the metadata of a NOSTR relay server.

NameTypeDescription
relayRelayThe relay object representing the relay connection.
generated_atintTimestamp when the metadata was generated.
connection_successboolWhether the connection to the relay was successful.
nip11_successboolWhether NIP-11 metadata was successfully retrieved.
openableOptional[bool]Whether the relay connection can be opened.
readableOptional[bool]Whether the relay supports reading.
writableOptional[bool]Whether the relay supports writing.
rtt_openOptional[int]Round-trip time for opening connection in ms.
rtt_readOptional[int]Round-trip time for reading in ms.
rtt_writeOptional[int]Round-trip time for writing in ms.
nameOptional[str]Name of the relay.
descriptionOptional[str]Description of the relay.
bannerOptional[str]URL to the banner image.
iconOptional[str]URL to the icon image.
pubkeyOptional[str]Public key of the relay operator.
contactOptional[str]Contact information for the relay.
supported_nipsOptional[List[int or str]]List of supported NIPs.
softwareOptional[str]Name of the software the relay is running.
versionOptional[str]Version of the relay software.
privacy_policyOptional[str]URL to the privacy policy.
terms_of_serviceOptional[str]URL to the terms of service.
limitationOptional[Dict[str, Any]]Dictionary of relay limitations.
extra_fieldsOptional[Dict[str, Any]]Additional custom fields for metadata.

Initialize a RelayMetadata object.

  • relay: Relay, the relay object.
  • generated_at: int, the timestamp when the metadata was generated.
  • connection_success: bool, indicates if the connection to the relay was successful.
  • nip11_success: bool, indicates if the NIP-11 metadata was successfully retrieved.
  • openable: Optional[bool], indicates if the relay connection can be opened.
  • readable: Optional[bool], indicates if the relay supports reading.
  • writable: Optional[bool], indicates if the relay supports writing.
  • rtt_open: Optional[int], round-trip time for connection opening.
  • rtt_read: Optional[int], round-trip time for reading.
  • rtt_write: Optional[int], round-trip time for writing.
  • name: Optional[str], the name of the relay.
  • description: Optional[str], a description of the relay.
  • banner: Optional[str], URL of the banner image.
  • icon: Optional[str], URL of the icon image.
  • pubkey: Optional[str], public key of the relay operator.
  • contact: Optional[str], contact information for the relay.
  • supported_nips: Optional[List[int or str]], list of supported NIPs.
  • software: Optional[str], software used by the relay.
  • version: Optional[str], version of the software.
  • privacy_policy: Optional[str], URL of the privacy policy.
  • terms_of_service: Optional[str], URL of the terms of service.
  • limitation: Optional[Dict[str, Any]], relay limitations.
  • extra_fields: Optional[Dict[str, Any]], additional fields for custom metadata.
>>> relay = Relay("wss://relay.example.com")
>>> relay_metadata = RelayMetadata(
relay=relay,
generated_at=1612137600,
connection_success=True,
nip11_success=True,
openable=True,
readable=True,
writable=True,
rtt_open=120,
rtt_read=80,
rtt_write=90,
name="Example Relay",
description="An example NOSTR relay",
banner="https://example.com/banner.png",
icon="https://example.com/icon.png",
pubkey="abcdef1234567890",
contact="contact@example.com",
supported_nips=[1, 2, 3],
software="nostr-relay-software",
version="1.0.0",
privacy_policy="https://example.com/privacy",
terms_of_service="https://example.com/terms",
limitation={"max_connections": 100},
extra_fields={"custom_field": "value"}
)
  • RelayMetadata: RelayMetadata object initialized with the provided parameters.
  • TypeError: If any input is of the wrong type.
  • TypeError: If limitations or extra_fields keys are not strings.
  • TypeError: If supported_nips contains non int or str elements.

Return a string representation of the RelayMetadata object showing all non-None attributes.

>>> relay_metadata = RelayMetadata(
relay=Relay("wss://relay.example.com"),
generated_at=1612137600,
connection_success=False,
nip11_success=False
)
>>> print(relay_metadata)
RelayMetadata(relay=Relay(url="wss://relay.example.com", network="clearnet"), generated_at=1612137600, connection_success=False, nip11_success=False)
  • str: String representation of the RelayMetadata object.
  • None

Creates a RelayMetadata object from a dictionary.

  • data: dict, dictionary representation of the RelayMetadata object.
>>> data = {
"relay": Relay("wss://relay.example.com"),
"generated_at": 1612137600,
"connection_success": False,
"nip11_success": False
}
>>> RelayMetadata.from_dict(data)
RelayMetadata(relay=Relay(url="wss://relay.example.com", network="clearnet"), generated_at=1612137600, connection_success=False, nip11_success=False)
  • RelayMetadata: RelayMetadata object created from the dictionary.
  • TypeError: If data is not a dict.
  • KeyError: If data does not contain the required keys.

Return a dictionary representation of the RelayMetadata object.

relay_metadata = RelayMetadata(
relay=Relay("wss://relay.example.com"),
generated_at=1612137600,
connection_success=False,
nip11_success=False
)
print(relay_metadata.to_dict())
{'relay': Relay(url="wss://relay.example.com", network="clearnet"), 'generated_at': 1612137600, 'connection_success': False, 'nip11_success': False}
  • dict: Dictionary representation of the RelayMetadata object.
  • None