Metadata-Version: 2.1
Name: postr
Version: 0.1.0
Summary: Small python nostr client
Author: Your Name
Author-email: you@example.com
Requires-Python: >=3.10,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: coincurve (>=18.0.0,<19.0.0)
Requires-Dist: pydantic (>=1.10.4,<2.0.0)
Requires-Dist: rel (>=0.4.7,<0.5.0)
Requires-Dist: socketify (>=0.0.5,<0.0.6)
Requires-Dist: websocket-client (>=1.4.2,<2.0.0)
Requires-Dist: websockets (>=10.4,<11.0)
Description-Content-Type: text/markdown

# Postr
Small python nostr client library for Python 3.10+

## Installation 
```
pip install postr
```

## Example

```python
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)
```
