-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #254 from vforvalerio87/monorepo
Monorepo
- Loading branch information
Showing
121 changed files
with
1,218 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
venv/ | ||
.idea/ | ||
snet_cli.egg-info/ | ||
blockchain/node_modules/ | ||
__pycache__/ | ||
snet_cli/resources/contracts/abi | ||
snet_cli/resources/contracts/networks | ||
snet_cli/resources/proto/*.py | ||
snet_cli/resources/node_modules | ||
build/ | ||
dist/ | ||
client_libraries/ | ||
__pycache__ | ||
blockchain/node_modules | ||
snet.egg-info/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,18 @@ | ||
# snet-cli | ||
# snet-python-monorepo | ||
|
||
[![CircleCI](https://circleci.com/gh/singnet/snet-cli.svg?style=svg)](https://circleci.com/gh/singnet/snet-cli) | ||
|
||
SingularityNET CLI | ||
SingularityNET Python Monorepo | ||
|
||
## Getting Started | ||
## Packages | ||
This repository is a monorepo that includes several packages that we publish to PyPI from a shared codebase, specifically: | ||
|
||
These instructions are for the development and use of the SingularityNET CLI. | ||
For further details, please check our full [Documentation](http://snet-cli-docs.singularitynet.io/). | ||
|Package |Description | | ||
|----------------------------------------------|---------------------------------------------------------------------| | ||
|[snet-cli](https://pypi.org/project/snet-cli/)|Command line interface to interact with the SingularityNET platform | | ||
|[snet-sdk](https://pypi.org/project/snet-sdk/)|Integrate SingularityNET services seamlessly into Python applications| | ||
|
||
### 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: | ||
|
||
```bash | ||
sudo apt-get install libudev-dev libusb-1.0-0-dev | ||
``` | ||
|
||
#### Install snet-cli using pip | ||
|
||
```bash | ||
$ 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 | ||
|
||
```bash | ||
sudo apt install python-argcomplete | ||
``` | ||
After the package is installed, activate autocomplete | ||
|
||
##### for all python commands (which includes snet commands as well) | ||
|
||
```bash | ||
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 | ||
```bash | ||
echo 'eval "$(register-python-argcomplete snet)"' >> ~/.bashrc | ||
``` | ||
then | ||
```bash | ||
source ~/.bashrc | ||
``` | ||
|
||
## Commands | ||
|
||
Complete documentation is available [here](http://snet-cli-docs.singularitynet.io/) | ||
|
||
|
||
## Development | ||
|
||
### Installing | ||
|
||
#### Prerequisites | ||
|
||
* [Python 3.6.5](https://www.python.org/downloads/release/python-365/) | ||
* [Node 8+ w/npm](https://nodejs.org/en/download/) | ||
|
||
--- | ||
|
||
* Clone the git repository | ||
```bash | ||
$ git clone [email protected]:singnet/snet-cli.git | ||
$ cd snet-cli | ||
``` | ||
|
||
* Install development/test blockchain dependencies | ||
```bash | ||
$ ./scripts/blockchain install | ||
``` | ||
|
||
* Install the package in development/editable mode | ||
```bash | ||
$ pip3 install -e . | ||
``` | ||
|
||
#### Building Docs | ||
|
||
* Install sphinx, sphinx-argparse and the rtd theme | ||
```bash | ||
$ pip install sphinx | ||
$ pip install sphinx-argparse | ||
$ pip install sphinx-rtd-theme | ||
``` | ||
|
||
* Run the build-docs.sh in the docs directory | ||
```bash | ||
$ cd docs | ||
$ sh build-docs.sh | ||
``` | ||
|
||
The documentation is generated under the docs/build/html folder | ||
|
||
### Release | ||
|
||
This project is published to [PyPI](https://pypi.org/project/snet-cli/). | ||
|
||
### Versioning | ||
|
||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the | ||
[tags on this repository](https://github.com/singnet/snet-cli/tags). | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the | ||
[LICENSE](https://github.com/singnet/alpha-daemon/blob/master/LICENSE) file for details. | ||
[LICENSE](https://github.com/singnet/snet-cli/blob/master/LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
venv/ | ||
snet.sdk.egg-info/ | ||
build/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 SingularityNET | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# 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](https://grpc.io/). | ||
To handle payment of services, SingularityNET uses [Ethereum state channels](https://dev.singularitynet.io/docs/concepts/multi-party-escrow/). | ||
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](https://dev.singularitynet.io/docs/concepts/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](https://github.com/singnet/snet-cli/snet_cli#installing-with-pip) | ||
|
||
Once you have the CLI installed, run the following command: | ||
```bash | ||
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: | ||
|
||
```python | ||
from snet_sdk import SnetSDK | ||
from config import config | ||
snet = SnetSDK(config) | ||
``` | ||
|
||
The `config` parameter must be a Python dictionary. | ||
See [config.py.sample](https://github.com/singnet/snet-code-examples/blob/master/python/client/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: | ||
|
||
```python | ||
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: | ||
|
||
```python | ||
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](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: | ||
- [gRPC Basics - Python](https://grpc.io/docs/tutorials/basic/python.html) | ||
- [gRPC Python’s documentation](https://grpc.io/grpc/python/) | ||
|
||
--- | ||
|
||
## Development | ||
|
||
### Installing | ||
|
||
#### Prerequisites | ||
|
||
* [Python 3.6.5](https://www.python.org/downloads/release/python-365/) | ||
* [Node 8+ w/npm](https://nodejs.org/en/download/) | ||
|
||
--- | ||
|
||
* Clone the git repository | ||
```bash | ||
$ git clone [email protected]:singnet/snet-cli.git | ||
$ cd snet-cli/snet_sdk | ||
``` | ||
|
||
* Install development/test blockchain dependencies | ||
```bash | ||
$ ./scripts/blockchain install | ||
``` | ||
|
||
* Install the package in development/editable mode | ||
```bash | ||
$ pip install -e . | ||
``` | ||
|
||
### Versioning | ||
|
||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the | ||
[tags on this repository](https://github.com/singnet/snet-cli/tags). | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the | ||
[LICENSE](https://github.com/singnet/snet-cli/blob/master/snet_sdk/LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--index-url https://pypi.python.org/simple | ||
../snet_cli/ | ||
-e . |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pkg_resources | ||
from setuptools import setup, find_namespace_packages | ||
|
||
|
||
PACKAGE_NAME = 'snet.sdk' | ||
|
||
|
||
def is_package_installed(package_name): | ||
installed_modules = [p.project_name for p in pkg_resources.working_set] | ||
return package_name in installed_modules | ||
|
||
|
||
dependencies = [] | ||
|
||
|
||
if is_package_installed('snet-cli'): | ||
# The default setup.py in the snet_cli package for local development installs the whole snet_cli package, | ||
# not the standalone snet.snet_cli namespace package; if a strict dependency on snet.snet_cli was enforced, | ||
# this setup.py would fetch it from PyPI. So, if snet_cli is installed and in your Python path, the | ||
# dependency on snet.snet_cli will be skipped. | ||
# If snet_cli is not available, snet.snet_cli will be fetched from PyPI. | ||
print("Package 'snet_cli' is installed and in your PYTHONPATH: skipping snet.snet_cli dependency") | ||
else: | ||
dependencies.append('snet.snet_cli') | ||
|
||
|
||
version_dict = {} | ||
with open("./snet/sdk/version.py") as fp: | ||
exec(fp.read(), version_dict) | ||
|
||
setup( | ||
name=PACKAGE_NAME, | ||
version=version_dict['__version__'], | ||
packages=find_namespace_packages(include=['snet.*']), | ||
namespace_packages=['snet'], | ||
url='https://github.com/singnet/snet-cli/tree/master/snet_sdk', | ||
license='MIT', | ||
author='SingularityNET Foundation', | ||
author_email='[email protected]', | ||
description='SingularityNET Python SDK', | ||
python_requires='>=3.6', | ||
install_requires=dependencies | ||
) |
Oops, something went wrong.