Skip to main content

snet-sdk-python

SingularityNET SDK for Python

Package

The package is published in PyPI at the following link:

Package Description
snet-sdk Integrate SingularityNET services seamlessly into Python applications

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.

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.

After executing this code, you should have client libraries created for this service. They are located in the following path: ~/.snet/org_id/service_id/python/

Note: Currently you can only save files to ~/.snet/

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. Continuing from the previous code this is an example using Exampleservicee from the 26072b8b6a0e448180f8c0e702ab6d2f organization:

import example_service_pb2_grpc

org_id = "26072b8b6a0e448180f8c0e702ab6d2f"
service_id = "Exampleservice"
group_name="default_group"

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

Note that org_id and service_id must be passed to config.

The generated service_client instance can be used to call methods provided by the service. To call these methods, you need to use the call_rpc method, passing into it the names of the method and data object, as well as the data itself (What specific data needs to be passed can be seen in the .proto file). Continuing from the previous code, this is an example using example-service from the snet organization:

result = service_client.call_rpc("mul", "Numbers", a=20, b=3)
print(f"Performing 20 * 3: {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-sdk-python.git
$ cd snet-sdk-python
  • Install the required dependencies
$ pip install -r requirements.txt
  • Install the package in development/editable mode
$ pip install -e .

License

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

Metadata

Release files for snet-sdk 3.2.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.2.0
File Size Uploaded
snet.sdk-3.2.0.tar.gz 18.2 kB Details

Built distribution (wheel)

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

Total release size: 41.7 kB

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

Download URL snet.sdk-3.2.0.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f695ee8c82310424c1bbdacb4a29a9086a4ce38573ae0cba50693c1c623be6d5
BLAKE2b-256 checksum
How to use checksums
648a80089703b0a73fbb843609cfd919d3ac1305adc6dfc442a853134e0a1caf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

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

Download URL snet.sdk-3.2.0-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82b3809be9beae4c0225eee2dcfee17720934ea53cca0b2f8583f99b10f83bde
BLAKE2b-256 checksum
How to use checksums
2f9c225fa33e7b9c02d9a5373cb0883ab59c65720e0d595cbe027a3078d35c30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

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

This release

3.2.0 This release

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

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