-
@ ever4st
2025-02-13 17:46:41This code below works with nostr_sdk 0.32.2
``` python import asyncio, argparse, json from nostr_sdk import Metadata, Client, NostrSigner, Keys, Filter, PublicKey, Kind from datetime import timedelta
async def main(npub): client = Client() await client.add_relay("wss://relay.damus.io") await client.connect() pk = PublicKey.from_bech32(npub) print(f"Getting profile metadata for {npub}:") f = Filter().kind(Kind(0)).author(pk).limit(1) events = await client.get_events_of([f], timedelta(seconds=15)) if events: event = events[0] metadata_dict = json.loads(event.content()) for key, value in metadata_dict.items(): print(f"{key}: {value}") else: print("Could not retrieve metadata for the given public key.")
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)) ``` but with nostr_sdk 0.39 the program no longer worked and crash with error:
AttributeError: type object 'PublicKey' has no attribute 'from_bech32'. Did you mean: 'to_bech32'?
why?
source: - https://github.com/ev3rst/nostr_sdk_examples - https://alashazam.wordpress.com/2024/07/07/python-nostr_sdk-fetching-all-metadata/