singnet / snet-sdk-python

Make gRPC calls to SingularityNET services programmatically using Python
MIT License
0 stars 1 forks source link

SDK API discussion #16

Open vsbogd opened 5 years ago

vsbogd commented 5 years ago

I have created this issue to discuss the API which should be provided by SDK for client development. Currently implemented approach is to generate client API stubs on the fly when new client instance is created (see Usage section of the README.md).

Example I have posted below has two items which I would like to discuss:

  1. it contains some example of API which can be used to configure SingularityNet service interaction session
  2. it demonstrates client implementation when client stubs are generated in advance, before developing a client code.
import snet
import snet.example_service as example_service

# Define identity, ethereum endpoint, IPFS endpoint, session cache strategy
identity = snet.PrivateKeyIdentity("path/to/private/key") 
eth = snet.KovanEth()
ipfs = snet.SnetIpfs()
cache = snet.FileSystemSessionCache("path/to/cache/folder")
session = snet.Session(identity=identity, eth=eth, ipfs=ipfs, cache=cache)

# Check AGI tokens balance and MultiPartyEscrow contract balance of session
# identity, and deposit tokens to the MultiPartyEscrow.
print("AGI tokens available:", session.balance())
session.deposit(1000)
print("AGI tokens available:", session.balance())

# Instantiate "Example Service" client and call the method.
# example_service.Calculator is generated as prerequisite step, for example
# user calls `snet sdk` command providing org_id and service_id to generate
# snet.example_service package with all necessary stubs. All logic related to
# opening channel, finding proper endpoint, switching between endpoints is
# embedded into service stub.
example_service = example_service.Calculator(session)
numbers = example_service.Numbers(a=7, b=6)
result = example_service.mul(numbers)
print("Calculation result:", result.value)
print("AGI tokens available:", session.balance())

Item 2 is not so important probably for interpreted languages like Python or JavaScript but it can be faster and may be simpler than generating stubs on the fly. BTW it is harder to reuse such stubs in snet-cli so it is a bit contradicts to issue #9.

ksridharbabuus commented 5 years ago

@vsbogd I mean Json Files with password as one of the Identity along with the existing identities we have.

chetankothari commented 5 years ago

@vsbogd the suggestions made here look good. For the second point now we will only pass ServiceClient to select.

chetankothari commented 5 years ago

@vsbogd @vforvalerio87 @astroseger @ferrouswheel @raamb JS SDK mostly done and minor things are pending. Since this is a huge PR, it would be great if you guys could add your feedback on the PR.