Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9cc11b3
feat: change channels caching to save already received channels after…
Arondondon Mar 11, 2026
3c7633d
feat: remove redundant imports
Arondondon Mar 11, 2026
e98f88e
fix: return web3 into the dependencies
Arondondon Mar 11, 2026
fb11a01
Merge pull request #108 from singnet/SPS-11
Arondondon Mar 11, 2026
62934e7
fix: add makefile, add linter, apply linter,
Arondondon Mar 11, 2026
287274c
Merge pull request #109 from singnet/SPS-14
Arondondon Mar 13, 2026
82d3c02
feat: rework config, add pydantic settings
Arondondon Mar 13, 2026
7fc2a36
Merge pull request #110 from singnet/SPS-16
Arondondon Mar 13, 2026
797cc2f
Merge pull request #111 from singnet/development
Arondondon Mar 13, 2026
26e5d96
feat: rework contracts calls, implement registry contract, enhance im…
Arondondon Mar 16, 2026
9051518
fix: change imports
Arondondon Mar 16, 2026
1a19737
feat: add new types, refactor storage provider
Arondondon Mar 17, 2026
a3895fc
fix: apply linter
Arondondon Mar 17, 2026
f2af65e
feat: start implementing service metadata
Arondondon Mar 18, 2026
5df5bf3
feat: end implementing service metadata, rework storage provider
Arondondon Mar 20, 2026
8ac6a69
feat: implement org metadata, end reworking storage provider
Arondondon Mar 20, 2026
476873f
feat: add functionality of publishing files into the storage, begin i…
Arondondon Mar 25, 2026
28c6abb
Merge pull request #113 from singnet/SPS-14
Arondondon Mar 25, 2026
485f29a
feat: fully replace deprecated service metadata implementation by new…
Arondondon Mar 25, 2026
78c64cf
feat: fully implement registry contract, service metadata and organiz…
Arondondon Mar 27, 2026
88aa179
feat: add updating org flow and validating metadata
Arondondon Mar 27, 2026
ce69a12
fix: fix several bugs, now service call is working
Arondondon Mar 27, 2026
6c59ca3
Merge pull request #114 from singnet/SPS-18
Arondondon Mar 27, 2026
28d7aea
fix: fix several bugs x2
Arondondon Mar 30, 2026
4bf0676
docs: update readme
Arondondon Mar 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lint:
@ruff check . --fix
@ruff format .
.PHONY: lint

test:
python -m coverage run -m pytest tests/ -v && \
python -m coverage report
.PHONY: test
180 changes: 129 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,70 @@ To handle payment of services, SingularityNET uses
[Ethereum state channels](https://dev.singularitynet.io/docs/products/DecentralizedAIPlatform/CoreConcepts/SmartContracts/mpe).
The SingularityNET SDK abstracts and manages state channels with service providers on behalf of the user and
handles authentication with the SingularityNET services.
To call a service on a SingularityNET platform, the user must be able to deposit funds (FET tokens) to the
[Multi-Party Escrow](https://dev.singularitynet.io/docs/products/DecentralizedAIPlatform/CoreConcepts/SmartContracts/mpe) Smart Contract.
To deposit these tokens or do any other transaction on the Ethereum blockchain.

## Getting Started

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

### Usage
### Installation

To call a service on a SingularityNET platform, the user must be able to deposit funds (FET tokens) to the
[Multi-Party Escrow](https://dev.singularitynet.io/docs/products/DecentralizedAIPlatform/CoreConcepts/SmartContracts/mpe) Smart Contract.
To deposit these tokens or do any other transaction on the Ethereum blockchain.
To install SingularityNET Python SDK package run:

```shell
pip install snet-sdk
```

### Config

There are three ways to configure the SDK (set variables):

- `.env` file

```dotenv
SNET_PRIVATE_KEY=12345678...
SNET_ETH_RPC_ENDPOINT=https://mainnet.infura.io/v3/12345678...
SNET_FORCE_UPDATE=False
SNET_LIGHTHOUSE_TOKEN=12345678...
```

- environment variables

- `configure()` function

Once you have installed snet-sdk in your current environment, you can import it into your Python script and create an
instance of the base sdk class:
```python
from snet import sdk

"""
SDK configuration provided by the application provider.
To run the application, replace 'private_key' and 'eth_rpc_endpoint' with your values.
"""
config = sdk.config.Config(
private_key="YOUR_PRIVATE_KEY", # Replace with your Ethereum private key
eth_rpc_endpoint="https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY", # Replace with your Alchemy API key
concurrency=False,
force_update=False
)
from snet.sdk.config import configure

# Initialize the SnetSDK instance
snet_sdk = sdk.SnetSDK(config)

PRIVATE_KEY = "12345678..."
INFURA_KEY = "12345678..."

configure(
private_key=PRIVATE_KEY,
eth_rpc_endpoint=f"https://mainnet.infura.io/v3/{INFURA_KEY}",
force_update=False,
lighthouse_token="12345678...",
)
```

The `config` parameter is an instance of the `Config` class.
See [config.py](https://dev.singularitynet.io/docs/products/DecentralizedAIPlatform/SDK/PythonSDK/Documentation/config/)
for a reference.
>Please note that variables in the '.env` file and environment variables must start with "SNET_" and must be uppercase!

#### Config parameters description

- `private_key`: Your wallet's private key that will be used to pay for calls. Is **required** in config;
- `private_key`: Your wallet's private key that will be used to sign transactions (and pay for calls). Is **required** in config;
- `signer_private_key`: Is equal to `private_key`, if not specified. Your wallet's private key that will be used to pay for calls.
- `eth_rpc_endpoint`: RPC endpoint that is used to access the Ethereum network. Is **required** in config;
> To get your **Alchemy API Key**, follow [this guide](https://dev.singularitynet.io/docs/products/DecentralizedAIPlatform/Daemon/alchemy-api/).

- `wallet_index`: The index of the wallet that will be used to pay for calls;
- `ipfs_endpoint`: IPFS endpoint that is used to access IPFS;
- `concurrency`: If set to True, will enable concurrency for the SDK;
- `force_update`: If set to False, will reuse the existing gRPC stubs (if any) instead of downloading proto and regenerating them every time.
- `mpe_contract_address`: The address of the Multi-Party Escrow smart contract;
- `token_contract_address`: The address of the SingularityNET token smart contract;
- `registry_contract_address`: The address of the Registry smart contract;
- `signer_private_key`: The private key of the signer. Used to sign the service call. Equals to `private_key` by default.

#### List organizations and their services

You can use the sdk client instance`s methods get_organization_list() to list all organizations and get_services_list("org_id") to list all services of a given organization.

```python
orgs_list = snet_sdk.get_organization_list()
print(*orgs_list, sep="\n")
# ...
# GoogleOrg3
# 26072b8b6a0e448180f8c0e702ab6d2f
# 43416d873fcb454589900189474b2eaa
# ...
```

```python
org_id = "26072b8b6a0e448180f8c0e702ab6d2f"
services_list = snet_sdk.get_services_list(org_id=org_id)
print(*services_list, sep="\n")
# Exampleservice
```
- `mpe_contract_address`: Custom address of the Multi-Party Escrow smart contract;
- `token_contract_address`: Custom address of ASI (FET) token smart contract;
- `registry_contract_address`: Custom address of the Registry smart contract;
- `lighthouse_token`: Personal Lighthouse storage token to save files into it.

### Calling the service

Expand All @@ -99,7 +93,7 @@ organization:
```python
service_client = snet_sdk.create_service_client(org_id="26072b8b6a0e448180f8c0e702ab6d2f",
service_id="Exampleservice",
group_name="default_group")
payment_strategy_type=PaymentStrategyType.PAID_CALL)
```

After executing this code, you should have client libraries created for this service. They are located at the following
Expand Down Expand Up @@ -145,6 +139,90 @@ perform other actions related to payment. In this case, the choice of payment st
opening a channel and depositing funds into MPE occurs automatically. For more information on payment, please
visit the [Payment](#payment) section.

## Organization and service managing

### Getting data

Here are useful methods for getting data

```python
from snet.sdk import SnetSDK

sdk = SnetSDK()
org_id = "<ORG_ID>"
service_id = "<SERVICE_ID>"

orgs_list = sdk.get_organization_list()
services_list = sdk.get_services_list(org_id=org_id)

org_metadata = sdk.get_organization_metadata(org_id)
service_metadata = sdk.get_service_metadata(org_id, service_id)
```

### Creating and publishing the service

- create service metadata instance using chaining methods

```python
from snet.sdk import SnetSDK, ServiceMetadata

sdk = SnetSDK()
org_id = "<ORG_ID>"
service_id = "<SERVICE_ID>"

service_metadata = (
ServiceMetadata(
version=1, display_name=service_id, service_type="grpc", tags=["first", "second"]
)
.add_group(free_call_signer_address="0x123456qweasd", endpoints=["https://test-daemon.com"])
.add_contributor("me")
)
```

- publish the service into blockchain including saving `.proto` files and service metadata into storage

```python
sdk.publish_service_comprehensively(
org_id,
service_id,
service_metadata,
proto_dir="<PATH_TO_DIR_WITH_PROTO_FILES>",
storage_type=StorageType.FILECOIN,
)
```

### Updating the service

- fetch and edit service metadata

```python
from snet.sdk import SnetSDK

sdk = SnetSDK()
org_id = "<ORG_ID>"
service_id = "<SERVICE_ID>"

service_metadata = sdk.get_service_metadata(org_id, service_id)
service_metadata.change_description(
short_description="new_short_description", description="new_description"
)
```

- update the service in blockchain including saving `.proto` files and service metadata into storage

```python
sdk.update_service(org_id, service_id, service_metadata)
```

> Please note that the Python SDK provides all the features for interacting with the SNET platform.
> You can use them separately using the following entities:
>
> - sdk.mpe_contract
> - sdk.registry_contract
> - sdk.storage_provider
> - sdk.payment_channel_provider
> - sdk.account

## Payment

When creating a service client, you can select a payment strategy using the `payment_strategy_type` parameter:
Expand Down
35 changes: 19 additions & 16 deletions examples/calculator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from snet import sdk

config = sdk.config.Config(private_key="YOUR_PRIVATE_KEY",
eth_rpc_endpoint=f"https://sepolia.infura.io/v3/YOUR_INFURA_KEY",
concurrency=False,
force_update=False)

operators = {
"+": "add",
"-": "sub",
"*": "mul",
"/": "div"
}
config = sdk.config.Config(
private_key="YOUR_PRIVATE_KEY",
eth_rpc_endpoint="https://sepolia.infura.io/v3/YOUR_INFURA_KEY",
concurrency=False,
force_update=False,
)

operators = {"+": "add", "-": "sub", "*": "mul", "/": "div"}

snet_sdk = sdk.SnetSDK(config)
calc_client = snet_sdk.create_service_client(org_id="26072b8b6a0e448180f8c0e702ab6d2f",
service_id="Exampleservice", group_name="default_group")
calc_client = snet_sdk.create_service_client(
org_id="26072b8b6a0e448180f8c0e702ab6d2f",
service_id="Exampleservice",
group_name="default_group",
)


def parse_expression(expression):
Expand All @@ -23,12 +23,16 @@ def parse_expression(expression):
raise Exception(f"Invalid expression '{expression}'. Three items required.")

if elements[1] not in ["+", "-", "*", "/"]:
raise Exception(f"Invalid expression '{expression}'. Operation must be '+' or '-' or '*' or '/'.")
raise Exception(
f"Invalid expression '{expression}'. Operation must be '+' or '-' or '*' or '/'."
)
try:
a = float(elements[0])
b = float(elements[2])
except ValueError:
raise Exception(f"Invalid expression '{expression}'. Operands must be integers or floating point numbers.")
raise Exception(
f"Invalid expression '{expression}'. Operands must be integers or floating point numbers."
)
op = elements[1]

return a, b, op
Expand All @@ -54,4 +58,3 @@ def main():

if __name__ == "__main__":
main()

Loading
Loading