A library for interacting with the cosmos networks
Project description
CosmPy
A python library for interacting with cosmos based blockchain networks
Installing
To install the project use:
pip3 install cosmpy
Getting started
Below is a simple example for querying an account's balance and sending funds from one account to another using RestClient
:
from cosmpy.clients.signing_cosmwasm_client import SigningCosmWasmClient
from cosmpy.common.rest_client import RestClient
from cosmpy.crypto.address import Address
from cosmpy.crypto.keypairs import PrivateKey
from cosmpy.protos.cosmos.base.v1beta1.coin_pb2 import Coin
# Data
rest_endpoint_address = "http://the_rest_endpoint"
alice_private_key = PrivateKey(bytes.fromhex("<private_key_in_hex_format>"))
chain_id = "some_chain_id"
denom = "some_denomination"
bob_address = Address("some_address")
channel = RestClient(rest_endpoint_addres)
client = SigningCosmWasmClient(private_key, channel, chain_id)
# Query Alice's Balance
res = client.get_balance(client.address, denom)
print(f"Alice's Balance: {res.balance.amount} {res.balance.denom}")
# Send 1 <denom> from Alice to Bob
client.send_tokens(bob_address, [Coin(amount="1", denom=denom)])
Documentation
To see the documentation, first run:
make generate-docs
Then (if on Linux or MacOS):
make open-docs
And if on windows, open docs/build/html/index.html
.
Examples
Under the examples
directory, you can find examples of basic ledger interactions with cosmpy
using both REST and gRPC, e.g. querying, sending a transaction, interacting with a smart contract, and performing atomic swaps. To run any example <example_file_name>
:
python ./examples/<example_file_name>.py
Extra Resources
Project details
Release history Release notifications | RSS feed
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 cosmpy-0.2.0rc1.tar.gz
.
File metadata
- Download URL: cosmpy-0.2.0rc1.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b80f63aa9aed654ba4a79ac8c7b5147389a1f1c8fbe2e0fc88e242cb2f98679 |
|
MD5 | f8e71b0919b3bafe80808f48485785ea |
|
BLAKE2b-256 | acdfe464792fa1ae3d4b7e30f6c9e7ed4aefa3b0ee986ecf41f571e448c86c13 |
File details
Details for the file cosmpy-0.2.0rc1-py3-none-any.whl
.
File metadata
- Download URL: cosmpy-0.2.0rc1-py3-none-any.whl
- Upload date:
- Size: 398.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76bf7daef6a1984357ad99fbc3a8b8da2c90f327d298117f34b2df6a60ef83f3 |
|
MD5 | 0c8c78f2305111d76fee6ca39840b371 |
|
BLAKE2b-256 | 27e12667202659a8e1d6c02ec867287072e437e762501c148b01e0cabaee33bd |