Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# python-nostr

A Python library for making [Nostr](https://github.com/nostr-protocol/nostr) clients

## Usage

**Generate a key**

```python
from nostr.key import PrivateKey

Expand All @@ -11,7 +14,9 @@ public_key = private_key.public_key
print(f"Private key: {private_key.bech32()}")
print(f"Public key: {public_key.bech32()}")
```

**Connect to relays**

```python
import json
import ssl
Expand All @@ -27,12 +32,14 @@ time.sleep(1.25) # allow the connections to open
while relay_manager.message_pool.has_notices():
notice_msg = relay_manager.message_pool.get_notice()
print(notice_msg.content)

relay_manager.close_connections()
```

**Publish to relays**

```python
import json
import json
import ssl
import time
from nostr.event import Event
Expand All @@ -57,7 +64,9 @@ time.sleep(1) # allow the messages to send

relay_manager.close_connections()
```

**Receive events from relays**

```python
import json
import ssl
Expand Down Expand Up @@ -86,21 +95,34 @@ time.sleep(1) # allow the messages to send
while relay_manager.message_pool.has_events():
event_msg = relay_manager.message_pool.get_event()
print(event_msg.event.content)

relay_manager.close_connections()
```

## Installation

```bash
pip install nostr
```

Note: I wrote this with Python 3.9.5.

## Test Suite
See the [Test Suite README](test/README.md)
## Running tests

Install tox

```
pip install tox
```

Run tests

```
tox
```

## Disclaimer

- This library is in very early development.
- It might have some bugs.
- I need to add more tests.
Expand Down
14 changes: 9 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ dynamic=["version"]
[tool.setuptools_scm]
write_to = "nostr/_version.py"

[project.optional-dependencies]
test = [
"pytest >=7.2.0",
"pytest-cov[all]"
]
[tool.tox]
legacy_tox_ini = """
[testenv]
deps =
pytest
pytest-cov[all]
commands =
pytest
"""
31 changes: 0 additions & 31 deletions test/README.md

This file was deleted.