11# python-nostr
2+
23A Python library for making [ Nostr] ( https://github.com/nostr-protocol/nostr ) clients
34
45## Usage
6+
57** Generate a key**
8+
69``` python
710from nostr.key import PrivateKey
811
@@ -11,7 +14,9 @@ public_key = private_key.public_key
1114print (f " Private key: { private_key.bech32()} " )
1215print (f " Public key: { public_key.bech32()} " )
1316```
17+
1418** Connect to relays**
19+
1520``` python
1621import json
1722import ssl
@@ -27,12 +32,14 @@ time.sleep(1.25) # allow the connections to open
2732while relay_manager.message_pool.has_notices():
2833 notice_msg = relay_manager.message_pool.get_notice()
2934 print (notice_msg.content)
30-
35+
3136relay_manager.close_connections()
3237```
38+
3339** Publish to relays**
40+
3441``` python
35- import json
42+ import json
3643import ssl
3744import time
3845from nostr.event import Event
@@ -57,7 +64,9 @@ time.sleep(1) # allow the messages to send
5764
5865relay_manager.close_connections()
5966```
67+
6068** Receive events from relays**
69+
6170``` python
6271import json
6372import ssl
@@ -86,21 +95,34 @@ time.sleep(1) # allow the messages to send
8695while relay_manager.message_pool.has_events():
8796 event_msg = relay_manager.message_pool.get_event()
8897 print (event_msg.event.content)
89-
98+
9099relay_manager.close_connections()
91100```
92101
93102## Installation
103+
94104``` bash
95105pip install nostr
96106```
97107
98108Note: I wrote this with Python 3.9.5.
99109
100- ## Test Suite
101- See the [ Test Suite README] ( test/README.md )
110+ ## Running tests
111+
112+ Install tox
113+
114+ ```
115+ pip install tox
116+ ```
117+
118+ Run tests
119+
120+ ```
121+ tox
122+ ```
102123
103124## Disclaimer
125+
104126- This library is in very early development.
105127- It might have some bugs.
106128- I need to add more tests.
0 commit comments