Skip to content

Add iter_export_range to export ranges longer than 31 days - #138

Open
SyedAbdullahh wants to merge 1 commit into
prooflinedev:mainfrom
SyedAbdullahh:add-iter-export-range
Open

SyedAbdullahh wants to merge 1 commit into
prooflinedev:mainfrom
SyedAbdullahh:add-iter-export-range

Conversation

@SyedAbdullahh

Copy link
Copy Markdown

Who it helps: anyone exporting more than a month of data, such as a quarterly report, a yearly spend total or a backfill into a warehouse. The export API reads a window of at most 31 days, so today the caller splits the range by hand and runs iter_export_pages for each window. That's easy to get wrong: an inclusive end or a boundary rounded to a day in local time reads rows twice or skips them, and the export still looks complete.

What it does: iter_export_range on both clients reads [from_time, to_time) of any length as back-to-back windows and yields every page of each window.

with ProoflineClient() as client:
    for page in client.iter_export_range(org_id, "reviews",
            from_time="2026-01-01T00:00:00Z", to_time="2027-01-01T00:00:00Z"):
        print(page.window.from_time, page.window.to_time, len(page.rows))

Decisions

  • Windows are exactly 31 × 24 hours of elapsed time, and the last one is shorter. Each boundary is one UTC timestamp, used as one window's to and the next window's from, so windows neither overlap nor leave gaps. The caller's from_time and to_time are sent exactly as written.
  • Each window is read through iter_export_pages, so cursor checks, retries, response limits and max_pages (per window) all stay in one place. Nothing in the transport changes.
  • Each yielded ExportRangePage is an ExportPage plus the ExportWindow it came from. Every window yields at least one page, even with no rows, so a caller can check the whole range was read, or restart from the last window they kept, since a cursor only works within its own window.
  • These raise ValueError before any request:
    • a time that isn't an RFC 3339 date-time with an offset, including date-only values, February 30, 24:00, +24:00 and anything finer than microseconds
    • an empty or reversed range
    • a range that needs more than max_windows windows (default 100, max 1000), the same style of limit as max_pages
  • finding_outcomes is refused. Its rows are groups counted over one window, so groups from separate windows aren't totals for the range. The error points to iter_export_pages for a single window.
  • I parse the timestamps myself rather than with datetime.fromisoformat, which also accepts ISO 8601 forms the API doesn't (week dates, the basic format) and handles fractional seconds differently across Python versions.

How I verified it

  • 66 new test cases: unit tests in tests/test_exports.py for window splitting and date validation, and HTTP tests in tests/test_http.py against the loopback server for both clients, CSV and NDJSON. They cover cursors within a window, an empty window, non-UTC offsets, exact 31-day ranges, a leap day, ranges up to 3,100 days, rejected inputs (with no request sent), and stopping at the first window that fails or hits max_pages. All 66 fail on main.
  • To check the tests catch real mistakes, I planted four bugs one at a time (32-day windows, overlapping windows, allowing finding_outcomes, an off-by-one window count). Each made a test fail.
  • python scripts/check.py passes on Python 3.13.12, the CI version, on macOS: the generation check, the contracts, ruff check, ruff format --check, mypy, 284 tests (218 on main), the builds, and the installed-package smoke tests. GitHub Actions hasn't run it yet, and nothing was run against the live API.
  • I assume "at most 31 days" means a window of exactly 31 days is accepted. If the server counts it differently, the fix is the EXPORT_WINDOW constant.

Not included: checking that the dataset version or settled horizon stays the same across windows. #120 adds a horizon check within one window, and this builds on top of the iterator without changing it.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 02:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants