Repository navigation
Add iter_export_range to export ranges longer than 31 days - #138
Open
SyedAbdullahh wants to merge 1 commit into
Open
SyedAbdullahh wants to merge 1 commit into
SyedAbdullahh wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_pagesfor 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_rangeon both clients reads[from_time, to_time)of any length as back-to-back windows and yields every page of each window.Decisions
toand the next window'sfrom, so windows neither overlap nor leave gaps. The caller'sfrom_timeandto_timeare sent exactly as written.iter_export_pages, so cursor checks, retries, response limits andmax_pages(per window) all stay in one place. Nothing in the transport changes.ExportRangePageis anExportPageplus theExportWindowit 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.ValueErrorbefore any request:24:00,+24:00and anything finer than microsecondsmax_windowswindows (default 100, max 1000), the same style of limit asmax_pagesfinding_outcomesis refused. Its rows are groups counted over one window, so groups from separate windows aren't totals for the range. The error points toiter_export_pagesfor a single window.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
tests/test_exports.pyfor window splitting and date validation, and HTTP tests intests/test_http.pyagainst 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 hitsmax_pages. All 66 fail onmain.finding_outcomes, an off-by-one window count). Each made a test fail.python scripts/check.pypasses on Python 3.13.12, the CI version, on macOS: the generation check, the contracts,ruff check,ruff format --check,mypy, 284 tests (218 onmain), the builds, and the installed-package smoke tests. GitHub Actions hasn't run it yet, and nothing was run against the live API.EXPORT_WINDOWconstant.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.