Skip to content

Event

The Event class represents a single NOSTR event.

NameTypeDescription
idstrUnique identifier of the event, derived from event fields.
pubkeystrPublic key of the event creator.
created_atintUnix timestamp for when the event was created.
kindintInteger representing the type of event (0–65535).
tagsList[List[str]]List of tag lists, each tag is a list of strings.
contentstrText or JSON content of the event.
sigstrCryptographic signature of the event.
content_objdict or NoneParsed JSON object if content is valid JSON, otherwise None.

Initialize an Event object.

  • id (str): ID of the event, must be a 64-character hex string matching the calculated event ID.
  • pubkey (str): Public key of the event creator, 64-character hex string.
  • created_at (int): Unix timestamp of when the event was created (must be positive).
  • kind (int): Event type, integer between 0 and 65535.
  • tags (List[List[str]]): Tags associated with the event; each tag is a list of strings.
  • content (str): Event content, raw string (JSON or plain text).
  • sig (str): Cryptographic signature, 128-character hex string.
>>> id = "0x123"
>>> pubkey = "0x123"
>>> created_at = 1612137600
>>> kind = 0
>>> tags = [["tag1", "tag2"]]
>>> content = "content"
>>> sig = "0x123"
>>> event = Event(id, pubkey, created_at, kind, tags, content, sig)
  • Event: Event object initialized with the provided parameters.
  • TypeError: If any input parameter has an incorrect type.
  • ValueError: If kind is out of range, or if ID, pubkey, or signature lengths are incorrect.
  • ValueError: If created_at is negative.
  • ValueError: If the event ID or signature is invalid based on verification.

Return a string representation of the Event object.

  • None
>>> event = Event(id, pubkey, created_at, kind, tags, content, sig)
>>> event
Event(id=0x123, pubkey=0x123, created_at=1612137600, kind=0, tags=[["tag1", "tag2"]], content=content, sig=0x123)
  • str: String representation of the Event object.

Create an Event object from a dictionary.

  • data (dict): Dictionary with keys "id", "pubkey", "created_at", "kind", "tags", "content", and "sig".
>>> data = {"id": "0x123", "pubkey": "0x123", "created_at": 1612137600, "kind": 0, "tags": [["tag1", "tag2"]], "content": "content", "sig": "0x123"}
>>> event = Event.from_dict(data)
Event(id=0x123, pubkey=0x123, created_at=1612137600, kind=0, tags=[["tag1", "tag2"]], content=content, sig=0x123)
  • Event: Event object created from the dictionary.
  • TypeError: If data is not a dictionary.
  • KeyError: If any required key is missing in data.

Return a dictionary representation of the Event object.

  • None
>>> event = Event(id, pubkey, created_at, kind, tags, content, sig)
>>> event.to_dict()
{'id': '0x123', 'pubkey': '0x123', 'created_at': 1612137600, 'kind': 0, 'tags': [['tag1', 'tag2']], 'content': 'content', 'sig': '0x123', 'content_obj': None}
  • dict: Dictionary representation of the Event object, including content_obj.