Metadata-Version: 2.1
Name: pybalancer
Version: 1.0
Summary: an simple load balancer for Python
Home-page: https://github.com/wenqf11/pybalancer
Author: Qingfu Wen
Author-email: qingfu.wen@gmail.com
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Requires-Dist: uhashring (>=2.1)

# pybalancer
**pybalancer** an simple load balancer for Python

## Features

English

* a simple load balancer
* consistent Hash Load Balance using **uhashring** ketama hash function
* periodly health checks, remove failed instance and add when it recovers
* manually call remove_instance when it fails.


## Installation
Using pip:

```
$ pip install pybalaner
```

## Basic usage

**pybalancer** is very simple and efficient to use:

```python
from pybalancer import LoadBalancer

# create a consistent hash ring of 3 nodes of weight 1
balancer = LoadBalancer(instances=['node1:port1', 'node2:port2', 'node3:port3'], interval=5)

# get the node name for the remote_addr key
target_instance = balancer.get_instance(remote_addr="host:port")

failed_times = 0
# call target_instance fails
if call(target_instance):
	failed_times += 1
	if failed_times > max_fails:
		balancer.remove_instance(target_instance)


alive_instances = balancer.get_alive_instances()
print(alive_instances)
```

