Skip to content

Implement pagination support for local evaluation #204

Description

@khvn26

When updating the environment document asynchronously, exhaust all pages.

The following python code describes the process of consuming all api/v1/environment-document pages, the compiled_document should be stored as the environment document in the SDKs local memory cache.

import json

import requests

ENVIRONMENT_KEY = "<server key>"
BASE_API_URL = "https://edge.api.flagsmith.com"

session = requests.Session()
session.headers.update({"X-Environment-Key": ENVIRONMENT_KEY})


if __name__ == "__main__":
    documents = []
    url = f"{BASE_API_URL}/api/v1/environment-document"

    while True:
        env_doc_response = session.get(url)
        documents.append(env_doc_response.json())

        if not env_doc_response.links:
            break

        url = f'{BASE_API_URL}{env_doc_response.links["next"]["url"]}'

    compiled_document = documents[0]
    for document in documents[1:]:
        compiled_document["identity_overrides"] += document["identity_overrides"]

If retrieval of all pages takes longer that the polling interval, emit a warning log.

Activity

  1. Zaimwa9 commented on Oct 3, 2025

    @Zaimwa9
    Contributor

    @matthewelwell I'm noticing that we only merge identity_overrides. I couldn't find the example code and until I get my hands on a paginated env-document, I also merged the feature_states in the first version

  2. khvn26 commented on Oct 3, 2025

    @khvn26
    MemberAuthor

    Let's keep with identity_overrides for now. Hopefully, Flagsmith/flagsmith#5721 will help us drop the pagination altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions