Skip to main content

Python implementation of a kaspa grpc client

Project description

kaspy

Python implementation of a kaspa-grpc client.

work in progress...

Breaking changes will occur without prior notice!

Installaton:

pip install kaspy

Basic Documentaion:

Connecting to a RPC server with connect() or auto_connect():

# Import the kaspa client
from kaspy.kaspa_clients import RPCClient

#Initialize a client instance
client = RPCClient() 

#Connect to a predefined host
client.connect(host='<ip>', port='<port>') 

#OR

#Connect to a a publicaly broadcasted node from the dns_seed_servers.
client.auto_connect() #note: it may take a while to find a responsive nodes, timeout should be issued to not get stuck searching

Sending a request():

continued...

#define the command you want to send
command = 'getInfoRequest'

#build the payload for the command
payload = {} #in our case we don't need to send additional information 

#send the request to the server and retrive the response
resp  = client.request(command=command, payload=payload)

print(resp) # print response

Subscribing to a stream with subscribe():

continued...

command = 'notifyVirtualSelectedParentChainChangedRequest'

payload = {}

def callback_func(notification : dict) # create a callback function to process the notifications
    print(notification)

#send the request to the server and retrive the response
resp  = client.subscribe(command=command, payload=payload, callback=callback_func)

import time
time.sleep(5) # do stuff

client.unsubscribe(command) #unsubscribe to the stream

Disenganging the service with close() or disconnect()

continued...

client.disconnect() # finishes sending all requests and responses in Que, halts all operations, but keeps the channel open.

client.close() # closes the channel completely

for more references on commands and payloads see:

https://github.com/kaspanet/kaspad/blob/master/infrastructure/network/netadapter/server/grpcserver/protowire/rpc.md

for conversions to KaspaMessage command names reference:

https://github.com/kaspagang/kaspy/blob/master/kaspy/protos/messages.proto

known issues:

To Do:

Fix breaking issue

Clean up, lots of unused code left in place.

Implement error handling and timeouts

Implement Streaming Callback handling of notification messages

add to pip

Implement auto-reconnect options to client

  • Implement P2P communication
  • 2nd cleanup
  • Documentation
  • Allow for commandline use
  • ...
  • Async Implementation

Requirements

  • grpc
  • google

Contribute

feel free to open a pull request.

Authors

@D-Stacks

Donations welcome @ kaspa:qzyjckdvgyxgwqj8zztw7qkqylsp864fyquzg8ykmmwkz58snu85zlk0mfy89

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kaspy-0.0.10-py3.7.egg (69.8 kB view details)

Uploaded Egg

kaspy-0.0.10-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file kaspy-0.0.10-py3.7.egg.

File metadata

  • Download URL: kaspy-0.0.10-py3.7.egg
  • Upload date:
  • Size: 69.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.42.1 importlib-metadata/4.8.1 keyring/21.1.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.7.6

File hashes

Hashes for kaspy-0.0.10-py3.7.egg
Algorithm Hash digest
SHA256 21b16524e933ea0a74ab8348803652dd31a4ee6b1cb26c6c21d54b2dec9a8c0b
MD5 d3f48e0d7f72c7a1685ea6325f8a1d99
BLAKE2b-256 dd08c23ec7bc1a0fff91cba468cff7f1b90265a58097463cb927ab3c6798a600

See more details on using hashes here.

File details

Details for the file kaspy-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: kaspy-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.42.1 importlib-metadata/4.8.1 keyring/21.1.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.7.6

File hashes

Hashes for kaspy-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 dadf8abf8f8e32e4766302a9fe9bd05bca36cd29d930acb3f3e875dd12b02c6e
MD5 6c4cda762f419eab4cf89f53d91c15a4
BLAKE2b-256 c7cdaa82528584888b2a8f3a6364ca4ff0b69f8701b4517425e49868501c73a6

See more details on using hashes here.

Supported by

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