Skip to main content

nostpy-cli

nostpy-cli is a Command Line Interface tool for sending and querying nostr events by websocket connection.

Features

  • Send events to specified relays
  • Query events from specified relays
  • Encode/decode kind4 messages
  • Supports NIP-50 searches

Prerequisites

Before installing nostpy-cli, ensure you have Python 3.6 or higher installed on your system. You can check your Python version by running:

python3 --version

Installation

Install Using pip

To install using pip use the command below:

pip install nostpy-cli

Build from source

Clone the Repository First, clone the repository to your local machine:

git clone https://github.com/UTXOnly/nostpy-cli.git
cd nostpy-cli
python3 -m build
pip install .

Usage

Once installed, you can run nostpy-cli from the command line as shown below:

Send Event

To send an event:

nostpy-cli send_event -privkey "your_private_key_hex" -content "your plaintext message" -tags "[['tag1', 'value1']]" -kind 4 --relay "wss://yourrelayurl.com" "wss://yoursecondrelayurl.com"

--priv_key and --relay arguments are required, all else are optional

Example

  • Send a kind 1 event with tags
nostpy-cli send_event -pubkey 5ce5b352f1ef76b1dffc5694dd5b34126137184cc9a7d78cba841c0635e17952 -privkey 2b1e4e1f26517dda57458596760bb3bd3bd3717083763166e12983a6421abc18 -content test27 -tags "[
['t', 'vvfdvfd'], ['v', 'v2']]" -kind 1 --relay wss://relay.nostpy.lol wss://relay.damus.io wss://nos.lol
  • Send a kind 4 direct message
nostpy-cli send_event -privkey 2b1e4e1f26517dda57458596760bb3bd3bd3717083763166e12983a6421abc18 -content "This is my plaintext message" -tags "[['p', '4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc']]" -kind 4 --relay wss://relay.nostpy.lol wss://relay.damus.io wss://nos.lol

Query Event

To query events:

nostpy-cli query --kinds "[1,9735]" --relay "wss://yourrelayurl.com"

--relay field required

Example

  • Query an event with search
nostpy-cli query -kinds "[31990,1]" -search "random_search" -since 1713629501 -authors npub1g5pm4gf8hh7skp2rsnw9h2pvkr32sdnuhkcx9yte7qxmrg6v4txqqudjqv --relay wss://relay.nostpy.lol

Decrypt kind4 message content

Decrypt kind4 message content by providing recipient private key hex, sender public key hex and the message ciphertext, returns the plaintext message

Example

nostpy-cli decrypt -content "kP9dCG/stpEGNTjW2/aySQ==?iv=+GCHVOBAiM9X074n1vxiFg==" -priv_key 2b1e4e1f26517dda57458596760bb3bd3bd3717083763166e12983a6421abc18 -sender_pubkey 4503baa127bdfd0b054384dc5ba82cb0e2a8367cbdb0629179f00db1a34caacc 

Help

To view all available commands and their options, use the help command:

nostpy-cli -h
usage: nostpy-cli [-h] {query,send_event,decode} ...

Send and query nostr events

options:
  -h, --help            show this help message and exit

commands:
  valid commands

  {query,send_event,decode}
                        additional help
    query               Query events
    send_event          Send an event
    decode              Decode kind4 content

Example send usage: nostpy-cli send_event -pubkey "abc123..." -privkey "def456..." -content "Hello, world!" --relay "wss://example.com"

Contributing

Contributions to nostpy-cli are welcome! Please feel free to submit pull requests or open issues to report bugs or suggest enhancements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Release files for nostpy-cli 0.3.3

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

Source distribution (sdist)

Source distribution for nostpy-cli 0.3.3
File Size Uploaded
nostpy_cli-0.3.3.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nostpy-cli 0.3.3
File Interpreter ABI Platform
nostpy_cli-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / nostpy_cli-0.3.3.tar.gz

Download URL nostpy_cli-0.3.3.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
eeffd0a905621f8b802debe012951c57dd1b8d84990db10a8e355ef4cef4ddeb
BLAKE2b-256 checksum
How to use checksums
5853f49fa6141dea843a88fe9254c078b7fd7754486c16764882341796b0bec1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.8.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

Release files / nostpy_cli-0.3.3-py3-none-any.whl

Download URL nostpy_cli-0.3.3-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a538ae1115f167397776a18600402d7547c61417e741027d60af9fb4782bfed
BLAKE2b-256 checksum
How to use checksums
996c317b574f861f65c46083b266766827b0b56913a5ca6d04619ca4146cac1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.8.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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