Small python nostr client
Project description
Postr
Small python nostr client library for Python 3.10+
Installation
pip install postr
Example
import asyncio
import postr
async def controller():
user = postr.User()
hub = postr.RelayHub()
damus = await hub.connect("wss://relay.damus.io")
wellorder = await hub.connect("wss://nostr-verified.wellorder.net")
hub.publish(
postr.RequestMessage(
subscription_id="ABC",
filters=postr.Filter(kinds=postr.SetMetadata),
)
)
#
hub.publish(
postr.EventMessage(event=user.sign(postr.TextNote(content="Hello there!")))
)
# parse messages as they are received
while True:
match message := await hub.messages.get():
case postr.SubscriptionResponse(event=postr.TextNote()):
event = message.event
log.info(f"TextNote {event.content}")
case postr.SubscriptionResponse(event=postr.RecommendServer()):
event = message.event
known = set(map(lambda x: x.relay, hub.connections))
if event.url not in known:
log.info(f"Connecting to '{event.url}'")
socket = await hub.connect(event.url)
case postr.SubscriptionResponse(event=postr.SetMetadata()):
event = message.event
log.info(f"Set Metadata: {event.content}")
case postr.SubscriptionResponse():
event = message.event
log.info(f"unknown kind {event.kind}")
case postr.EndOfStoredEventsResponse():
log.info("Closing subscription at end of stored events")
hub.publish(
postr.CloseMessage(subscription_id=message.subscription_id),
connection=message.relay,
)
case _:
log.info("Received something else")
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
postr-0.1.0.tar.gz
(7.4 kB
view details)
Built Distribution
postr-0.1.0-py3-none-any.whl
(9.4 kB
view details)
File details
Details for the file postr-0.1.0.tar.gz
.
File metadata
- Download URL: postr-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.10 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d46a5f12d76e7c190cca5472045d178f11ea206575ce916d139406d18c105829 |
|
MD5 | 21ceb8b18e733eae447b63b3dd1187f0 |
|
BLAKE2b-256 | a26402852a67de5c88b2e0d55d2fd7bf098fd83415793f4e0af84f9ade90d2a3 |
File details
Details for the file postr-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: postr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.10 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0483909dc97ce39334b40cc70d0d23eaea7d9ddb3593c177a306417cb2500a3e |
|
MD5 | b14c084e7db1aa3caaba05bab057ad54 |
|
BLAKE2b-256 | acf5c5e707cb042e937f4b999a1dc29f0c04c9f5252408e3c816902190b4128f |