Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

7. Proxies

Fatih Kılıç edited this page May 5, 2019 · 2 revisions

Using RateLimitProxy

from anyapi import AnyAPI
from anyapi.proxy_handlers import RateLimitProxy

proxy_configuration = {
  'default': proxy0, # Can be None or removed
  'proxies': [proxy0, proxy1, proxy2,....], # don't forget to add default proxy!
  'paths': {
    '/anything': rate_limit0,
    '/anything/endpoint': rate_limit1
  }
}

api = AnyAPI(
    "https://httpbin.org",
    proxy_configuration=proxy_configuration,
    proxy_handler=RateLimitProxy,
)

Writing your own Proxy Handler

class MyProxyHandler:
  def __init__(self, **proxy_configuration):
    set_some_stuff()

  def get(self, keyword_arguments):
    proxy = get_some_stuff(keyword_arguments)

    return {"http": proxy, "https": proxy}

Clone this wiki locally