The Flare SDK automatically recognizes the FLARE_API_KEY and FLARE_TENANT_ID environment variables.For example, you may expose the following environment variables, and then create an API client from them:
import osfrom flareio import FlareApiClientfrom flareio.ratelimit import Limiterapi_key = os.environ.get("FLARE_API_KEY")if not api_key: raise Exception("Please provide an API key")api_client = FlareApiClient(api_key=api_key)limiter = Limiter.from_seconds(0.25)last_from: str | None = Nonefetched_pages: int = 0for resp in api_client.scroll( method="GET", url="/astp/v2/sources", params={ "from": last_from, },): # Rate limiting (default). limiter.tick() # Get results from the response resp_data = resp.json() items = resp_data.get("items") fetched_pages += 1 print(f"Fetched page {fetched_pages} ({last_from=}) with {len(items)} items...") # Save the last "next" value. last_from = resp_data.get("next") or last_fromprint("The last value for 'next' was", last_from)
The FlareApiClient has a scroll_events method that can be used with event feeds endpoints.
The advantage of this method over scroll is that it also automates the fetching of individual events.
To route requests through an HTTP proxy, pass a proxies dict to FlareApiClient. It accepts the same format as the requestsproxies argument.
Using a Proxy
from flareio import FlareApiClientclient = FlareApiClient( api_key="fw_...", proxies={"https": "http://proxy.corp.local:8080"},)
The HTTP_PROXY and HTTPS_PROXY environment variables are also picked up by requests, so setting them is enough if you’d rather not pass proxies explicitly.