Round Robin Utilities

0.1.0 · active · verified Sun Apr 12

The `roundrobin` library provides a small collection of round-robin selectors for various distribution needs. It includes `basic()` for plain round-robin, `weighted()` for classic LVS-style weighted round-robin, `smooth()` for Nginx-style smooth weighted round-robin, and `smooth_stateful()` for smooth weighted round-robin with runtime controls like health checks or slow-start. The current version is 0.1.0, released in January 2026, indicating active development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the `basic()`, `weighted()`, `smooth()`, and `smooth_stateful()` functions. It shows how to initialize each type of round-robin selector and retrieve items. For `smooth_stateful()`, an example of dynamically adjusting an item's weight at runtime is also included.

import roundrobin

# Basic round-robin
get_basic = roundrobin.basic(["A", "B", "C"])
print(''.join([get_basic() for _ in range(7)]))

# Weighted round-robin
get_weighted = roundrobin.weighted([("A", 5), ("B", 1), ("C", 1)])
print(''.join([get_weighted() for _ in range(7)]))

# Smooth weighted round-robin
get_smooth = roundrobin.smooth([("A", 5), ("B", 1), ("C", 1)])
print(''.join([get_smooth() for _ in range(7)]))

# Stateful smooth weighted round-robin with runtime controls
rr_stateful = roundrobin.smooth_stateful([("A", 5), ("B", 1), ("C", 1)])
outputs = []
for _ in range(14):
    outputs.append(rr_stateful())
print(''.join(outputs))

# Example of runtime weight adjustment with smooth_stateful
rr_stateful_adjust = roundrobin.smooth_stateful([("A", 5), ("B", 1), ("C", 1)])
rr_stateful_adjust.set("A", weight=2)
outputs_adjust = []
for _ in range(14):
    outputs_adjust.append(rr_stateful_adjust())
print(''.join(outputs_adjust))

view raw JSON →