Skip to main content

Python API

Bitcoin Cash full node as a Python library

PyPi Version License py-standard-style Telegram

Knuth Python API is a high performance implementation of the Bitcoin Cash protocol focused on users requiring extra performance and flexibility. It is a Bitcoin Cash node you can use as a library.

Getting started with Python

  1. Create a new Python console project:
$ mkdir HelloKnuth
$ cd HelloKnuth
  1. Add a reference to our Python API package:
$ pip install kth
  1. Create a new file called index.py and write some code:
import kth
import signal
import asyncio

running_ = False

def shutdown(sig, frame):
    global running_
    print('Graceful shutdown ...')
    running_ = False

async def main():
    global running_
    signal.signal(signal.SIGINT, shutdown)
    config = kth.config.getDefault(kth.config.Network.mainnet)

    with kth.node.Node(config, True) as node:
        await node.launch(kth.primitives.StartModules.all)
        print("Knuth node has been launched.")
        running_ = True

        (_, height) = await node.chain.getLastHeight()
        print(f"Current height in local copy: {height}")

        if await comeBackAfterTheBCHHardFork(node):
            print("Bitcoin Cash has been created!")

        # node.close()
        print("Good bye!")

async def comeBackAfterTheBCHHardFork(node):
    hfHeight = 478559
    while running_:
        (_, height) = await node.chain.getLastHeight()
        if height >= hfHeight:
            return True
        await asyncio.sleep(10)

    return False

asyncio.run(main())
  1. Enjoy Knuth node as a Python library:
$ python index.py

Issues

Each of our modules has its own Github repository, but in case you want to create an issue, please do so in our main repository.

Metadata

Release files for kth 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kth 0.8.0
File Size Uploaded
kth-0.8.0.tar.gz 26.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kth 0.8.0
File Interpreter ABI Platform
kth-0.8.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 57.4 kB

Release files / kth-0.8.0.tar.gz

Download URL kth-0.8.0.tar.gz
Size 26.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2712f8ff8cdac18278e6fdf7afc6fd8e88055e8a0ce59d11e185804108ed943d
BLAKE2b-256 checksum
How to use checksums
ba1cdf3fee4bad914593c7fcabdae27f31459f608276c58569d59f3f698fe4f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release files / kth-0.8.0-py2.py3-none-any.whl

Download URL kth-0.8.0-py2.py3-none-any.whl
Size 30.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
31457c627d8421054660ba968a59e107f20c0aedab23a5a7019522086b81c817
BLAKE2b-256 checksum
How to use checksums
57667a191c00939fca19df569e6bc7ae20639568763f0417acbe0c262fd11c6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page