# Cosmos Protobuf
This repository compains the whole cosmos protobuf files compiled for python and ready to use with grpc. Please use the according .proto file as documentation for each python file.
## Installation
You can install this package directly from the repository by using:
```
python -m pip install sentinel-protobuf
```
## Usage
The following code snippet will query the balances for the address ``osmo15hzhcvgs2ljfng6unghvr5l32prwqdyq4aguxn``. The according query.proto file in the bank subdirectory contains the Request and the Response for this request. The details for the response are defined in ``QueryAllBalancesResponse``. It contains the balances and pagination attribute which can be accessed as shown in the example below.
```python
import grpc
import cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2_grpc as query_pb2_grpc
import cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2 as query_pb2
host = "osmosis.strange.love"
port = "9090"
c = grpc.insecure_channel(f'{host}:{port}')
stub = query_pb2_grpc.QueryStub(c)
r = stub.AllBalances(query_pb2.QueryAllBalancesRequest(address="osmo15hzhcvgs2ljfng6unghvr5l32prwqdyq4aguxn"))
print(r.balances)
```
### Sentinel example
The following code snippet will query all the subscription for sentnode123
```python
import grpc
from sentinel_protobuf.sentinel.subscription.v2.subscription_pb2 import NodeSubscription
from sentinel_protobuf.sentinel.subscription.v2.querier_pb2 import QuerySubscriptionsForNodeRequest
from sentinel_protobuf.sentinel.subscription.v2.querier_pb2_grpc import QueryServiceStub
# channel = grpc.secure_channel("host:port", grpc.ssl_channel_credentials())
channel = grpc.insecure_channel("grpc.sentinel.co:9090")
stub = QueryServiceStub(channel)
response = stub.QuerySubscriptionsForNode(QuerySubscriptionsForNodeRequest(address="sentnode123"))
for subscription in response.subscriptions:
print(NodeSubscription.FromString(subscription.value))
```
## Build yourself
There are two scripts helping you to fork this repository to work with any cosmos based coin.
Addititional Requirements:
1. `grpcio-tools`
2. `GitPython`
3. `protoletariat`
Steps:
1. Create a config in ``configs`` and take a existing one as example
2. Run the ``aggregate.py`` file with your filename without ``.json`` (Example ``python aggregate.py cosmos``)
3. Run the ``compile.py`` to compile all your files to protobuf
4. Build your package. You're done!
## Protobuf compilation
The files are compiled using the ``grpc_tools.protoc`` command from the [grpcio-tools](https://pypi.org/project/grpcio-tools/) library.
To compile a .proto file manually use following command:
```
python -m grpc_tools.protoc -I <absolute path to project root> --python_out=. --grpc_python_out=. <absolute path to .proto file>
```
After compiling all the files with protoc you need to fix the imports by using [protoletariat](https://github.com/cpcloud/protoletariat)
Note:
* The --grpc_python_out=. is only needed when compiling a query.proto file as these define the actual grpc query
* To compile the whole project it is favorable to match all proto files by using `*.proto` instead of each individual file. You can also match the whole folders to compile multiple folders at the same time. Not that the folders might contain sub-folders.
## Other Cosmos based coins
Currently following coins are maintained by me:
* Cosmos (this branch)
* Evmos (branch: ``chain/evmos``, package name: ``evmos-protobuf``)
* Osmosis (branch: ``chain/osmosis``, package name: `osmosis-protobuf`)
* Stargaze (branch: ``chain/stargaze``, package name: `stargaze-protobuf`)
* Sentinel (branch: ``chain/sentinel``, package name `sentinel-protobuf`)
Raw data
{
"_id": null,
"home_page": "",
"name": "sentinel-protobuf",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "cosmos,cosmospy,cosmospy-protobuf,proto,protobuf,sentinel,sentinel-protobuf",
"author": "",
"author_email": "freQniK <freQniK@mathnodes.com>",
"download_url": "https://files.pythonhosted.org/packages/d3/8c/24588ff21b29bf437c6e1ba77b9ae3de3939dc46e08d8e6e334d14d27950/sentinel_protobuf-0.3.3.tar.gz",
"platform": null,
"description": "# Cosmos Protobuf\nThis repository compains the whole cosmos protobuf files compiled for python and ready to use with grpc. Please use the according .proto file as documentation for each python file.\n\n## Installation\n\nYou can install this package directly from the repository by using:\n```\npython -m pip install sentinel-protobuf\n```\n\n## Usage\n\nThe following code snippet will query the balances for the address ``osmo15hzhcvgs2ljfng6unghvr5l32prwqdyq4aguxn``. The according query.proto file in the bank subdirectory contains the Request and the Response for this request. The details for the response are defined in ``QueryAllBalancesResponse``. It contains the balances and pagination attribute which can be accessed as shown in the example below. \n\n```python\nimport grpc\nimport cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2_grpc as query_pb2_grpc\nimport cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2 as query_pb2\n\nhost = \"osmosis.strange.love\"\nport = \"9090\"\n\nc = grpc.insecure_channel(f'{host}:{port}')\nstub = query_pb2_grpc.QueryStub(c)\n\nr = stub.AllBalances(query_pb2.QueryAllBalancesRequest(address=\"osmo15hzhcvgs2ljfng6unghvr5l32prwqdyq4aguxn\"))\nprint(r.balances)\n\n```\n### Sentinel example\nThe following code snippet will query all the subscription for sentnode123\n\n```python\nimport grpc\nfrom sentinel_protobuf.sentinel.subscription.v2.subscription_pb2 import NodeSubscription\nfrom sentinel_protobuf.sentinel.subscription.v2.querier_pb2 import QuerySubscriptionsForNodeRequest\nfrom sentinel_protobuf.sentinel.subscription.v2.querier_pb2_grpc import QueryServiceStub\n\n# channel = grpc.secure_channel(\"host:port\", grpc.ssl_channel_credentials())\nchannel = grpc.insecure_channel(\"grpc.sentinel.co:9090\")\nstub = QueryServiceStub(channel)\n\nresponse = stub.QuerySubscriptionsForNode(QuerySubscriptionsForNodeRequest(address=\"sentnode123\"))\nfor subscription in response.subscriptions:\n print(NodeSubscription.FromString(subscription.value))\n```\n\n## Build yourself\nThere are two scripts helping you to fork this repository to work with any cosmos based coin.\n\nAddititional Requirements:\n1. `grpcio-tools`\n2. `GitPython`\n3. `protoletariat`\n\nSteps:\n1. Create a config in ``configs`` and take a existing one as example\n2. Run the ``aggregate.py`` file with your filename without ``.json`` (Example ``python aggregate.py cosmos``)\n3. Run the ``compile.py`` to compile all your files to protobuf\n4. Build your package. You're done!\n\n## Protobuf compilation \n\nThe files are compiled using the ``grpc_tools.protoc`` command from the [grpcio-tools](https://pypi.org/project/grpcio-tools/) library.\nTo compile a .proto file manually use following command:\n```\npython -m grpc_tools.protoc -I <absolute path to project root> --python_out=. --grpc_python_out=. <absolute path to .proto file>\n```\n\nAfter compiling all the files with protoc you need to fix the imports by using [protoletariat](https://github.com/cpcloud/protoletariat)\n\nNote:\n* The --grpc_python_out=. is only needed when compiling a query.proto file as these define the actual grpc query\n* To compile the whole project it is favorable to match all proto files by using `*.proto` instead of each individual file. You can also match the whole folders to compile multiple folders at the same time. Not that the folders might contain sub-folders.\n\n## Other Cosmos based coins\nCurrently following coins are maintained by me:\n* Cosmos (this branch)\n* Evmos (branch: ``chain/evmos``, package name: ``evmos-protobuf``)\n* Osmosis (branch: ``chain/osmosis``, package name: `osmosis-protobuf`)\n* Stargaze (branch: ``chain/stargaze``, package name: `stargaze-protobuf`)\n* Sentinel (branch: ``chain/sentinel``, package name `sentinel-protobuf`)\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License",
"summary": "This package contains a compiled python version of all sentinel protobuf files with their dependencies",
"version": "0.3.3",
"project_urls": {
"Bug Tracker": "https://github.com/MathNodes/cosmospy-protobuf/issues",
"Homepage": "https://github.com/MathNodes/cosmospy-protobuf/"
},
"split_keywords": [
"cosmos",
"cosmospy",
"cosmospy-protobuf",
"proto",
"protobuf",
"sentinel",
"sentinel-protobuf"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f35220c847723d42712575a5d3c7329dd35bc43aec52a7bb54263ca14aaaec96",
"md5": "fa7e30bf8d5e76f0198ecabd17f501e3",
"sha256": "f9881b75cd481d8229e84c6fef38bcc093e4621450c195ba85773bdd42de7ecb"
},
"downloads": -1,
"filename": "sentinel_protobuf-0.3.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "fa7e30bf8d5e76f0198ecabd17f501e3",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 632574,
"upload_time": "2023-12-27T18:59:20",
"upload_time_iso_8601": "2023-12-27T18:59:20.321487Z",
"url": "https://files.pythonhosted.org/packages/f3/52/20c847723d42712575a5d3c7329dd35bc43aec52a7bb54263ca14aaaec96/sentinel_protobuf-0.3.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d38c24588ff21b29bf437c6e1ba77b9ae3de3939dc46e08d8e6e334d14d27950",
"md5": "f14c42ec39ffaba049c0d58f80f50d51",
"sha256": "0b1b7231ba399bb6735d0111e3b1c48e16c8053290264bea16a9223fac441361"
},
"downloads": -1,
"filename": "sentinel_protobuf-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "f14c42ec39ffaba049c0d58f80f50d51",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 277466,
"upload_time": "2023-12-27T18:59:24",
"upload_time_iso_8601": "2023-12-27T18:59:24.299625Z",
"url": "https://files.pythonhosted.org/packages/d3/8c/24588ff21b29bf437c6e1ba77b9ae3de3939dc46e08d8e6e334d14d27950/sentinel_protobuf-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-27 18:59:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MathNodes",
"github_project": "cosmospy-protobuf",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "sentinel-protobuf"
}