nostrclient, a Python client for Nostr.
git clone https://github.com/duozhutuan/nostrclient
cd nostrclient
pip3 install nostrclient --break-system-packages
filters = {"kinds":[1],"limit":100}
r = Relay(relays[0])
r.connect(5)
def handler_event(event):
print(event['content'])
sub = r.subscribe(filters)
sub.on("EVENT",handler_event)
from nostrclient.key import PrivateKey
from nostrclient.localStorage import local_storage
Keypriv = local_storage.get("Keypriv")
pkey = PrivateKey(Keypriv)
if Keypriv is None :
local_storage.set("Keypriv",str(pkey))
print("Your public key: ",pkey.public_key)
print("Your public key bech32: ",pkey.public_key.bech32())
r = RelayPool(relays,pkey)
content = "The message from nostrclient python nostr client."
kind = 42
tags = [['e', 'f412192fdc846952c75058e911d37a7392aa7fd2e727330f4344badc92fb8a22', 'wss://nos.lol', 'root']]
msg = {
"kind":kind,
"tags":tags,
"content":content,
}
r.publish(msg)
from nostrclient.user import User
user = User(pkey.public_key,r)
event = user.fetchProfile()
if event is not None:
print(event)
else:
print("No user Profile")