This package contains a compiled python version of all cosmos protobuf files with their dependencies
Project description
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.
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_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)
Build yourself
There are two scripts helping you to fork this repository to work with any cosmos based coin.
Addititional Requirements:
grpcio-tools
grpclib
GitPython
protoletariat
Steps:
- Create a config in
configs
and take a existing one as example - Run the
aggregate.py
file with your filename without.json
(Examplepython aggregate.py cosmos
) - Run the
compile.py
to compile all your files to protobuf - Build your package. You're done!
Protobuf compilation
The files are compiled using the grpc_tools.protoc
command from the 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=. --grpclib_python_out=. <absolute path to .proto file>
After compiling all the files with protoc you need to fix the imports by using 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
)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cosmospy_protobuf-0.4.0.tar.gz
.
File metadata
- Download URL: cosmospy_protobuf-0.4.0.tar.gz
- Upload date:
- Size: 21.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06a3fabb4983c34b083f7f141f7bf7434ede0fa726fafecb1921f3dec31233e7 |
|
MD5 | e1f085cf1871d301950ef4f30abda6ae |
|
BLAKE2b-256 | eeff52e0ca3d2990e55fa9f28bc95005a040480bd3e2ac8519712532ca0672db |
File details
Details for the file cosmospy_protobuf-0.4.0-py2.py3-none-any.whl
.
File metadata
- Download URL: cosmospy_protobuf-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 608.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f08f6461604cf858f2eefc9592b3d911e8db3c11115015615cada99c8f78066 |
|
MD5 | 4edb434eeac13fbaef9308c4f1ec4859 |
|
BLAKE2b-256 | 95667fffcc56f3cc220fb69fc220176f0eca6b5aea6881f244906e575f045de8 |