Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/concepts/paging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ These are end-to-end examples in various programming languages.
<Accordion title="Python SDK Example">
```python
import os
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_key = os.environ.get("FLARE_API_KEY")
Expand All @@ -79,6 +79,8 @@ if not api_key:

api_client = FlareApiClient(api_key=api_key)

limiter_default = Limiter.from_seconds(0.25)

last_from: str | None = None
fetched_pages: int = 0

Expand All @@ -90,7 +92,7 @@ for resp in api_client.scroll(
},
):
# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

# Get results from the response
resp_data = resp.json()
Expand All @@ -109,9 +111,9 @@ print("The last value for 'next' was", last_from)
<Accordion title="Python Generic Example">
```python
import os
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_key = os.environ.get("FLARE_API_KEY")
Expand All @@ -120,12 +122,13 @@ if not api_key:

api_client = FlareApiClient(api_key=api_key)

limiter_default = Limiter.from_seconds(0.25)

from_: str | None = None
fetched_pages: int = 0

while True:
# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

params: dict = {}
if from_:
Expand Down
9 changes: 5 additions & 4 deletions docs/guides/cookie-monitoring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ This is an end-to-end example in Python.
<Accordion title="Python SDK Example">
```python
import json
import time

from datetime import datetime
from datetime import timedelta
from datetime import timezone
from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_client = FlareApiClient.from_env()

limiter_default = Limiter.from_seconds(0.25)

last_from: str | None = None
fetched_pages: int = 0
fetch_full_event: bool = False
Expand All @@ -86,8 +88,7 @@ for resp in api_client.scroll(
).isoformat(),
},
):
# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

resp_data: dict = resp.json()

Expand All @@ -105,7 +106,7 @@ for resp in api_client.scroll(

# Optionally fetch more information about how it was leaked...
if fetch_full_event:
time.sleep(0.2)
limiter_default.tick()
full_event = api_client.get(
url="/firework/v2/activities/",
params={
Expand Down
6 changes: 4 additions & 2 deletions docs/guides/credentials-export-domain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ These are end-to-end examples in various programming languages.
```python
import csv
import sys
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_client = FlareApiClient.from_env()

limiter = Limiter.from_seconds(0.25)

# The cursor from which we are starting the current execution.
last_from: str | None = None

Expand Down Expand Up @@ -89,7 +91,7 @@ for resp in api_client.scroll(
last_from = resp.json().get("next") or last_from

# Rate limiting.
time.sleep(0.25)
limiter.tick()

print(f"The next execution could resume using {last_from=}.")
```
Expand Down
11 changes: 6 additions & 5 deletions docs/guides/global-search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ These are end-to-end examples in various programming languages.
<Accordion title="Python SDK Example">
```python
import datetime
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_client = FlareApiClient.from_env()

limiter_search = Limiter.from_seconds(1)
limiter_default = Limiter.from_seconds(0.25)

from_timestamp: str = (
datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(hours=1)
).isoformat()
Expand All @@ -83,8 +86,7 @@ for resp in api_client.scroll(
},
},
):
# Rate limiting (search).
time.sleep(1)
limiter_search.tick()

resp_data: dict = resp.json()
items: list[dict] = resp_data["items"]
Expand All @@ -97,8 +99,7 @@ for resp in api_client.scroll(

# (Optional): Get the full data
for item in items:
# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

event_response = api_client.get(
url="/firework/v2/activities/",
Expand Down
7 changes: 4 additions & 3 deletions docs/guides/tenant-credentials.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ These are end-to-end examples in various programming languages.

<Accordion title="Python SDK Example">
```python
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_client = FlareApiClient.from_env()

limiter = Limiter.from_seconds(1)

last_from: str | None = None
fetched_pages: int = 0

Expand All @@ -41,7 +42,7 @@ for resp in api_client.scroll(
},
):
# Rate limiting.
time.sleep(1)
limiter.tick()

resp_data: dict = resp.json()

Expand Down
10 changes: 6 additions & 4 deletions docs/guides/tenant-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ These are end-to-end examples in various programming languages.
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_client = FlareApiClient.from_env()

limiter_search = Limiter.from_seconds(1)
limiter_default = Limiter.from_seconds(0.25)

last_from: str | None = None
fetched_pages: int = 0

Expand All @@ -114,8 +118,7 @@ for resp in api_client.scroll(
"from": last_from,
},
):
# Rate limiting (search).
time.sleep(1)
limiter_search.tick()

resp_data: dict = resp.json()

Expand All @@ -128,8 +131,7 @@ for resp in api_client.scroll(

# (Optional): Get the full data
for item in resp_data["items"]:
# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

event_response = api_client.get(
url="/firework/v2/activities/",
Expand Down
23 changes: 10 additions & 13 deletions docs/guides/update-identifiers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,32 @@ This guide covers how to list identifiers, retrieve a specific identifier by ID,

<Accordion title="Python SDK Example">
```python
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_client = FlareApiClient.from_env()

limiter_default = Limiter.from_seconds(0.25)

# 1. List all identifiers
for resp in api_client.scroll(
method="GET",
url="/firework/v3/identifiers/",
):
# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

data = resp.json()
items = data.get("items", [])

for item in items:
# Rate limiting (default).
time.sleep(0.25)
for item in resp.json()["items"]:
limiter_default.tick()

identifier_id = item.get("id")
identifier_id = item["id"]

# 2. Get the full identifier by ID
identifier_resp = api_client.get(f"/firework/v3/identifiers/{identifier_id}")
identifier = identifier_resp.json().get("identifier")
identifier = identifier_resp.json()["identifier"]

# Rate limiting (default).
time.sleep(0.25)
limiter_default.tick()

# 3. Do the necessary updates to the identifier
api_client.put(
Expand Down
6 changes: 4 additions & 2 deletions docs/sdk/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ The `FlareApiClient` has a `scroll` method that can be used with endpoints that

```python Paging Util - Generic Example
import os
import time

from flareio import FlareApiClient
from flareio.ratelimit import Limiter


api_key = os.environ.get("FLARE_API_KEY")
Expand All @@ -76,6 +76,8 @@ if not api_key:

api_client = FlareApiClient(api_key=api_key)

limiter = Limiter.from_seconds(0.25)

last_from: str | None = None
fetched_pages: int = 0

Expand All @@ -87,7 +89,7 @@ for resp in api_client.scroll(
},
):
# Rate limiting (default).
time.sleep(0.25)
limiter.tick()

# Get results from the response
resp_data = resp.json()
Expand Down