Coder Social home page Coder Social logo

rajeevbbqq / snet-cli Goto Github PK

View Code? Open in Web Editor NEW

This project forked from singnet/snet-cli

0.0 1.0 0.0 1.33 MB

SingularityNET CLI for interacting with SNET blockchain contracts and deployed services.

License: MIT License

Python 63.94% Shell 11.01% Makefile 0.10% Smarty 0.07% CSS 24.87%

snet-cli's Introduction

snet-python-monorepo

CircleCI

SingularityNET Python Monorepo

Packages

This repository is a monorepo that includes several packages that we publish to PyPI from a shared codebase, specifically:

Package Description
snet-cli Command line interface to interact with the SingularityNET platform
snet-sdk Integrate SingularityNET services seamlessly into Python applications

License

This project is licensed under the MIT License - see the LICENSE file for details.

snet-cli

CircleCI

SingularityNET CLI

Getting Started

These instructions are for the development and use of the SingularityNET CLI. For further details, please check our full Documentation.

Installing with pip

Install prerequisites

You should have python with version >= 3.6.5 and pip installed.

Additionally you should install the following packages:

  • libudev
  • libusb 1.0

If you use Ubuntu (or any Linux distribution with APT package support) you should do the following:

sudo apt-get install libudev-dev libusb-1.0-0-dev

Install snet-cli using pip

$ pip3 install snet-cli

Enabling commands autocomplete

If you want to enable auto completion of commands, you should install the following package

  • python-argcomplete

On ubuntu (or any Linux distribution with APT package support), you should do the following

sudo apt install python-argcomplete

After the package is installed, activate autocomplete

for all python commands (which includes snet commands as well)
sudo activate-global-python-argcomplete

Note: Changes will not take effect until shell is restarted.

only for snet commands, then you should do the following
echo 'eval "$(register-python-argcomplete snet)"' >> ~/.bashrc

then

source ~/.bashrc

Commands

Complete documentation is available here

Development

Installing

Prerequisites


  • Clone the git repository
$ git clone https://github.com/singnet/snet-cli.git
$ cd snet-cli/packages/snet_cli
  • Install development/test blockchain dependencies
$ ./scripts/blockchain install
  • Install the package in development/editable mode
$ pip3 install -e .

Building Docs

  • Install sphinx, sphinx-argparse and the rtd theme
$ pip install sphinx
$ pip install sphinx-argparse
$ pip install sphinx-rtd-theme
  • Run the build-docs.sh in the docs directory
$ cd docs
$ sh build-docs.sh

The documentation is generated under the docs/build/html folder

Release

This project is published to PyPI.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

snet-sdk-python

SingularityNET SDK for Python

Getting Started

These instructions are for the development and use of the SingularityNET SDK for Python.

Core concepts

The SingularityNET SDK allows you to make calls to SingularityNET services programmatically from your application.
To communicate between clients and services, SingularityNET uses gRPC.
To handle payment of services, SingularityNET uses Ethereum state channels.
The SingularityNET SDK abstracts and manages state channels with service providers on behalf of the user and handles authentication with the SingularityNET services.

Usage

To call a SingularityNET service, the user must be able to deposit funds (AGI tokens) to the Multi-Party Escrow Smart Contract.
To deposit these tokens or do any other transaction on the Ethereum blockchain, the user must possess an Ethereum identity with available Ether.

To interact with SingularityNET services, you must compile the appropriate client libraries for that service.
To generate the client libraries to use in your application, you need the SingularityNET Command Line Interface, or CLI, which you can download from PyPi, see https://github.com/singnet/snet-cli#installing-with-pip

Once you have the CLI installed, run the following command:

snet sdk generate-client-library python <org_id> <service_id>

Optionally, you can specify an output path; otherwise it's going to be ./client_libraries/python/<registry_address>/<org_id>/<service_id>.
You should move or copy these generated files to the root of your project.

Once you have installed the snet-sdk in your current environment and it's in your PYTHONPATH, you should import it and create an instance of the base sdk class:

from snet import sdk
from config import config
snet_sdk = sdk.SnetSDK(config)

The config parameter must be a Python dictionary.
See test_sdk_client.py.sample for a sample configuration file.

Free call configuration

If you want to use free call you need to add below mwntioned attributes in config file.

"free_call_auth_token-bin":"f2548d27ffd319b9c05918eeac15ebab934e5cfcd68e1ec3db2b92765",
"free-call-token-expiry-block":172800,
"email":"[email protected]"  

You can download this config for a given service from Dapp

Now, the instance of the sdk can be used to create service client instances. To create a service client instance, it needs to be supplied with the client libraries that you compiled before.
Specifically, it needs the Stub object of the service you want to use from the compiled _pb2_grpc.py file of the client library.
Continuing from the previous code this is an example using example-service from the snet organization:

import example_service_pb2_grpc

org_id = "snet"
service_id = "example-service"
group_name="default_group"

service_client = snet_sdk.create_service_client(org_id, service_id,example_service_pb2_grpc.CalculatorStub,group_name)

The generated service_client instance can be used to call the methods exposed by the service.
To call these methods, a request object must be provided. Specifically, you should pick the appropriate request message type that is referenced in the stub object.
Continuing from the previous code this is an example using example-service from the snet organization:

import example_service_pb2

request = example_service_pb2.Numbers(a=20, b=3)

result = service_client.service.mul(request)
print("Performing 20 * 3: {}".format(result))   # Performing 20 * 3: value: 60.0

You can get this code example at https://github.com/singnet/snet-code-examples/tree/python_client/python/client

For more information about gRPC and how to use it with Python, please see:


Development

Installing

Prerequisites


  • Clone the git repository
$ git clone [email protected]:singnet/snet-cli.git
$ cd snet-cli/snet_sdk
  • Install development/test blockchain dependencies
$ ./scripts/blockchain install
  • Install the package in development/editable mode
$ pip install -e .

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

snet-sdk-python

SingularityNET SDK for Python

Getting Started

These instructions are for the development and use of the SingularityNET SDK for Python.

Core concepts

The SingularityNET SDK allows you to make calls to SingularityNET services programmatically from your application.
To communicate between clients and services, SingularityNET uses gRPC.
To handle payment of services, SingularityNET uses Ethereum state channels.
The SingularityNET SDK abstracts and manages state channels with service providers on behalf of the user and handles authentication with the SingularityNET services.

Usage

To call a SingularityNET service, the user must be able to deposit funds (AGI tokens) to the Multi-Party Escrow Smart Contract.
To deposit these tokens or do any other transaction on the Ethereum blockchain, the user must possess an Ethereum identity with available Ether.

To interact with SingularityNET services, you must compile the appropriate client libraries for that service.
To generate the client libraries to use in your application, you need the SingularityNET Command Line Interface, or CLI, which you can download from PyPi, see https://github.com/singnet/snet-cli#installing-with-pip

Once you have the CLI installed, run the following command:

snet sdk generate-client-library python <org_id> <service_id>

Optionally, you can specify an output path; otherwise it's going to be ./client_libraries/python/<registry_address>/<org_id>/<service_id>.
You should move or copy these generated files to the root of your project.

Once you have installed the snet-sdk in your current environment and it's in your PYTHONPATH, you should import it and create an instance of the base sdk class:

from snet import sdk
from config import config
snet_sdk = sdk.SnetSDK(config)

The config parameter must be a Python dictionary.
See config.py.sample for a sample configuration file.

Now, the instance of the sdk can be used to create service client instances. To create a service client instance, it needs to be supplied with the client libraries that you compiled before.
Specifically, it needs the Stub object of the service you want to use from the compiled _pb2_grpc.py file of the client library.
Continuing from the previous code this is an example using example-service from the snet organization:

import example_service_pb2_grpc

org_id = "snet"
service_id = "example-service"

service_client = sdk.create_service_client(org_id, service_id, example_service_pb2_grpc.CalculatorStub)

The generated service_client instance can be used to call the methods exposed by the service.
To call these methods, a request object must be provided. Specifically, you should pick the appropriate request message type that is referenced in the stub object.
Continuing from the previous code this is an example using example-service from the snet organization:

import example_service_pb2

request = example_service_pb2.Numbers(a=20, b=3)

result = service_client.service.mul(request)
print("Performing 20 * 3: {}".format(result))   # Performing 20 * 3: value: 60.0

You can get this code example at https://github.com/singnet/snet-code-examples/tree/python_client/python/client

For more information about gRPC and how to use it with Python, please see:


Development

Installing

Prerequisites


  • Clone the git repository
$ git clone [email protected]:singnet/snet-cli.git
$ cd snet-cli/snet_sdk
  • Install development/test blockchain dependencies
$ ./scripts/blockchain install
  • Install the package in development/editable mode
$ pip install -e .

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

snet-cli's People

Contributors

amebel avatar anandrgitnirman avatar anandsnet avatar arturgontijo avatar ascandella avatar astroseger avatar dhivakharvenkatachalam avatar ferrouswheel avatar keshrisohit avatar lcdupree avatar ldub avatar pennachin avatar prashantramangupta avatar pratik-vii avatar raamb avatar rajeevbbqq avatar restyled-commits avatar stellarspot avatar thebeast0407 avatar tiero avatar vforvalerio87 avatar vinthedark avatar vivek205 avatar vsbogd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.