HTTP-based communication layer for `consensual` package.
Project description
consensual_http
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_http
Developer
Download the latest version from GitHub
repository
git clone https://github.com/lycantropos/consensual_http.git
cd consensual_http
Install dependencies
python -m pip install -r requirements.txt
Install
python setup.py install
Usage
>>> from consensual.raft import Node
>>> from consensual_http import communication
>>> from yarl import URL
>>> node_url = URL.build(scheme='http',
... host='localhost',
... port=6000)
>>> heartbeat = 0.1
>>> from typing import Any
>>> processed_parameters = []
>>> def dummy_processor(parameters: Any) -> None:
... processed_parameters.append(parameters)
>>> def stop(parameters: Any = None) -> None:
... receiver.stop()
>>> processors = {'dummy': dummy_processor, 'stop': stop}
>>> sender = communication.Sender(heartbeat=heartbeat,
... urls=[node_url])
>>> from asyncio import Event, get_event_loop
>>> loop = get_event_loop()
>>> node = Node.from_url(node_url,
... heartbeat=heartbeat,
... loop=loop,
... processors=processors,
... sender=sender)
>>> node_is_running = Event()
>>> receiver = communication.Receiver(node,
... on_run=node_is_running.set)
>>> from aiohttp.client import ClientSession
>>> def validate_response(response: Any) -> None:
... assert isinstance(response, dict)
... assert response.keys() == {'error'}
... assert response['error'] is None
>>> async def run() -> None:
... await node_is_running.wait()
... async with ClientSession(node.url) as session:
... validate_response(await (await session.post('/')).json())
... validate_response(await (await session.post('/dummy',
... json=42)).json())
... validate_response(await (await session.delete('/',
... json=[str(node.url)])).json())
... validate_response(await (await session.delete('/')).json())
... stop(None)
>>> _ = loop.create_task(run())
>>> receiver.start()
>>> all(parameters == 42 for parameters in processed_parameters)
True
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 up
Bash
script:
./run-tests.sh
PowerShell
script:
.\run-tests.ps1
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file consensual_http-0.1.0.tar.gz
.
File metadata
- Download URL: consensual_http-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using 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.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06dcb3dc9223c90ca19ea6fb13ff674145ddb1aa81f20a7be76483f631f26efd |
|
MD5 | 51272b33d3ba8de7f88cae19ebfc3a52 |
|
BLAKE2b-256 | 903df01c9ddc464d9014098f58e87dc2c9fe86f87d17ac85e0ebf1ccac8578b7 |
File details
Details for the file consensual_http-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: consensual_http-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using 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.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fef025a63551b482d8ab2cc01d4ce88c60c5c22ba0a0b8ef84c64b579dd72f |
|
MD5 | 30172a0b18feacd3dfff4be6e89a56a9 |
|
BLAKE2b-256 | cfc51376b059e2852ccb6954b813196560cd408f332237d3b5f095414e528c31 |