Skip to main content

The Python SDK for Terra Classic Data Analysis

Project description



py-sdk-logo

The Python SDK for Terra Classic Data Analysis

(Unfamiliar with Terra? Check out the Terra Docs)

GitHub Python pip

Explore the Docs »
PyPI Package · GitHub Repository

The Terra Classic Data Analysis Software Development Kit (SDK) not only possesses the functions of a basic SDK but also specifically enhances the on - chain historical data tracing and data analysis functions.

Features

  • Basic SDK: Inherit all the LCD query、Tx transaction from the basic SDK and maintain updates.

  • Data Analysis: Enhanced the on-chain data analysis function, providing aggregation interfaces for historical data tracing and display of pre - processed results.

  • BUG Fixed: Since validators have the greatest stake in the development of the Terra chain, they actively fix bugs and add features. Currently, the Binodes validator is the main maintainer.

Recent changes

0.1.5 (2025-05-16)

feat(core): add MsgUpdateContractAdmin and improve message handling

  • Add MsgUpdateContractAdmin class to support updating contract admin
  • Improve message parsing and handling for various modules
  • Add to_data() methods for proposal classes
  • Update init and parse_msg files to include new message type

0.1.4 (2025-05-09)

feat(gov): add support for v1 and v1beta1 gov messages

  • Add MsgSubmitProposal and MsgDeposit classes for v1 and v1beta1
  • Update LCD client to support both v1 and v1beta1 gov messages
  • Add parse_content support for AddBurnTaxExemptionAddressProposal

0.1.3.2

feat(sdk): add new messages and update existing ones

  • Add MsgVote_v1beta1 to gov module- Add MsgCancelUnbondingDelegation to staking module
  • Add MsgInstantiateContract2 to wasm module- Update MsgGrantAuthorization in authz module
  • Update AccessConfig in wasm/data.py

0.1.3.1

  • fix(authz): update MsgExecAuthorized to properly handle 'msgs' field- Change 'msgs' field handling in MsgExecAuthorized.from_data

0.1.3

  • Fixed the problem of incorrect automatic gas calculation when the Fee was not set for TX transactions in the basic SDK.
  • Fixed the issue in the basic SDK where there were no query results when querying the vote list.
  • Add default LCD and Chain ID.

Table of Contents


API Reference

An intricate reference to the APIs on the Terra SDK can be found here.


Getting Started

A walk-through of the steps to get started with the Terra SDK alongside a few use case examples are provided below. Alternatively, a tutorial video is also available here as reference.

Requirements

Terra Classic SDK requires Python v3.7+.

Installation

NOTE: All code starting with a $ is meant to run on your terminal (a bash prompt). All code starting with a >>> is meant to run in a python interpreter, like ipython.

Terra SDK can be installed (preferably in a virtual environment from PyPI using pip) as follows:

$ pip install -U terra-classic-data-analysis-sdk

You might need to run pip via python -m pip install -U terra-classic-data-analysis-sdk. Additionally, you might have pip3 installed instead of pip; proceed according to your own setup.

Usage Examples

One line of code to query the maximum block height on the current blockchain:

>>> from terra_classic_sdk.client.lcd import LCDClient

>>> LCDClient().tendermint.block_info()['block']['header']['height']

'1687543'

Notice:User-defined LCD and CHAIN are still supported, and the usage inherits from the underlying basic SDK capabilities.

Async Usage

If you want to make asynchronous, non-blocking LCD requests, you can use AsyncLCDClient. The interface is similar to LCDClient, except the module and wallet API functions must be awaited.

>>> import asyncio 
>>> from terra_classic_sdk.client.lcd import AsyncLCDClient

>>> async def main():
      terra = AsyncLCDClient()
      total_supply = await terra.bank.total()
      print(total_supply)
      await terra.session.close # you must close the session

>>> asyncio.get_event_loop().run_until_complete(main())

Building and Signing Transactions

If you wish to perform a state-changing operation on the Terra Classic blockchain such as sending tokens, swapping assets, withdrawing rewards, or even invoking functions on smart contracts, you must create a transaction and broadcast it to the network. Terra Classic SDK provides functions that help create StdTx objects.

Example Using a Wallet (recommended)

A Wallet allows you to create and sign a transaction in a single step by automatically fetching the latest information from the blockchain (chain ID, account number, sequence).

Use LCDClient.wallet() to create a Wallet from any Key instance. The Key provided should correspond to the account you intend to sign the transaction with.

NOTE: If you are using MacOS and got an exception 'bad key length' from MnemonicKey, please check your python implementation. if python3 -c "import ssl; print(ssl.OPENSSL_VERSION)" returns LibreSSL 2.8.3, you need to reinstall python via pyenv or homebrew.

>>> from terra_classic_sdk.client.lcd import LCDClient
>>> from terra_classic_sdk.key.mnemonic import MnemonicKey

# Fill in the mnemonic phrase of your wallet. A better practice is to set it as a system variable and read it.
>>> key = MnemonicKey(
    mnemonic="sport oppose usual cream task benefit canvas xxxxxxxxxxxxxxxxxx")

# Init wallet
>>> wallet = LCDClient().wallet(key=key)

Once you have your Wallet, you can simply create a StdTx using Wallet.create_and_sign_tx.

>>> from terra_classic_sdk.core.bank import MsgSend
>>> from terra_classic_sdk.client.lcd.api.tx import CreateTxOptions

>>>  tx = wallet.create_and_sign_tx(CreateTxOptions(
        msgs=[MsgSend(
            "terra1drs4gul908c59638gu9s88mugdnujdprjhtu7n", # Sender
            'terra1s2xpff7mj6jpxfyhr7pe25vt8puvgj4wyq8lz4', # Receiver
            "1000000uluna"  # send 1 lunc
        )],
        memo="test transaction!",
        gas_adjustment=1.2,  # Auto fee, can be increased during peak periods.
 
        # fee=Fee(240324,'7023928uluna'),  # Set the fees manually if you need
    ))

You should now be able to broadcast your transaction to the network.

>>> result = LCDClient().tx.broadcast(tx)
>>> print(result)

Dependencies

Terra Classic SDK uses Poetry to manage dependencies. To get set up with all the required dependencies, run:

$ pip install poetry
$ poetry install

Tests

Terra Classic SDK provides extensive tests for data classes and functions. To run them, after the steps in Dependencies:

$ make test

Code Quality

Terra Classic SDK uses Black, isort, and Mypy for checking code quality and maintaining style. To reformat, after the steps in Dependencies:

$ make qa && make format

Contributing

Community contribution, whether it's a new feature, correction, bug report, additional documentation, or any other feedback is always welcome. Please read through this section to ensure that your contribution is in the most suitable format for us to effectively process.


Reporting an Issue

First things first: Do NOT report security vulnerabilities in public issues! Please disclose responsibly by submitting your findings to the Terra Bugcrowd submission form. The issue will be assessed as soon as possible. If you encounter a different issue with the Python SDK, check first to see if there is an existing issue on the Issues page, or if there is a pull request on the Pull requests page. Be sure to check both the Open and Closed tabs addressing the issue.

If there isn't a discussion on the topic there, you can file an issue. The ideal report includes:

  • A description of the problem / suggestion.
  • How to recreate the bug.
  • If relevant, including the versions of your:
    • Python interpreter
    • Terra SDK
    • Optionally of the other dependencies involved
  • If possible, create a pull request with a (failing) test case demonstrating what's wrong. This makes the process for fixing bugs quicker & gets issues resolved sooner.

Requesting a Feature

If you wish to request the addition of a feature, please first check out the Issues page and the Pull requests page (both Open and Closed tabs). If you decide to continue with the request, think of the merits of the feature to convince the project's developers, and provide as much detail and context as possible in the form of filing an issue on the Issues page.


Contributing Code

If you wish to contribute to the repository in the form of patches, improvements, new features, etc., first scale the contribution. If it is a major development, like implementing a feature, it is recommended that you consult with the developers of the project before starting the development to avoid duplicating efforts. Once confirmed, you are welcome to submit your pull request.

For new contributors, here is a quick guide:

  1. Fork the repository.
  2. Build the project using the Dependencies and Tests steps.
  3. Install a virtualenv.
  4. Develop your code and test the changes using the Tests and Code Quality steps.
  5. Commit your changes (ideally follow the Angular commit message guidelines).
  6. Push your fork and submit a pull request to the repository's main branch to propose your code.

A good pull request:

  • Is clear and concise.
  • Works across all supported versions of Python. (3.7+)
  • Follows the existing style of the code base (Flake8).
  • Has comments included as needed.
  • Includes a test case that demonstrates the previous flaw that now passes with the included patch, or demonstrates the newly added feature.
  • Must include documentation for changing or adding any public APIs.
  • Must be appropriately licensed (MIT License).

Documentation Contributions

Documentation improvements are always welcome. The documentation files live in the docs directory of the repository and are written in reStructuredText and use Sphinx to create the full suite of documentation.
When contributing documentation, please do your best to follow the style of the documentation files. This means a soft limit of 88 characters wide in your text files and a semi-formal, yet friendly and approachable, prose style. You can propose your improvements by submitting a pull request as explained above.

Need more information on how to contribute?

You can give this guide read for more insight.


License

This software is licensed under the MIT license. See LICENSE for full disclosure.


 

Terra-logo

Powering the innovation of money.

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

terra_classic_data_analysis_sdk-0.1.5.tar.gz (106.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

terra_classic_data_analysis_sdk-0.1.5-py3-none-any.whl (153.6 kB view details)

Uploaded Python 3

File details

Details for the file terra_classic_data_analysis_sdk-0.1.5.tar.gz.

File metadata

File hashes

Hashes for terra_classic_data_analysis_sdk-0.1.5.tar.gz
Algorithm Hash digest
SHA256 9f399f19508ad5416d0dab09810979f480087893419ae25f78096b8da1cb24b4
MD5 c107e0fc8aa78eefcbe71a4e48de2ebb
BLAKE2b-256 945162eeaddbd766d2155d4c7ecd46ad9c74edece87e4fd973deb8e8c4000d63

See more details on using hashes here.

File details

Details for the file terra_classic_data_analysis_sdk-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for terra_classic_data_analysis_sdk-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0e911ab4bd48fa6772f993ff0b17a469678d4e9272d91990b4792b25589e786b
MD5 668b6170f94cdf391780cc866b28ce8f
BLAKE2b-256 578d09d576a599a44cba79bb72a14a7071e9ab8517d84750ef8d466b44a1eb7d

See more details on using hashes here.

Supported by

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