monstr
Monstr: Python Nostr module. Python code for working with nostr.
- A basic relay implementation for testing against locally
- Client for working with a single relay
- ClientPool for working with multiple relays
- Keys for working with and converting between hex/npub/nsec
- Entities for encoding and decoding NIP19 nostr entities
install
git clone https://github.com/monty888/monstr.git
cd monstr
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt # or pip install .
# probably required to run examples else nostr module won't be found
export PYTHONPATH="$PYTHONPATH:./"
to use postgres as store psycopg2 must be installed
# install wheel helper, if needed.
pip pip install wheel
# maybe required on linux
# sudo apt install postgresql automake pkg-config libtool
# maybe required on mac
# brew install postgresql automake pkg-config libtool libffi
# now actually install psycopg2
pip install psycopg2
test monstr package import
# create a new python shell
python3
>> import monstr
>> from monstr.encrypt import Keys
>> test = Keys()
>> Keys.is_valid_key(test.private_key_hex())
True
>>
Note: developed against python 3.10.6
use
basic queries with context manager
from monstr.client.client import Client
async with Client(url) as c:
events = await c.query({
'limit': 100
})
for c_evt in events:
print(c_evt)
basic queries without context manager
from monstr.client.client import Client
c = Client(url)
asyncio.create_task(c.run())
await c.wait_connect()
events = await c.query({
'limit': 100
})
for c_evt in events:
print(c_evt)
c.end()
further examples
/monstr/examples/keys.py - create new keys or look up other representation of existing keys
/monstr/examples/create_test_env - creates a test environment relay running on local host port 8888 storing data in sqlitedb prepopulated with some data - currently hardcoded to come from relay wss://nostr-pub.wellorder.net and based on key 5c4bf3e548683d61fb72be5f48c2dff0cf51901b9dd98ee8db178efe522e325f. The relay also has HTTP get methods added:
- /e
- /req
- /view_profile
/monstr/examples/basic_usage.py - examples query and post to test relay
/monstr/examples/post_text.py - type in and post text events to test relay
/monstr/examples/print_text_notes.py - display text notes for given key, EOSE and EVENT
/monstr/exampels/query.py - simple cmd line queries see query.py --help
/monstr/examples/simple_bot.py - a simple bot that return the count for each time it gets a message for a pub_k
/monstr/examples/view_profile.py - simple webserver running at 8080 with method /view_profile?pub_k={a_pub_k} that returns that profiles data by querying the local relay
Contribute:
-- TODO
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file monstr-0.1.2.tar.gz.
File metadata
- Download URL: monstr-0.1.2.tar.gz
- Upload date:
- Size: 95.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
python-httpx/0.24.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7027be7e7a22ddc9e5587b39d84ccd1e7129dc6a0cf110813b5420cec1fcf47
|
|
| MD5 |
0353c8497dc152d367b150b23ed256c6
|
|
| BLAKE2b-256 |
c3cfaf1b4c246fcfc243d10c2c637e299dc408eb89840801505039ff4ae9a4d1
|
File details
Details for the file monstr-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: monstr-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 103.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
python-httpx/0.24.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef1efbf479e2ce1c5be366c20471fa6f46700b9a2619fe36c3f5c78ed25f26db
|
|
| MD5 |
7d17119810ecaac304eae8ca98268cd8
|
|
| BLAKE2b-256 |
e99b933bdd3627e5171cdea69dc43d8a61433d28192c6b3d314412d5d18a6d11
|