Skip to main content

A library for interacting with the cosmos networks

Project description

CosmPy

PyPI PyPI - Python Version PyPI - Wheel License

AEA framework sanity checks and tests flake8 mypy Black mypy

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmpy-0.2.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

cosmpy-0.2.0-py3-none-any.whl (398.7 kB view details)

Uploaded Python 3

File details

Details for the file cosmpy-0.2.0.tar.gz.

File metadata

  • Download URL: cosmpy-0.2.0.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

Hashes for cosmpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1fd08bfc2538f1d77376665901ea5678d8406d1f8cf8c508f81dab4efabba4ec
MD5 269de7235ad22d7a9d226dfbee27a7ba
BLAKE2b-256 a8908a6139f8207d0f0deedc76f371d19312e818dad99c4302318d9932d69bfd

See more details on using hashes here.

File details

Details for the file cosmpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cosmpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 398.7 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

Hashes for cosmpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bb24f9f5bc0fd279c42162e81569d44bb88928a67bfeff93e3413cfea4b5c95
MD5 4a9d5541676247dd54aff3190b1f66cd
BLAKE2b-256 91dcc15f85d9684b836ed932082d6711ab48aa487b97d54f31bfe364eb26ac50

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page