Skip to main content

Witnet Library

This library is light client implementation for witnet node, capable of directly interacting with witnet node. ( See Witnet.io for more information )

Features

  • Allows sending proto messages to witnet node.
  • Performs handshake with witnet node.
  • Iterates over the nodes in witnet network in a DAG(directed acyclic graph) fashion

How to use

Performing handshake with witnet node.

from witnet_lib.witnet_client import WitnetClient
from witnet_lib.utils import AttrDict

# Setting config
config = AttrDict({
    "genesis_sec": 1602666000,
    "magic": 40941,
    "sender_addr": "127.0.0.1:21341",
    "time_per_epoch": 45,
})
client = WitnetClient(config)
client.handshake("127.0.0.1:21337")
client.close()

Listening to messages from witnet node.

#After performing handshake with node.
msg = client.receive_msg() # this returns serialized message from node
parsed_msg = client.msg_handler.parse_msg(msg) # we need to parse the message
print(parsed_msg)
print(parsed_msg.kind)

The connection is of keep alive type, so messages are continually sent from witnet node. To listen for all messages:

while True:
    msg = client.receive_msg() # this returns serialized message from node
    parsed_msg = client.msg_handler.parse_msg(msg)
    print(parsed_msg)

Sending message to witnet node.

#After performing handshake with node.
cmd = client.msg_handler.version_cmd("127.0.0.1:21337") # this returns a version message
print(cmd)
msg = client.msg_handler.serialize(cmd)# this returns serialized messsage ready to be sent to node
client.send_msg(msg)
msg_from_node = client.receive_msg() # this returns only one whole message from node
msg_from_node_with_msg_len, reced_or_not = client.tcp_handler.receive(30) # this returns x bytes from connection stream

Mapping all nodes in the network (DAG fashion)

from witnet_lib import utils
from witnet_lib.map_nodes  import MapNodes
config = utils.AttrDict({
    "genesis_sec": 1602666000,
    "magic": 40941,
    "sender_addr": "127.0.0.1:21341",
    "time_per_epoch": 45,
})
mapper = MapNodes(config, ["127.0.0.1:21337"]) # provide initialisation peers
all_nodes, active_map = mapper.start_mapping_workers(3) # number of connections allowed to be created in parallel
print(all_nodes)
print(active_map) # it contains node id with the list of its peers

Metadata

Release files for witnet-lib 1.0.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 witnet-lib 1.0.0
File Size Uploaded Provenance
witnet_lib-1.0.0.tar.gz 19.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for witnet-lib 1.0.0
File Interpreter ABI Platform
witnet_lib-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.3 kB

Release files / witnet_lib-1.0.0.tar.gz

Download URL witnet_lib-1.0.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
059c04a91819948256915fa983d3516f1078166796da07defb71e8d5275fe7f0
BLAKE2b-256 checksum
How to use checksums
55506772d99564379f6aedb4072321e93f3391b0e3d40ada607d56a912969760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Release files / witnet_lib-1.0.0-py3-none-any.whl

Download URL witnet_lib-1.0.0-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bf92898f3b3bc8c71983a46d0a6a5d1f6ac4a3485583b8fe6e25115d0e63ef9
BLAKE2b-256 checksum
How to use checksums
51a2bb53d5550ec62457fa31b8030fe96eafcb7045472f64b629bfeba68b8649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

Security for witnet-lib 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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