ever4st
ever4st
alashazam@iris.to
Feb 14, 2025

Python: cleaner version

using nostr_sdk library read metadata from npub

Tested and working with nostr_sdk version 0.39

from nostr_sdk import Metadata, Client, Keys, Filter, PublicKey
from datetime import timedelta
import argparse
import asyncio
import json

async def main(npub):
	client = Client()
	await client.add_relay("wss://relay.damus.io")
	await client.connect()
	pk = PublicKey.parse(npub)
	print(f"\nGetting profile metadata for {npub}:")
	metadata = await client.fetch_metadata(pk, timedelta(seconds=15))

	# Printing each field of the Metadata object
	print(f"Name: {metadata.get_name()}")
	print(f"Display Name: {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()}")
	print(f"LUD06: {metadata.get_lud06()}")
	print(f"LUD16: {metadata.get_lud16()}")
	#print(f"Custom: {metadata.get_custom()}")

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Fetch all metadata for a given npub')
    parser.add_argument('npub', type=str, help='The npub of the user')
    args = parser.parse_args()
    asyncio.run(main(args.npub))