The Event struct represents the structure for an event in Nostr. Many of the NIPs define specific content and tags that are required to correctly represent a kind. The nostr crate ships with a set of NIP-specific utilities for working with certain event kinds.

Metadata (NIP-01)


Use the Metadata struct to deserialize the content of an event into a struct.

    let event = EventBuilder::new(Kind::Metadata, content, vec![]).to_event(&keys)?;
    let metadata = Metadata::from_json(&event.content)?;

If you have an existing metadata object, it can be used with the EventBuilder struct to create an EventBuilder with the metadata already attached.

    let metadata = Metadata::from_json(content)?;
    let event = EventBuilder::metadata(&metadata).to_event(&keys)?;

For documentation on the available struct attributes, check out the Metadata documentation.


Using the Metadata class to build the metadata object and the EventBuilder class to create a Metadata event.

    # Create metadata object with desired content
    metadata_content = Metadata()\
        .set_about("This is a Test Account for Rust Nostr Python Bindings")\

    # Build metadata event and assign content
    builder = EventBuilder.metadata(metadata_content)

    # Signed event and print details
    print("Creating Metadata Event:")
    event = builder.to_event(keys)

    print(" Event Details:")
    print(f"     Author    : {}")
    print(f"     Kind      : {event.kind().as_u16()}")
    print(f"     Content   : {event.content()}")
    print(f"     Datetime  : {event.created_at().to_human_datetime()}")
    print(f"     Signature : {event.signature()}")
    print(f"     Verify    : {event.verify()}")
    print(f"     JSON      : {event.as_json()}")

Use the Metadata class to deserialize the content of an exsiting metadata event.

    # Deserialize Metadata from event
    print("Deserializing Metadata Event:")
    metadata = Metadata().from_json(event.content())
    print(" Metadata Details:")
    print(f"     Name      : {metadata.get_name()}")
    print(f"     Display   : {metadata.get_display_name()}")
    print(f"     About     : {metadata.get_about()}")
    print(f"     Website   : {metadata.get_website()}")
    print(f"     Picture   : {metadata.get_picture()}")
    print(f"     Banner    : {metadata.get_banner()}")
    print(f"     NIP05     : {metadata.get_nip05()}")