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
Hashes for consensual_http-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fef025a63551b482d8ab2cc01d4ce88c60c5c22ba0a0b8ef84c64b579dd72f |
|
MD5 | 30172a0b18feacd3dfff4be6e89a56a9 |
|
BLAKE2b-256 | cfc51376b059e2852ccb6954b813196560cd408f332237d3b5f095414e528c31 |