Skip to main content

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)

Metadata

Release files for postr 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for postr 0.1.0
File Size Uploaded Provenance Actions
postr-0.1.0.tar.gz 7.4 kB Without provenance Details for postr-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for postr 0.1.0
File Interpreter ABI Platform Actions
postr-0.1.0-py3-none-any.whl Python 3 none any Details for postr-0.1.0-py3-none-any.whl

Total release size: 16.8 kB

Release files / postr-0.1.0.tar.gz

Download URL postr-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d46a5f12d76e7c190cca5472045d178f11ea206575ce916d139406d18c105829
BLAKE2b-256 checksum
How to use checksums
a26402852a67de5c88b2e0d55d2fd7bf098fd83415793f4e0af84f9ade90d2a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.10 Windows/10

Release files / postr-0.1.0-py3-none-any.whl

Download URL postr-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0483909dc97ce39334b40cc70d0d23eaea7d9ddb3593c177a306417cb2500a3e
BLAKE2b-256 checksum
How to use checksums
acf5c5e707cb042e937f4b999a1dc29f0c04c9f5252408e3c816902190b4128f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.10.10 Windows/10

Security for postr 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page