{"id":13566047,"url":"https://github.com/secretanalytics/secret-sdk-python","last_synced_at":"2025-04-03T23:31:02.336Z","repository":{"id":44410006,"uuid":"365509094","full_name":"secretanalytics/secret-sdk-python","owner":"secretanalytics","description":"Python library to interact with Secret Network on Cosmos","archived":false,"fork":false,"pushed_at":"2025-03-13T14:45:21.000Z","size":3198,"stargazers_count":39,"open_issues_count":9,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-13T15:36:01.457Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/secretanalytics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-08T12:29:45.000Z","updated_at":"2025-03-13T14:45:26.000Z","dependencies_parsed_at":"2024-11-16T01:36:00.281Z","dependency_job_id":null,"html_url":"https://github.com/secretanalytics/secret-sdk-python","commit_stats":{"total_commits":277,"total_committers":17,"mean_commits":"16.294117647058822","dds":0.6173285198555957,"last_synced_commit":"0af824e3e2ec787e837dfee0052ab44f0329a42e"},"previous_names":["stephanegg/secret-sdk-python"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretanalytics%2Fsecret-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretanalytics%2Fsecret-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretanalytics%2Fsecret-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretanalytics%2Fsecret-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secretanalytics","download_url":"https://codeload.github.com/secretanalytics/secret-sdk-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247097662,"owners_count":20883122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:02:00.853Z","updated_at":"2025-04-03T23:31:02.331Z","avatar_url":"https://github.com/secretanalytics.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# \u003cdiv  align=\"center\"\u003e \u003cp \u003e Python SDK for Secret Network \u003c/p\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\nThe Secret Software Development Kit (SDK) in Python is a simple library toolkit for building software that can interact with the Secret blockchain and provides simple abstractions over core data structures, serialization, key management, and API request generation. The SDK is based on a fork of \u003ca href=\"https://github.com/terra-money/terra.py\"\u003eterra.py\u003c/a\u003e on Terra\n\n## Features\n\n- Written in Python offering extensive support libraries\n- Versatile support for key management solutions\n- Exposes the Secret Rest API through LCDClient\n\n\u003cbr/\u003e\n\n# Table of Contents\n\n- [API Reference](#api-reference)\n- [Getting Started](#getting-started)\n  - [Requirements](#requirements)\n  - [Installation](#installation)\n  - [Dependencies](#dependencies)\n  - [Tests](#tests)\n  - [Code Quality](#code-quality)\n- [Usage Examples](#usage-examples)\n  - [Getting Blockchain Information](#getting-blockchain-information)\n    - [Async Usage](#async-usage)\n  - [Building and Signing Transactions](#building-and-signing-transactions)\n    - [Example Using a Wallet](#example-using-a-wallet-recommended)\n- [Contributing](#contributing)\n  - [Reporting an Issue](#reporting-an-issue)\n  - [Requesting a Feature](#requesting-a-feature)\n  - [Contributing Code](#contributing-code)\n  - [Documentation Contributions](#documentation-contributions)\n- [License](#license)\n\n\u003cbr/\u003e\n\n# API Reference\n\nAn intricate reference to the APIs on the Secret SDK can be found \u003ca href=\"https://api.scrt.network/swagger/\"\u003ehere\u003c/a\u003e.\n\n\u003cbr/\u003e\n\n# Getting Started\n\nA walk-through of the steps to get started with the Secret SDK alongside with a few use case examples are provided below.\n\n## Requirements\n\nSecret SDK requires \u003ca href=\"https://www.python.org/downloads/\"\u003ePython v3.7+\u003c/a\u003e.\n\n## Installation\n\n\u003csub\u003e**NOTE:** _All code starting with a `$` is meant to run on your terminal (a bash prompt). All code starting with a `\u003e\u003e\u003e` is meant to run in a python interpreter, like \u003ca href=\"https://pypi.org/project/ipython/\"\u003eipython\u003c/a\u003e._\u003c/sub\u003e\n\nSecret SDK can be installed (preferably in a `virtual environment` from PyPI using `pip`) as follows:\n\n```\n$ pip install -U secret-sdk\n```\n\n\u003csub\u003e_You might have `pip3` installed instead of `pip`; proceed according to your own setup._\u003csub\u003e\n\n## Dependencies\n\nSecret SDK uses \u003ca href=\"https://python-poetry.org/\"\u003ePoetry\u003c/a\u003e to manage dependencies. To get set up with all the required dependencies, run:\n\n```\n$ pip install poetry\n$ poetry install\n```\n\n## Tests\n\nSecret SDK provides extensive tests for data classes and functions. To run them, after the steps in [Dependencies](#dependencies):\n\n```\n$ make test\n```\n\n\u003cbr/\u003e\n\n# Usage Examples\n\nSecret SDK can help you read block data, query secret contracts, sign and send transactions, and many more.\nFollowing examples are provided to help get building started.\n\nIn order to interact with the Secret blockchain, you'll need a connection to a Secret node or an api. This can be done through setting up an LCDClient (The LCDClient is an object representing an HTTP connection to a Secret LCD node.):\n\n```\nfrom secret_sdk.client.lcd import LCDClient\nsecret = LCDClient(chain_id=\"secret-4\", url=node_rest_endpoint)\n```\n\n## Getting Blockchain Information\n\nOnce properly configured, the `LCDClient` instance will allow you to interact with the Secret blockchain. Try getting the latest block height:\n\n```\nsecret.tendermint.block_info()['block']['header']['height']\n```\n\n`'1687543'`\n\n### Async Usage\n\nIf 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.\n\n\u003cpre\u003e\u003ccode\u003e\nimport asyncio \nfrom secret_sdk.client.lcd import AsyncLCDClient\n\nasync def main():\n        \u003cstrong\u003easync with AsyncLCDClient(url=node_rest_endpoint, chain_id=\"secret-4\") as secret:\u003c/strong\u003e\n            community_pool = await secret.distribution.community_pool()\n            print(community_pool)\n            \u003cstrong\u003eawait secret.session.close()  # you must close the session\u003c/strong\u003e\n\nasyncio.get_event_loop().run_until_complete(main())\n\u003c/code\u003e\u003c/pre\u003e\n\nYou can improve the efficiency of consecutive queries by making them asynchronous.\n\n\u003cpre\u003e\u003ccode\u003e\nimport asyncio\nimport uvloop\n\nfrom secret_sdk.client.lcd import AsyncLCDClient\nfrom secret_sdk.exceptions import LCDResponseError\n\ndef owner_of(token_id):\n        return {\n                \"owner_of\": {\n                    \"token_id\": token_id,\n                }\n            }\n\nasync def query_owner(secret, contract_address, token_id, query):\n        try:\n            msg = await secret.wasm.contract_query(contract_address, query)\n            return (token_id, msg[\"owner_of\"][\"owner\"])\n        except LCDResponseError:\n            return (token_id, \"\")\n\nasync def query_collection(contract_address, token_ids):\n        \u003cstrong\u003easync with AsyncLCDClient(chain_id=\"secret-4\", url=node_rest_endpoint) as secret: \u003c/strong\u003e\n            requests = [query_owner(secret, contract_address, token, owner_of(token)) for token in token_ids]\n            \u003cstrong\u003eowners = await asyncio.gather(*requests, return_exceptions=True)\u003c/strong\u003e\n            print(owners)\n            \u003cstrong\u003eawait secret.session.close() # you must close the session \u003c/strong\u003e\n\nuvloop.install()\nif __name__ == '__main__':\n        asyncio.run(query_collection(contract_address, token_ids))\n\u003c/code\u003e\u003c/pre\u003e\n\n## Building and Signing Transactions\n\nIf you wish to perform a state-changing operation on the Secret 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.\nSecret SDK provides functions that help create StdTx objects.\n\n### Example Using a Wallet (_recommended_)\n\nA `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).\n\nUse `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.\n\n```\nfrom secret_sdk.client.lcd import LCDClient\nfrom secret_sdk.key.mnemonic import MnemonicKey\n\nmk = MnemonicKey(mnemonic=MNEMONIC)\nsecret = LCDClient(node_rest_endpoint, \"secret-4\")\nwallet = secret.wallet(mk)\n```\n\nOnce you have your Wallet, you can create and broadcast tx with `wallet.create_and_broadcast_tx` method .\n\n```\nfrom secret_sdk.core import StdFee\nfrom secret_sdk.core.bank import MsgSend\n\nsend_msg = MsgSend(\n    wallet.key.acc_address,\n    RECIPIENT,\n    \"1000000uscrt\"    # send 1 scrt\n)\nresult = wallet.create_and_broadcast_tx(\n    msg_list=[send_msg],\n    memo=\"\",\n    gas=200000,\n)\nprint(result)\n```\n\nOr use the abstraction `wallet.send_tokens` (see `wallet.execute_tx` to execute a smart contract with `handle_msg`).\n\n```\ntx = wallet.send_tokens(recipient_addr=RECIPIENT, transfer_amount=\"1000000uscrt\")\n```\n\n### Batch Transactions\n\nYou can combine muliple state-changing transactions for the same contract into a single transaction. The contract used here is from the [Counter contract example](https://docs.scrt.network/secret-network-documentation/development/intro-to-secret-contracts)\n\n```\nmsg = {\n  'increment': {}\n}\n\nmsg_list = [msg for _ in range(10)]\n\ntx = wallet.execute_tx(\n  CONTRACT_ADDR,\n  msg_list,\n  memo=\"My first batch transaction!\",\n)\n```\n\n\u003cbr/\u003e\n\n# Contributing\n\nCommunity 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.\n\n\u003cbr/\u003e\n\n## Reporting an Issue\n\nFirst things first: **Do NOT report security vulnerabilities in public issues!** Please disclose responsibly by letting the Secret SDK team know upfront (discord , telegram). We will assess the issue as soon as possible on a best-effort basis and will give you an estimate for when we have a fix and release available for an eventual public disclosure. \u003c/br\u003e\nIf you encounter a different issue with the Python SDK, check first to see if there is an existing issue on the Issues page or a pull request on the Pull request page (both Open and Closed tabs) addressing the topic.\n\nIf there isn't a discussion on the topic there, you can file an issue. The ideal report includes:\n\n- A description of the problem / suggestion.\n- How to recreate the bug.\n- If relevant, including the versions of your:\n  - Python interpreter\n  - Secret SDK\n  - Optionally of the other dependencies involved\n- If possible, create a pull request with a (failing) test case demonstrating what's wrong. This makes the process for fixing bugs quicker \u0026 gets issues resolved sooner.\n  \u003c/br\u003e\n\n## Requesting a Feature\n\nIf you wish to request the addition of a feature, please first checkout 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.\n\n\u003cbr/\u003e\n\n## Contributing Code\n\nIf 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 in order not to risk spending a lot of time working on a change that might not get merged into the project. Once confirmed, you are welcome to submit your pull request.\n\u003c/br\u003e\n\n### For new contributors, here is a quick guide:\n\n1. Fork the repository.\n2. Build the project using the [Dependencies](#dependencies) and [Tests](#tests) steps.\n3. Install a \u003ca href=\"https://virtualenv.pypa.io/en/latest/index.html\"\u003evirtualenv\u003c/a\u003e.\n4. Develop your code and test the changes using the [Tests](#tests) and [Code Quality](#code-quality) steps.\n5. Commit your changes\n6. Push your fork and submit a pull request to the repository's `main` branch to propose your code.\n\nA good pull request:\n\n- is clear.\n- works across all supported versions of Python. (3.7+)\n- Follows the existing style of the code base (\u003ca href=\"https://pypi.org/project/flake8/\"\u003e`Flake8`\u003c/a\u003e).\n- Has comments included as needed.\n- A test case that demonstrates the previous flaw that now passes with the included patch, or demonstrates the newly added feature.\n- If it adds / changes a public API, it must also include documentation for those changes.\n- Must be appropriately licensed (MIT License).\n  \u003c/br\u003e\n\n## Documentation Contributions\n\nDocumentation improvements are always welcome. The documentation files live in the [docs](./docs) directory of the repository and are written in \u003ca href=\"https://docutils.sourceforge.io/rst.html\"\u003ereStructuredText\u003c/a\u003e and use \u003ca href=\"https://www.sphinx-doc.org/en/master/\"\u003eSphinx\u003c/a\u003e to create the full suite of documentation.\n\u003c/br\u003e\nWhen 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 imporvements by submiting a pull request as explained above.\n\n### Need more information on how to contribute?\n\nYou can give this \u003ca href=\"https://opensource.guide/how-to-contribute/#how-to-submit-a-contribution\"\u003eguide\u003c/a\u003e read for more insight.\n\n\u003cbr/\u003e\n\n# License\n\nThis software is licensed under the MIT license. See [LICENSE](./LICENSE) for full disclosure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecretanalytics%2Fsecret-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecretanalytics%2Fsecret-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecretanalytics%2Fsecret-sdk-python/lists"}