
How to Send Messages on Nostr with Python (Complete Guide, 2025)
Want to post on Nostr from Python? Here's everything you need in one place. Install Dependencies pip install websocket-client coincurve That's it. Two packages. Generate Keys from coincurve import PrivateKey private_key = PrivateKey () public_key = private_key . public_key_xonly . hex () print ( f " Private key: { private_key . secret . hex () } " ) print ( f " Public key: { public_key } " ) Save your private key! There's no "forgot password" on Nostr. Send a Message import json import time import hashlib import websocket from coincurve import PrivateKey # Your keys PRIVATE_KEY = " your_hex_private_key " pk = PrivateKey ( bytes . fromhex ( PRIVATE_KEY )) pubkey = pk . public_key_xonly . hex () # Create event content = " Hello Nostr! Sent from Python 🐍 " created_at = int ( time . time ()) kind = 1 # Text note tags = [] # Sign (NIP-01) serialized = json . dumps ( [ 0 , pubkey , created_at , kind , tags , content ], separators = ( ' , ' , ' : ' ), ensure_ascii = False ) event_id = hashlib
Continue reading on Dev.to Tutorial
Opens in a new tab
