Skip to main content

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 osmosis_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:

  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 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)

Metadata

Release files for osmosis-protobuf 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osmosis-protobuf 0.3.0
File Size Uploaded
osmosis_protobuf-0.3.0.tar.gz 21.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for osmosis-protobuf 0.3.0
File Interpreter ABI Platform
osmosis_protobuf-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 23.0 MB

Release files / osmosis_protobuf-0.3.0.tar.gz

Download URL osmosis_protobuf-0.3.0.tar.gz
Size 21.8 MB
Tags Source
SHA-256 checksum
How to use checksums
d1066ee10ddf1661befee203bb3c277526ba34d813a3a0501d2e3a1e9f2a6d4e
BLAKE2b-256 checksum
How to use checksums
841cefa73ef03bb567dc66a53c0da5673c7c2e4e62141d8c845e0de8aa827527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / osmosis_protobuf-0.3.0-py2.py3-none-any.whl

Download URL osmosis_protobuf-0.3.0-py2.py3-none-any.whl
Size 1.2 MB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3ef4b41192f6dec4f66381ffee07f1bf6254d11a9ca286e2a4a3eb8c061fddbf
BLAKE2b-256 checksum
How to use checksums
c7b494414ddfc3d4bff0d6241dc9d5e6b1edbb307e314d473ab09b72a3c6cea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

0.4.0

2 release files

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page