Skip to main content

High level Nostr client library.

Project description

Nostr SDK - Python Package

Description

A high-level, Nostr client library.

If you're writing a typical Nostr client or bot, this is likely the crate you need.

However, the crate is designed in a modular way and depends on several other lower-level libraries. If you're attempting something more custom, you might be interested in these:

Getting started

pip install nostr-sdk
import asyncio
from datetime import timedelta
from nostr_sdk import Keys, Client, NostrSigner, EventBuilder, Filter, Metadata, Nip46Signer, init_logger, LogLevel
import time


async def main():
    # Init logger
    init_logger(LogLevel.INFO)

    # Initialize client without signer
    # client = Client()

    # Or, initialize with Keys signer
    keys = Keys.generate()
    signer = NostrSigner.keys(keys)

    # Or, initialize with NIP46 signer
    # app_keys = Keys.parse("..")
    # uri = NostrConnectUri.parse("bunker://.. or nostrconnect://..")
    # nip46 = await Nip46Signer.init(uri, app_keys, timedelta(seconds=60), None)
    # signer = NostrSigner.nip46(nip46)

    client = Client(signer)

    # Add relays and connect
    await client.add_relays(["wss://relay.damus.io", "wss://nos.lol"])
    await client.connect()

    # Send an event using the Nostr Signer
    builder = EventBuilder.text_note("Test from Rust Nostr Python!", [])
    await client.send_event_builder(builder)
    await client.set_metadata(Metadata().set_name("Testing Rust Nostr"))

    # Mine a POW event and sign it with custom keys
    custom_keys = Keys.generate()
    print("Mining a POW text note...")
    event = EventBuilder.text_note("Hello from Rust Nostr Python bindings!", []).to_pow_event(custom_keys, 20)
    event_id = await client.send_event(event)
    print("Event sent:")
    print(f" hex:    {event_id.to_hex()}")
    print(f" bech32: {event_id.to_bech32()}")

    time.sleep(2.0)

    # Get events from relays
    print("Getting events from relays...")
    f = Filter().authors([keys.public_key(), custom_keys.public_key()])
    events = await client.get_events_of([f], timedelta(seconds=10))
    for event in events:
        print(event.as_json())


asyncio.run(main())

More examples can be found at:

Supported NIPs

Look at https://github.com/rust-nostr/nostr/tree/master/crates/nostr#supported-nips

Book

Learn more about rust-nostr at https://rust-nostr.org.

State

This library is in an ALPHA state, things that are implemented generally work but the API will change in breaking ways.

Donations

rust-nostr is free and open-source. This means we do not earn any revenue by selling it. Instead, we rely on your financial support. If you actively use any of the rust-nostr libs/software/services, then please donate.

License

This project is distributed under the MIT software license - see the LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

nostr_sdk-0.32.1-cp312-cp312-win_amd64.whl (5.9 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

nostr_sdk-0.32.1-cp312-cp312-manylinux_2_31_aarch64.whl (9.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.31+ ARM64

nostr_sdk-0.32.1-cp312-cp312-manylinux_2_28_x86_64.whl (8.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.28+ x86-64

nostr_sdk-0.32.1-cp312-cp312-macosx_11_0_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ x86-64

nostr_sdk-0.32.1-cp312-cp312-macosx_11_0_arm64.whl (7.5 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

nostr_sdk-0.32.1-cp311-cp311-win_amd64.whl (5.9 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

nostr_sdk-0.32.1-cp311-cp311-manylinux_2_31_aarch64.whl (9.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.31+ ARM64

nostr_sdk-0.32.1-cp311-cp311-manylinux_2_28_x86_64.whl (8.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

nostr_sdk-0.32.1-cp311-cp311-macosx_11_0_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ x86-64

nostr_sdk-0.32.1-cp311-cp311-macosx_11_0_arm64.whl (7.5 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

nostr_sdk-0.32.1-cp310-cp310-win_amd64.whl (5.9 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

nostr_sdk-0.32.1-cp310-cp310-manylinux_2_31_aarch64.whl (9.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.31+ ARM64

nostr_sdk-0.32.1-cp310-cp310-manylinux_2_28_x86_64.whl (8.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

nostr_sdk-0.32.1-cp310-cp310-macosx_11_0_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ x86-64

nostr_sdk-0.32.1-cp310-cp310-macosx_11_0_arm64.whl (7.5 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

nostr_sdk-0.32.1-cp39-cp39-win_amd64.whl (5.9 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

nostr_sdk-0.32.1-cp39-cp39-manylinux_2_31_aarch64.whl (9.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.31+ ARM64

nostr_sdk-0.32.1-cp39-cp39-manylinux_2_28_x86_64.whl (8.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

nostr_sdk-0.32.1-cp39-cp39-macosx_11_0_x86_64.whl (7.9 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ x86-64

nostr_sdk-0.32.1-cp39-cp39-macosx_11_0_arm64.whl (7.5 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page