Skip to main content

Client of redundant servers

Build Status codecov PyPI version

Generic client of redundant servers. A simple framework to make requests of unreliable servers. Throws an exception if no servers are available, otherwise returns a result from the first server that doesn't fail. Supports round-robin, fixed, and random orders of servers.

The intention is that you can use this to glue together things that are otherwise slightly tedious, using your own client classes which inherit from ClientOfRedundantServers.

Installation

pip install client-of-redundant-servers

Usage

Say you have some web servers, all serving the same content, and you want to get a file from any one. You don't care which server responds, but you don't want to have to manually look for failures and try again.

client_of_redundant_servers lets you write things like this:

import requests
import client_of_redundant_servers as cors
from collections import OrderedDict


class ClientOfRedundantWebServers(cors.ClientOfRedundantServers):
    def __init__(self, url_list: list):
        # Super().__init__ wants a dict, but this example is so simple that
        # a list can be used to create an OrderedDict of None.
        url_dict = OrderedDict((url, None) for url in url_list)
        super().__init__(url_dict)

    def _get_file_func(self, url):
        try:
            r =  requests.get(url)
            # Check for errors that didn't raise a requests.exception
            if not r.ok:
                raise cors.CurrentServerFailed
            return r
        except requests.exceptions.RequestException:
            raise cors.CurrentServerFailed

    def get_file(self):
        return self.request(self._get_file_func)


# Only picking on Ubuntu because it is widely mirrored.
urls = ["http://badserver.example.com/badfile",
        "http://www.mirrorservice.org/sites/cdimage.ubuntu.com/cdimage/releases/16.04/release/SHA256SUMS",
        "http://nl.archive.ubuntu.com/ubuntu-cdimages/16.04/release/SHA256SUMS"]

client = ClientOfRedundantWebServers(urls)
try:
    r = client.get_file()
    print(r.text)
    print("*****")
    print("Retrieved from : " + r.url)
except cors.AllAvailableServersFailed:
    print("Error! No servers were available to service the request.")

If you run that, you'll see that the client tries to retrieve the file from badserver, which fails, so it continues to try the next available server.

See the "examples" directory for some examples that might be useful. Currently there's a RADIUS client using pyrad and an Active Directory LDAP client using ldap3.

Release files for client-of-redundant-servers 0.6

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

Source distribution (sdist)

Source distribution for client-of-redundant-servers 0.6
File Size Uploaded
client_of_redundant_servers-0.6.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for client-of-redundant-servers 0.6
File Interpreter ABI Platform
client_of_redundant_servers-0.6-py3-none-any.whl Python 3 none any Details

Total release size: 16.2 kB

Release files / client_of_redundant_servers-0.6.tar.gz

Download URL client_of_redundant_servers-0.6.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1ef476736c022b067d4498f14fb06cd0ac5a67f3c00de7d3cfc004de43dfc5b4
BLAKE2b-256 checksum
How to use checksums
019b06ec1c7d8e5602e0bce37e18beac6c8fe9eef5c113b17c0c63ee9e13269a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / client_of_redundant_servers-0.6-py3-none-any.whl

Download URL client_of_redundant_servers-0.6-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3beff3504c4fdce736d76d00470ce1ec00026a79faab353d340eb3b2b0e4cbcb
BLAKE2b-256 checksum
How to use checksums
d9d41b34b9dbcf2e315ef4552c6cd4f78c9258a60dbb0b3267a6dfad0ea5accd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6 This release

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

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