Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ctrl-Felix/cosmospy-protobuf
Cosmos Protobuf library
https://github.com/ctrl-Felix/cosmospy-protobuf
Last synced: 8 days ago
JSON representation
Cosmos Protobuf library
- Host: GitHub
- URL: https://github.com/ctrl-Felix/cosmospy-protobuf
- Owner: ctrl-Felix
- Created: 2022-05-01T23:00:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-30T21:37:00.000Z (11 months ago)
- Last Synced: 2024-03-24T11:02:59.056Z (8 months ago)
- Language: Python
- Homepage:
- Size: 1.31 MB
- Stars: 16
- Watchers: 1
- Forks: 15
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-cosmos - cosmospy-protobuf - A Python library containing all compiled protobuf files (works very good for grpc). (Client Libraries / Python)
README
# 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 cosmospy-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 # using grpcio
import cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2_grpc as query_pb2_grpc # for gprcio
#import cosmospy_protobuf.cosmos.bank.v1beta1.query_grpc as query_grpc # for gprclib
import cosmospy_protobuf.cosmos.bank.v1beta1.query_pb2 as query_pb2host = "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)```
## 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. `grpclib`
3. `GitPython`
4. `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 --python_out=. --grpc_python_out=. --grpclib_python_out=.
```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=. and --grpclib_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`)Maintained by external contributors:
- Sentinel (branch: `chain/sentinel`, package name: `sentinel-protobuf`)