diff --git a/README.md b/README.md index 4c494c3..98621ec 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -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 @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 417a873..2b993d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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]" -] \ No newline at end of file +[tool.tox] +legacy_tox_ini = """ +[testenv] +deps = + pytest + pytest-cov[all] +commands = + pytest +""" diff --git a/test/README.md b/test/README.md deleted file mode 100644 index a63bd98..0000000 --- a/test/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Testing python-nostr - -## Set up the test environment - -Install the test-runner dependencies: -``` -pip3 install -r test/requirements.txt -``` - -Then make the `nostr` python module visible/importable to the tests by installing the local dev dir as an editable module: -``` -# from the repo root -pip3 install -e . -``` - -## Running the test suite -Run the whole test suite: -``` -# from the repo root -pytest -``` - -Run a specific test file: -``` -pytest test/test_this_file.py -``` - -Run a specific test: -``` -pytest test/test_this_file.py::test_this_specific_test -``` \ No newline at end of file