## KomoDeFi Framework wrapper for Python
[**pykomodefi**](https://pypi.org/project/pykomodefi/) is a simple wrapper around [Komodo Platform's](https://komodoplatform.com/en/) [DeFi Framework](https://github.com/KomodoPlatform/komodo-defi-framework).
### Installation
`pip install pykomodefi`
### Usage
**Configuration:**
The configuration file can be passed as a parameter to the `KomoDeFi_API` class constructor:
```
>>> import pykomodefi
>>> dexapi = pykomodefi.KomoDeFi_API(config="/path/to/MM2.json")
```
If not set, the default configuration file path is `MM2.json` in the current folder, or `~/.kdf/MM2.json`.
It can be set to a different file later:
```
>>> import pykomodefi
>>> dexapi = pykomodefi.KomoDeFi_API()
>>> dexapi.set_config = "/path/to/MM2.json"
```
**Simple RPC call:**
```
>>> resp = dexapi.rpc("get_enabled_coins")
>>> resp
{
'result': [
{
'ticker': 'KMD',
'address': 'RMC1cWXngQf2117apEKoLh3x27NoG88yzd'
},
{
'ticker': 'LTC',
'address': 'LQyzwFtf8HU7VYQMhop5bv857uMao4jnKX'
}
]
}
```
**RPC call with parameters:**
```
>>> params = {"coin": "KMD"}
>>> resp = dexapi.rpc("my_balance", params)
>>> resp
{
'coin': 'KMD',
'balance': '20',
'unspendable_balance': '0',
'address': 'RMC1cWXngQf2117apEKoLh3x27NoG88yzd'
}
```
**v2 RPC call:**
```
>>> resp = dexapi.rpc("get_public_key", v2=True)
>>> resp
{
'mmrpc': '2.0',
'result': {
'public_key': '0371792f7a6846a0da28f3422501927ae103355c02750bc4c4d8430375329a09ac'
},
'id': None
}
```
The following methods are available as properties of the `KomoDeFi_API` class. These methods do not require any input parameters:
```
>>> dexapi.version
'1.0.7-beta_afe2e08'
>>> dexapi.pubkey
'0366d28a7926fb20287132692c4cef7bc7e00e76da064948676f8549c0ed7114d3'
>>> dexapi.pubkey_hash
'05aab5342166f8594baf17a7d9bef5d567443327'
>>> dexapi.peer_id
'12D3KooWS9MeuFZhJCfQTntwbTVnXMAJpz9Tvd1XYFuURrGqnJVR'
>>> dexapi.peers_info
{
"12D3KooWM8BrDBXc1TVw2vswoqYcQVn7fFvpAvcCfaV2Uqg2L9jU":["/ip4/89.248.168.39/tcp/38890"],
"12D3KooWJ3dEWK7ym1uwc5SmwbmfFSRmELrA9aPJYxFRrQCCNdwF":["/ip4/188.124.46.112/tcp/38890/p2p/12D3KooWJ3dEWK7ym1uwc5SmwbmfFSRmELrA9aPJYxFRrQCCNdwF"],
"12D3KooWL6yrrNACb7t7RPyTEPxKmq8jtrcbkcNd6H5G2hK7bXaL":["/ip4/168.119.236.233/tcp/38890/p2p/12D3KooWL6yrrNACb7t7RPyTEPxKmq8jtrcbkcNd6H5G2hK7bXaL"],
"12D3KooWPR2RoPi19vQtLugjCdvVmCcGLP2iXAzbDfP3tp81ZL4d":["/ip4/168.119.237.13/tcp/38890/p2p/12D3KooWPR2RoPi19vQtLugjCdvVmCcGLP2iXAzbDfP3tp81ZL4d"],
"12D3KooWKxavLCJVrQ5Gk1kd9m6cohctGQBmiKPS9XQFoXEoyGmS":["/ip4/168.119.236.249/tcp/38890/p2p/12D3KooWKxavLCJVrQ5Gk1kd9m6cohctGQBmiKPS9XQFoXEoyGmS"],
"12D3KooWDbBdifGp3viDR4dCECEFKepjhwhd2YwAqgNVdXpEeewu":["/ip4/80.82.76.214/tcp/38890"],
"12D3KooWJDoV9vJdy6PnzwVETZ3fWGMhV41VhSbocR1h2geFqq9Y":["/ip4/89.248.173.231/tcp/38890"]
}
>>> dexapi.orders
{
"maker_orders": {
....
},
"taker_orders": {
....
}
}
>>> dexapi.active_swaps
{
"uuids": [
"015c13bc-da79-43e1-a6d4-4ac8b3099b34",
"7592a07a-2805-4050-8ab8-984480e812f0",
"82cbad96-ea9f-40fb-9225-07496323e35d",
"177f7fa5-c9f3-4673-a2fa-28451a123e61"
]
}
>>> dexapi.enabled_coins
[
{
"address": "1WxswvLF2HdaDr4k77e92VjaXuPQA8Uji",
"ticker": "BTC"
},
{
"address": "R9o9xTocqr6CeEDGDH6mEYpwLoMz6jNjMW",
"ticker": "KMD"
},
{
"address": "R9o9xTocqr6CeEDGDH6mEYpwLoMz6jNjMW",
"ticker": "VRSC"
},
{
"address": "0xbAB36286672fbdc7B250804bf6D14Be0dF69fa29",
"ticker": "ETH"
}
]
>>> dexapi.enabled_coins_v2
[
"MARTY",
"AAVE-PLG20",
"DOGE"
]
```
For documentation about available methods and parameters, refer to: <https://developers.komodoplatform.com/basic-docs/atomicdex/introduction-to-atomicdex.html>
Some configuration params from within `MM2.json` are also available as properties:
```
>>> dexapi.netid
8762
>>> dexapi.rpcip
127.0.0.1
>>> dexapi.rpcport
7783
>>> dexapi.db_dir
/path/to/DB
```
### Building locally
- Run `poetry build`
- Run `pipx install --spec $(pwd)/dist/pykomodefi-0.2.6.tar.gz pykomodefi --include-deps --force` (change version number accordingly)
### Running tests
**Prerequisites:**
- Install dependencies: `poetry install`
- Set up test configuration by either:
- Creating `tests/.env` file with: `MM2_JSON_PATH=tests/MM2.json`
- OR copying test config to project root: `cp tests/MM2.json .`
**Run tests:**
```bash
# Run all tests with coverage
poetry run pytest tests/ -v
# Run tests with verbose output
poetry run pytest tests/ -vv
# Run with coverage report
poetry run pytest tests/ --cov=pykomodefi --cov-report=html
```
**Note:** Tests will show connection errors if the KomoDeFi Framework (MM2) is not running. This is expected behavior - the package correctly handles and reports connection failures. To run tests against a live MM2 instance, ensure MM2 is running on `127.0.0.1:7783` before running the tests.
Raw data
{
"_id": null,
"home_page": "https://github.com/smk762/pykomodefi",
"name": "pykomodefi",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": "dex, crypto, komodo, defi, api, trading, atomic swaps",
"author": "smk",
"author_email": "smk@komodoplatform.com",
"download_url": "https://files.pythonhosted.org/packages/49/32/555b12a650f27a5ea9e445fffeb8abaab21955235a1f7ff4620d219bf370/pykomodefi-0.2.6.tar.gz",
"platform": null,
"description": "\n## KomoDeFi Framework wrapper for Python\n\n[**pykomodefi**](https://pypi.org/project/pykomodefi/) is a simple wrapper around [Komodo Platform's](https://komodoplatform.com/en/) [DeFi Framework](https://github.com/KomodoPlatform/komodo-defi-framework).\n\n\n### Installation\n\n`pip install pykomodefi`\n\n\n### Usage\n\n**Configuration:**\n\nThe configuration file can be passed as a parameter to the `KomoDeFi_API` class constructor:\n\n```\n >>> import pykomodefi\n >>> dexapi = pykomodefi.KomoDeFi_API(config=\"/path/to/MM2.json\")\n```\nIf not set, the default configuration file path is `MM2.json` in the current folder, or `~/.kdf/MM2.json`.\nIt can be set to a different file later:\n\n```\n >>> import pykomodefi\n >>> dexapi = pykomodefi.KomoDeFi_API()\n >>> dexapi.set_config = \"/path/to/MM2.json\"\n```\n\n\n**Simple RPC call:**\n```\n >>> resp = dexapi.rpc(\"get_enabled_coins\")\n >>> resp\n {\n 'result': [\n {\n 'ticker': 'KMD',\n 'address': 'RMC1cWXngQf2117apEKoLh3x27NoG88yzd'\n },\n {\n 'ticker': 'LTC',\n 'address': 'LQyzwFtf8HU7VYQMhop5bv857uMao4jnKX'\n }\n ]\n }\n```\n \n**RPC call with parameters:**\n```\n >>> params = {\"coin\": \"KMD\"}\n >>> resp = dexapi.rpc(\"my_balance\", params)\n >>> resp\n {\n 'coin': 'KMD',\n 'balance': '20',\n 'unspendable_balance': '0',\n 'address': 'RMC1cWXngQf2117apEKoLh3x27NoG88yzd'\n }\n```\n\n**v2 RPC call:**\n```\n >>> resp = dexapi.rpc(\"get_public_key\", v2=True)\n >>> resp\n {\n 'mmrpc': '2.0',\n 'result': {\n 'public_key': '0371792f7a6846a0da28f3422501927ae103355c02750bc4c4d8430375329a09ac'\n },\n 'id': None\n }\n```\n\n\nThe following methods are available as properties of the `KomoDeFi_API` class. These methods do not require any input parameters:\n```\n >>> dexapi.version\n '1.0.7-beta_afe2e08'\n\n >>> dexapi.pubkey\n '0366d28a7926fb20287132692c4cef7bc7e00e76da064948676f8549c0ed7114d3'\n\n >>> dexapi.pubkey_hash\n '05aab5342166f8594baf17a7d9bef5d567443327'\n\n >>> dexapi.peer_id\n '12D3KooWS9MeuFZhJCfQTntwbTVnXMAJpz9Tvd1XYFuURrGqnJVR'\n\n >>> dexapi.peers_info\n {\n \"12D3KooWM8BrDBXc1TVw2vswoqYcQVn7fFvpAvcCfaV2Uqg2L9jU\":[\"/ip4/89.248.168.39/tcp/38890\"],\n \"12D3KooWJ3dEWK7ym1uwc5SmwbmfFSRmELrA9aPJYxFRrQCCNdwF\":[\"/ip4/188.124.46.112/tcp/38890/p2p/12D3KooWJ3dEWK7ym1uwc5SmwbmfFSRmELrA9aPJYxFRrQCCNdwF\"],\n \"12D3KooWL6yrrNACb7t7RPyTEPxKmq8jtrcbkcNd6H5G2hK7bXaL\":[\"/ip4/168.119.236.233/tcp/38890/p2p/12D3KooWL6yrrNACb7t7RPyTEPxKmq8jtrcbkcNd6H5G2hK7bXaL\"],\n \"12D3KooWPR2RoPi19vQtLugjCdvVmCcGLP2iXAzbDfP3tp81ZL4d\":[\"/ip4/168.119.237.13/tcp/38890/p2p/12D3KooWPR2RoPi19vQtLugjCdvVmCcGLP2iXAzbDfP3tp81ZL4d\"],\n \"12D3KooWKxavLCJVrQ5Gk1kd9m6cohctGQBmiKPS9XQFoXEoyGmS\":[\"/ip4/168.119.236.249/tcp/38890/p2p/12D3KooWKxavLCJVrQ5Gk1kd9m6cohctGQBmiKPS9XQFoXEoyGmS\"],\n \"12D3KooWDbBdifGp3viDR4dCECEFKepjhwhd2YwAqgNVdXpEeewu\":[\"/ip4/80.82.76.214/tcp/38890\"],\n \"12D3KooWJDoV9vJdy6PnzwVETZ3fWGMhV41VhSbocR1h2geFqq9Y\":[\"/ip4/89.248.173.231/tcp/38890\"]\n }\n\n >>> dexapi.orders\n {\n \"maker_orders\": {\n ....\n },\n \"taker_orders\": {\n ....\n }\n }\n\n >>> dexapi.active_swaps\n {\n \"uuids\": [\n \"015c13bc-da79-43e1-a6d4-4ac8b3099b34\",\n \"7592a07a-2805-4050-8ab8-984480e812f0\",\n \"82cbad96-ea9f-40fb-9225-07496323e35d\",\n \"177f7fa5-c9f3-4673-a2fa-28451a123e61\"\n ]\n }\n\n >>> dexapi.enabled_coins\n [\n {\n \"address\": \"1WxswvLF2HdaDr4k77e92VjaXuPQA8Uji\",\n \"ticker\": \"BTC\"\n },\n {\n \"address\": \"R9o9xTocqr6CeEDGDH6mEYpwLoMz6jNjMW\",\n \"ticker\": \"KMD\"\n },\n {\n \"address\": \"R9o9xTocqr6CeEDGDH6mEYpwLoMz6jNjMW\",\n \"ticker\": \"VRSC\"\n },\n {\n \"address\": \"0xbAB36286672fbdc7B250804bf6D14Be0dF69fa29\",\n \"ticker\": \"ETH\"\n }\n ]\n\n >>> dexapi.enabled_coins_v2\n [\n \"MARTY\",\n \"AAVE-PLG20\",\n \"DOGE\"\n ]\n```\n\nFor documentation about available methods and parameters, refer to: <https://developers.komodoplatform.com/basic-docs/atomicdex/introduction-to-atomicdex.html>\n\nSome configuration params from within `MM2.json` are also available as properties:\n```\n>>> dexapi.netid\n8762\n>>> dexapi.rpcip\n127.0.0.1\n>>> dexapi.rpcport\n7783\n>>> dexapi.db_dir\n/path/to/DB\n```\n\n### Building locally\n\n- Run `poetry build`\n- Run `pipx install --spec $(pwd)/dist/pykomodefi-0.2.6.tar.gz pykomodefi --include-deps --force` (change version number accordingly)\n\n### Running tests\n\n**Prerequisites:**\n- Install dependencies: `poetry install`\n- Set up test configuration by either:\n - Creating `tests/.env` file with: `MM2_JSON_PATH=tests/MM2.json`\n - OR copying test config to project root: `cp tests/MM2.json .`\n\n**Run tests:**\n```bash\n# Run all tests with coverage\npoetry run pytest tests/ -v\n\n# Run tests with verbose output\npoetry run pytest tests/ -vv\n\n# Run with coverage report\npoetry run pytest tests/ --cov=pykomodefi --cov-report=html\n```\n\n**Note:** Tests will show connection errors if the KomoDeFi Framework (MM2) is not running. This is expected behavior - the package correctly handles and reports connection failures. To run tests against a live MM2 instance, ensure MM2 is running on `127.0.0.1:7783` before running the tests.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A wrapper for the Komodo DeFi Framework API",
"version": "0.2.6",
"project_urls": {
"Documentation": "https://github.com/smk762/pykomodefi",
"Homepage": "https://github.com/smk762/pykomodefi",
"Repository": "https://github.com/smk762/pykomodefi"
},
"split_keywords": [
"dex",
" crypto",
" komodo",
" defi",
" api",
" trading",
" atomic swaps"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3877f7c9fccdf7efb6e8eeb920ff508f9ca29f6129244e3c525f7e4d2b2c8249",
"md5": "eab70dc1ae639b3559b3dfdbe4b29206",
"sha256": "ecda617ce030137357c99ffc4c151107e19d55837a69a115580c9aaf68869860"
},
"downloads": -1,
"filename": "pykomodefi-0.2.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eab70dc1ae639b3559b3dfdbe4b29206",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 30333,
"upload_time": "2025-09-12T22:46:19",
"upload_time_iso_8601": "2025-09-12T22:46:19.245151Z",
"url": "https://files.pythonhosted.org/packages/38/77/f7c9fccdf7efb6e8eeb920ff508f9ca29f6129244e3c525f7e4d2b2c8249/pykomodefi-0.2.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4932555b12a650f27a5ea9e445fffeb8abaab21955235a1f7ff4620d219bf370",
"md5": "d77404acdd4d836924b6bcadc6360d04",
"sha256": "ccbbe02dd3d42ec148a82e280c2df38df6405d6b46b5e6316e712dc76c38c1a1"
},
"downloads": -1,
"filename": "pykomodefi-0.2.6.tar.gz",
"has_sig": false,
"md5_digest": "d77404acdd4d836924b6bcadc6360d04",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 17251,
"upload_time": "2025-09-12T22:46:20",
"upload_time_iso_8601": "2025-09-12T22:46:20.879087Z",
"url": "https://files.pythonhosted.org/packages/49/32/555b12a650f27a5ea9e445fffeb8abaab21955235a1f7ff4620d219bf370/pykomodefi-0.2.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-12 22:46:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "smk762",
"github_project": "pykomodefi",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pykomodefi"
}