Giter VIP home page Giter VIP logo

apimux's Introduction

Python API Multiplexer

This library provides an easy way to manage multiple equivalent API services. It takes as an input a list of APIs and exposes an endpoint which can be used to fetch the results from the registered APIs.

How to use apimux

  1. Implement the specific API starting from the abstract class BaseThirdPartyAPIService.

Example:

class FakeAPI(BaseThirdPartyAPIService):
    def __init__(self):
        super(FakeAPI, self).__init__(name='Fake API Name')

    def get_result(self, data):
        # Process the data parameter and execute the request.
        # This is specific to each API.
        result = 42  # FakeAPI returns 42 as a result
        return result
  1. (Optional) Create a config file to overwrite the default parameters. More details can be found in the config file.

  2. Create the APIMultiplexer object.

Example:

api_mux = APIMultiplexer(
    api_list=[FakeAPI()],
    config_filepath="/opt/apimux_config.ini")

You can add/remove new APIs dynamically by calling the ADD or REMOVE methods.

  1. Fetch the data from the registered APIs by calling get_next_results.

Example:

data = ["Return", "42"]
# Now we fetch the result from one of the APIs
result = api_mux.get_next_results(data, number_of_results=1)  # 42
# To fetch the results from all registered APIs
all_results = api_mux.get_next_results(data, number_of_results=-1)

Note: The function will block until it completes. The results are fetched in parallel when multiple results are requested. When the number of results is passed, apimux will fetch the responses from the APIs sorted by the average response times of the previous requests (i.e. calling with number_of_results=1 will return the response from the fastest API).

A concrete example which shows how to use apimux can be found in Zeeguu-API.

apimux's People

Contributors

alinbalutoiu avatar mircealungu avatar

Watchers

 avatar James Cloos avatar Lars Holdijk avatar

Forkers

alinbalutoiu

apimux's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.