Expose census appends, match_type, raw payloads and rate limits - #34
Merged
Conversation
…imits Four gaps in the public surface, found while a consumer had to fall back to a third-party client: - Census appends were only reachable through the private `fields._census` dict. Adds `fields.census`, `fields.get_census(year)`, `fields.census_years` and `fields.census_data`, consistent with how the other appends are exposed. The private dict and the dynamic `fields.census2023` attributes keep working. - `match_type` and `address_lines` are returned on every v2 result but were silently dropped by `GeocodingResult`. Both are now parsed, for single and batch responses alike. - Adds `raw` / `to_dict()` on `GeocodingResponse` and `GeocodingResult`, so pipelines can cache the untouched payload instead of a lossy projection. - Parses the `X-RateLimit-*` headers into a `RateLimit` model, exposed as `GeocodingResponse.rate_limit` and `Geocodio.rate_limit`. No version bump -- release is a separate call.
Merged
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.
Closes four gaps in the client's public surface. These surfaced while reviewing a contractor-built Dagster skill that had to fall back to the third-party
pygeocodiopackage: every one of these was a reason it could not use the official client cleanly.Ready for review. No version bump is included, so a release is a separate call once this is approved.
Changes
Census appends had no public accessor. Requesting
fields=["census2023"]stored the data only on the privatefields._censusdict, so consumers had to writeresult.fields._census["census2023"]["full_fips"]to reach the single most useful append field. Addsfields.census,fields.get_census(year),fields.census_yearsandfields.census_data, matching how the other appends are already exposed.get_census()accepts2023,"2023"or"census2023". The private dict and the dynamicfields.census2023attributes are untouched.match_typeandaddress_lineswere silently dropped. Both are returned on every v2 result but were absent fromGeocodingResult, so the data was lost on parse. Both are now populated for single and batch responses. A full diff of the raw v2 JSON keys against the dataclass confirms these were the only two missing.No way to recover the raw payload. There was no
raw,to_dict(), or equivalent, anddataclasses.asdict()is lossy and leaks the private_censuskey. Addsrawandto_dict()to bothGeocodingResponseandGeocodingResult, so pipelines can cache the untouched response and add derived columns later without re-fetching and re-paying for the lookup.Rate limit headers were not exposed. The
X-RateLimit-*headers were logged at debug level only. Adds aRateLimitmodel exposed asGeocodingResponse.rate_limitandGeocodio.rate_limit, parsed case-insensitively and populated before error handling so it is available on 4xx and 5xx too. Worth noting the API sendsx-ratelimit-periodrather thanx-ratelimit-reset; both are modelled and the raw header dict is kept onRateLimit.headers.Compatibility
Backward compatible. New dataclass fields are appended, so positional construction still works, and existing attribute access is unchanged.
Verification
pytest tests/unit/-- 115 passed (9 new)pytest tests/e2e/-- 45 passed against the live API (4 new)flake8 src/ --ignore=E501-- clean;black --checkandisort --check-onlycleanmypy-- 19 errors, identical to the baseline onmain, none on new linesAll four changes were also verified by hand against api.geocod.io/v2.
Reviewer notes
fields.censusreturns the most recent vintage when several are present in the response. Multi-vintage callers should useget_census(year). Worth a sanity-check that this is the behaviour you want.rawis a real dataclass field, sodataclasses.asdict()output now includes it and roughly duplicates the payload. It isrepr=False, so reprs are unaffected.raw={}rather than the{query, response}wrapper, keepingresult.rawconsistently "the API result object". The wrapper stays reachable viaresponse.raw.