Skip to main content

consensual

Summary

consensual is a pure-Python library for defining network of nodes running in a consistent fault-tolerant manner by implementing state-of-the-art Raft consensus algorithm.

Currently, next features are implemented & property-based tested

  • leader election & log replication (described in section 5 of the article),
  • cluster membership changes (described in section 6 of the article), namely consensual addition & removal of nodes,
  • "solo mode": non-consensual separation of a node resulting in running as a cluster-by-itself,
  • separate node state resetting with history deletion.

Next crucial features to implement will be

  • persistence,
  • log compaction (described in section 7 of the article).

In what follows python is an alias for python3.7 or any later version (python3.8 and so on).

Installation

Install the latest pip & setuptools packages versions

python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository

python -m pip install --upgrade consensual

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/consensual.git
cd consensual

Install dependencies

python -m pip install -r requirements.txt

Install

python setup.py install

Usage

>>> from consensual.raft import Node, communication
>>> from yarl import URL
>>> node_url = URL.build(scheme='http',
...                      host='localhost',
...                      port=6000)
>>> other_node_url = URL.build(scheme='http',
...                            host='localhost',
...                            port=6001)
>>> heartbeat = 0.1
>>> from typing import Any, List, Optional
>>> processed_parameters = []
>>> def dummy_processor(parameters: Any) -> None:
...     processed_parameters.append(parameters)
>>> processors = {'dummy': dummy_processor}
>>> nodes = {}
>>> sender = communication.Sender([node_url], nodes)
>>> other_sender = communication.Sender([other_node_url], nodes)
>>> node = Node.from_url(node_url,
...                      heartbeat=heartbeat,
...                      processors=processors,
...                      sender=sender)
>>> other_node = Node.from_url(other_node_url,
...                            heartbeat=heartbeat,
...                            processors=processors,
...                            sender=other_sender)
>>> receiver = communication.Receiver(node, nodes)
>>> other_receiver = communication.Receiver(other_node, nodes)
>>> receiver.start()
>>> other_receiver.start()
>>> from asyncio import get_event_loop
>>> loop = get_event_loop()
>>> async def run() -> List[Optional[str]]:
...     return [await node.solo(),
...             await node.enqueue('dummy', 42),
...             await node.attach_nodes([other_node.url]),
...             await node.enqueue('dummy', 42),
...             await other_node.detach_nodes([node.url]),
...             await other_node.solo(),
...             await other_node.detach(),
...             await other_node.detach()]
>>> error_messages = loop.run_until_complete(run())
>>> receiver.stop()
>>> other_receiver.stop()
>>> all(error_message is None or isinstance(error_message, str)
...     for error_message in error_messages)
True
>>> all(parameters == 42 for parameters in processed_parameters)
True

We can also replace builtin consensual.raft.communication communication layer with another one (like consensual_http which is built on top of HTTP), usage patterns may change as a result.

Development

Bumping version

Preparation

Install bump2version.

Pre-release

Choose which version number category to bump following semver specification.

Test bumping version

bump2version --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump2version --verbose $CATEGORY

This will set version to major.minor.patch-alpha.

Release

Test bumping version

bump2version --dry-run --verbose release

Bump version

bump2version --verbose release

This will set version to major.minor.patch.

Running tests

Install dependencies

python -m pip install -r requirements-tests.txt

Plain

pytest

Inside Docker container:

docker-compose --file docker-compose.yml up

Bash script:

./run-tests.sh

PowerShell script:

.\run-tests.ps1

Metadata

Release files for consensual 0.2.3

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

Source distribution (sdist)

Source distribution for consensual 0.2.3
File Size Uploaded
consensual-0.2.3.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for consensual 0.2.3
File Interpreter ABI Platform
consensual-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 39.3 kB

Release files / consensual-0.2.3.tar.gz

Download URL consensual-0.2.3.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
803436af13acb5dd908aad848be03a7a5906773f233ea114f92fd1ab36fa25da
BLAKE2b-256 checksum
How to use checksums
4dc9b8ba6cffa6dca7b314d33c42f8dc7b51c26598b78705e5da7ddc6d075875
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

Release files / consensual-0.2.3-py3-none-any.whl

Download URL consensual-0.2.3-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15a222cafbe3447d930e3a4916fad0f494a1f9beea0853afb8bbe6d712aeb31d
BLAKE2b-256 checksum
How to use checksums
81c1b4353478a734c7dcd273964d72e298f878ab0fa84dc91853f27947e44e23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

3 release files

0.2.0

3 release files

0.1.0

3 release files

0.0.0

1 release file

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