-
![](https://image.nostr.build/ee47f48e7ca0d78892065638808cd731471ad07ebf26ddd0ed81fef437a1a5bd.jpg)
@ ever4st
2025-02-13 20:42:08
Installation:
``` bash
python3 -venv nostr-sdk
source nostr-sdk/bin/activate
pip install nostr_sdk requests
```
Python program:
``` python
# Usage example: python ns_read_metadata.py nostr:npub1mwce4c8qa2zn9zw9f372syrc9dsnqmyy3jkcmpqkzaze0slj94dqu6nmwy
# Compatible with version 0.39
# ns_read_metadata.py
# version 3
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.parse(npub)
print(f"\nGetting profile metadata for {npub}:")
metadata = await client.fetch_metadata(pk, timedelta(seconds=15))
print(metadata)
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))
```