Skip to main content

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":"test@test.com"  

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 git@github.com: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

Prerequisites

Note! don't use Python 3.8.2


Installing

  • Clone the git repository
$ git clone git@github.com:singnet/snet-cli.git
  • Install the required dependencies
$ cd snet-cli/packages/sdk
$ pip install -r requirements.txt
$ cd ../snet_cli
$ pip install -r requirements.txt
$ cd ../
$ pip install -r requirements.txt 
  • Install development/test blockchain dependencies
$ ./scripts/blockchain install
  • Blockchain configuration
    If required, you can view/edit the snet-cli configuration of ipfs, eth_rpc in ~/.snet/config for various networks.

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.

Metadata

Release files for snet-sdk 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snet-sdk 3.0.0
File Size Uploaded
snet.sdk-3.0.0.tar.gz 164.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for snet-sdk 3.0.0
File Interpreter ABI Platform
snet.sdk-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 332.1 kB

Release files / snet.sdk-3.0.0.tar.gz

Download URL snet.sdk-3.0.0.tar.gz
Size 164.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fa4008b6d40c0cec5070a156fbca2b3348865584067ee5f481996b18bdc62145
BLAKE2b-256 checksum
How to use checksums
c6279379ee71a1b97d49036b9366ab396a960c86748ce605613905969c515d4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

Release files / snet.sdk-3.0.0-py3-none-any.whl

Download URL snet.sdk-3.0.0-py3-none-any.whl
Size 168.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5eed568fcae330db81361203fb4dacbf0ea7fa722052898902a74b91f8489fc4
BLAKE2b-256 checksum
How to use checksums
ae1bbcae528205a13bc957602bcfb8db485c97e906d36f301b275ae168d75d82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9

Release history Release notifications | RSS feed

6.0.0

2 release files

5.1.0

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.7.2

2 release files

3.7.1

2 release files

3.7.0

2 release files

3.6.1

2 release files

3.6.0

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

This release

3.0.0 This release

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.0.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page