pyband


Namepyband JSON
Version 0.3.5 PyPI version JSON
download
home_pagehttps://bandprotocol.com/
SummaryPython library for BandChain
upload_time2023-03-24 03:31:40
maintainer
docs_urlNone
authorBand Protocol
requires_python>=3.7,<4.0
licenseMIT
keywords band blockchain oracle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
    <h2>PyBand</h2>
    <blockquote>BandChain Python Library</blockquote>
</div>

Pyband is a library that is used to interact with BandChain through the `gRPC` protocol. Querying data and sending
transaction can be done here!

## ⭐️ Features

This helper library allows users to interact with BandChain.

PyBand supports the following features:

- Getting the information of a specific oracle script, data source, and request ID.
- Getting the account information of specific address.
- Getting the latest request for a specific oracle script with its matching calldata and validator ask_count and
  min_count.
- Querying all the reporters associated with a specific validator.
- Seeing what client_id you are using and getting BandChain's latest block data.
- Able to send transaction in 3 modes: block mode, async mode, and sync mode.

## 📦 Installation

This library is available on [PyPI](https://pypi.org/project/pyband/)

```bash
pip install pyband
```

## 💎 Example Usage

The example below shows how this library can be used to get the result of the latest request for the price of any
cryptocurrency. In this example, we will get the latest price of BTC on BandChain's testnet.

The specified parameters are:

- `oracleScriptID`: 111
- `calldata`: The hex string representing the [OBI](<https://github.com/bandprotocol/bandchain/wiki/Oracle-Binary-Encoding-(OBI)>)-encoded value of `{'symbols': ['BTC'], 'multiplier': 100000000}`
- `minCount`: 10
- `askCount`: 16

```python
import asyncio

from pyband import Client, PyObi


async def main():
    grpc_url = "laozi-testnet6.bandchain.org"
    c = Client.from_endpoint(grpc_url, 443)

    oid = 111
    calldata = "00000001000000034254430000000005f5e100"
    min_count = 10
    ask_count = 16

    req_info = await c.get_latest_request(oid, calldata, min_count, ask_count)
    oracle_script = await c.get_oracle_script(oid)
    obi = PyObi(oracle_script.schema)

    # Converts the calldata into a readable syntax
    print(obi.decode_input(bytes.fromhex(calldata)))

    # Prints the result
    print(obi.decode_output(req_info.request.result.result))


if __name__ == "__main__":
    asyncio.run(main())
```

Below is the results of the example above.

```
{'symbols': ['BTC'], 'multiplier': 100000000}
{'rates': [1936488410000]}
```

This example shows how to send a transaction on BandChain using block mode.

```python
import asyncio
import os

from pyband import Client, Transaction, Wallet
from pyband.messages.cosmos.bank.v1beta1 import MsgSend
from pyband.proto.cosmos.base.v1beta1 import Coin


async def main():
    # Create a GRPC connection
    grpc_url = "laozi-testnet6.bandchain.org"
    c = Client.from_endpoint(grpc_url, 443)

    # Convert a mnemonic to a wallet
    wallet = Wallet.from_mnemonic(os.getenv("MNEMONIC"))
    sender = wallet.get_address().to_acc_bech32()

    # Prepare a transaction's properties
    msg_send = MsgSend(
        from_address=sender,
        to_address="band19ajhdg6maw0ja0a7qd9sq7nm4ym9f4wjg8r96w",
        amount=[Coin(amount="1000000", denom="uband")],
    )

    account = await c.get_account(sender)
    account_num = account.account_number
    sequence = account.sequence

    fee = [Coin(amount="50000", denom="uband")]
    chain_id = await c.get_chain_id()

    # Step 4 Construct a transaction
    txn = (
        Transaction()
        .with_messages(msg_send)
        .with_sequence(sequence)
        .with_account_num(account_num)
        .with_chain_id(chain_id)
        .with_gas(2000000)
        .with_fee(fee)
        .with_memo("")
    )

    # Sign and broadcast a transaction
    tx_block = await c.send_tx_block_mode(wallet.sign_and_build(txn))

    # Converting to JSON for readability
    print(tx_block.to_json(indent=4))


if __name__ == "__main__":
    asyncio.run(main())
```

## 🧀 Notes

For more examples, please go to [`examples`](/examples/request_data_example.py).

            

Raw data

            {
    "_id": null,
    "home_page": "https://bandprotocol.com/",
    "name": "pyband",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "BAND,BLOCKCHAIN,ORACLE",
    "author": "Band Protocol",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/1e/54/b366fd23c49dd6f75ab3cfbd64ee6a5b5fa9c6e9ef5c8d025f73e16e935b/pyband-0.3.5.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n    <h2>PyBand</h2>\n    <blockquote>BandChain Python Library</blockquote>\n</div>\n\nPyband is a library that is used to interact with BandChain through the `gRPC` protocol. Querying data and sending\ntransaction can be done here!\n\n## \u2b50\ufe0f Features\n\nThis helper library allows users to interact with BandChain.\n\nPyBand supports the following features:\n\n- Getting the information of a specific oracle script, data source, and request ID.\n- Getting the account information of specific address.\n- Getting the latest request for a specific oracle script with its matching calldata and validator ask_count and\n  min_count.\n- Querying all the reporters associated with a specific validator.\n- Seeing what client_id you are using and getting BandChain's latest block data.\n- Able to send transaction in 3 modes: block mode, async mode, and sync mode.\n\n## \ud83d\udce6 Installation\n\nThis library is available on [PyPI](https://pypi.org/project/pyband/)\n\n```bash\npip install pyband\n```\n\n## \ud83d\udc8e Example Usage\n\nThe example below shows how this library can be used to get the result of the latest request for the price of any\ncryptocurrency. In this example, we will get the latest price of BTC on BandChain's testnet.\n\nThe specified parameters are:\n\n- `oracleScriptID`: 111\n- `calldata`: The hex string representing the [OBI](<https://github.com/bandprotocol/bandchain/wiki/Oracle-Binary-Encoding-(OBI)>)-encoded value of `{'symbols': ['BTC'], 'multiplier': 100000000}`\n- `minCount`: 10\n- `askCount`: 16\n\n```python\nimport asyncio\n\nfrom pyband import Client, PyObi\n\n\nasync def main():\n    grpc_url = \"laozi-testnet6.bandchain.org\"\n    c = Client.from_endpoint(grpc_url, 443)\n\n    oid = 111\n    calldata = \"00000001000000034254430000000005f5e100\"\n    min_count = 10\n    ask_count = 16\n\n    req_info = await c.get_latest_request(oid, calldata, min_count, ask_count)\n    oracle_script = await c.get_oracle_script(oid)\n    obi = PyObi(oracle_script.schema)\n\n    # Converts the calldata into a readable syntax\n    print(obi.decode_input(bytes.fromhex(calldata)))\n\n    # Prints the result\n    print(obi.decode_output(req_info.request.result.result))\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\nBelow is the results of the example above.\n\n```\n{'symbols': ['BTC'], 'multiplier': 100000000}\n{'rates': [1936488410000]}\n```\n\nThis example shows how to send a transaction on BandChain using block mode.\n\n```python\nimport asyncio\nimport os\n\nfrom pyband import Client, Transaction, Wallet\nfrom pyband.messages.cosmos.bank.v1beta1 import MsgSend\nfrom pyband.proto.cosmos.base.v1beta1 import Coin\n\n\nasync def main():\n    # Create a GRPC connection\n    grpc_url = \"laozi-testnet6.bandchain.org\"\n    c = Client.from_endpoint(grpc_url, 443)\n\n    # Convert a mnemonic to a wallet\n    wallet = Wallet.from_mnemonic(os.getenv(\"MNEMONIC\"))\n    sender = wallet.get_address().to_acc_bech32()\n\n    # Prepare a transaction's properties\n    msg_send = MsgSend(\n        from_address=sender,\n        to_address=\"band19ajhdg6maw0ja0a7qd9sq7nm4ym9f4wjg8r96w\",\n        amount=[Coin(amount=\"1000000\", denom=\"uband\")],\n    )\n\n    account = await c.get_account(sender)\n    account_num = account.account_number\n    sequence = account.sequence\n\n    fee = [Coin(amount=\"50000\", denom=\"uband\")]\n    chain_id = await c.get_chain_id()\n\n    # Step 4 Construct a transaction\n    txn = (\n        Transaction()\n        .with_messages(msg_send)\n        .with_sequence(sequence)\n        .with_account_num(account_num)\n        .with_chain_id(chain_id)\n        .with_gas(2000000)\n        .with_fee(fee)\n        .with_memo(\"\")\n    )\n\n    # Sign and broadcast a transaction\n    tx_block = await c.send_tx_block_mode(wallet.sign_and_build(txn))\n\n    # Converting to JSON for readability\n    print(tx_block.to_json(indent=4))\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## \ud83e\uddc0 Notes\n\nFor more examples, please go to [`examples`](/examples/request_data_example.py).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library for BandChain",
    "version": "0.3.5",
    "project_urls": {
        "Documentation": "https://docs.bandchain.org/client-library/pyband/getting-started.html",
        "Homepage": "https://bandprotocol.com/",
        "Repository": "https://github.com/bandprotocol/pyband"
    },
    "split_keywords": [
        "band",
        "blockchain",
        "oracle"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f6391bdbb0f24ea3754373538e4c860123cce7e1891f5fb85c34654f9b4f0d5",
                "md5": "1c21393e617d00c5ae9d36b826365194",
                "sha256": "23317aa3f762f5c6c2b7ebfbd2a5fe769b6b1729cbde073548e45cb44dd0ab55"
            },
            "downloads": -1,
            "filename": "pyband-0.3.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1c21393e617d00c5ae9d36b826365194",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 119740,
            "upload_time": "2023-03-24T03:31:39",
            "upload_time_iso_8601": "2023-03-24T03:31:39.024814Z",
            "url": "https://files.pythonhosted.org/packages/0f/63/91bdbb0f24ea3754373538e4c860123cce7e1891f5fb85c34654f9b4f0d5/pyband-0.3.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1e54b366fd23c49dd6f75ab3cfbd64ee6a5b5fa9c6e9ef5c8d025f73e16e935b",
                "md5": "ac66cc18d1e516014318eac86bb339d2",
                "sha256": "f8d0d7c25e7b8d0b06306953e7e641042807eb6e78edb4af7b5dd0cd667b4561"
            },
            "downloads": -1,
            "filename": "pyband-0.3.5.tar.gz",
            "has_sig": false,
            "md5_digest": "ac66cc18d1e516014318eac86bb339d2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 85970,
            "upload_time": "2023-03-24T03:31:40",
            "upload_time_iso_8601": "2023-03-24T03:31:40.930665Z",
            "url": "https://files.pythonhosted.org/packages/1e/54/b366fd23c49dd6f75ab3cfbd64ee6a5b5fa9c6e9ef5c8d025f73e16e935b/pyband-0.3.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-24 03:31:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bandprotocol",
    "github_project": "pyband",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyband"
}
        
Elapsed time: 0.15211s