Skip to main content

A simple python Data Vending Machine (DVM) implementation on nostr

Project description

ezdvm

Easily run any python code behind a DVM on Nostr. Just pick a kind (for basic text-to-text use 5050) and put the code you want to run in the do_work() function. Then run the DVM.

Install

cd ezdvm/
python3.12 -m venv venv
source venv/bin/activate
pip install ezdvm

Create your own DVM

Steps:

  1. Choose the job request kind in the init function
  2. Run any python code inside the do_work() function. The event arg is the original job request from the user, in the form of nostr-sdk event, for python examples see here: https://github.com/rust-nostr/nostr/tree/master/bindings/nostr-sdk-ffi/bindings-python/examples
from ezdvm import EZDVM


class HelloWorldDVM(EZDVM):

    def __init__(self):
        # choose the job request kinds you will listen and respond to
        super().__init__(kinds=[5050])

    async def do_work(self, event):
        return "Hello World!"


if __name__ == "__main__":
    hello_world_dvm = HelloWorldDVM()
    hello_world_dvm.add_relay("wss://relay.damus.io")
    hello_world_dvm.add_relay("wss://relay.primal.net")
    hello_world_dvm.add_relay("wss://nos.lol")
    hello_world_dvm.add_relay("wss://nostr-pub.wellorder.net")
    hello_world_dvm.start()

Testing

Once it's running on your machine, if you are using kind 5050 you can test it here: https://dvmdash.live/playground/

Note that currently you have to use a NIP-07 extension to login first

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ezdvm-0.1.1.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

ezdvm-0.1.1-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page