docs: clarify sync vs async client usage, add method patterns and best practices#48
Open
JoshuaVulcan wants to merge 1 commit intomainfrom
Open
docs: clarify sync vs async client usage, add method patterns and best practices#48JoshuaVulcan wants to merge 1 commit intomainfrom
JoshuaVulcan wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the README to better guide users on when and how to use the synchronous (ERClient) vs asynchronous (AsyncERClient) EarthRanger clients, and provides more concrete usage patterns and best-practice guidance.
Changes:
- Adds a sync vs async decision table and separate usage sections for
ERClientandAsyncERClient. - Introduces “common patterns” examples (single-item gets, paginated iteration, and common post methods).
- Adds a reference-style section for common method signatures plus operational best practices (errors, time ranges, bulk reads, rate limits).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| The async client currently supports: | ||
|
|
||
| * **Post:** Sensor observations (positions), events/reports, event attachments, camera trap reports, messages; event/subject/event type/category CRUD where implemented. | ||
| * **Get:** Events, single event, event types, observations, subject groups, feature groups, sources, source assignments (subjectsources), user/me. |
Comment on lines
+133
to
+134
| * **Constructor:** `ERClient(service_root, client_id=None, username=None, password=None, token=None, provider_key=None, ...)` | ||
| Same for `AsyncERClient`. Use `token` or `client_id`+`username`+`password`. Set `provider_key` when posting sensor/camera-trap data. |
| Same for `AsyncERClient`. Use `token` or `client_id`+`username`+`password`. Set `provider_key` when posting sensor/camera-trap data. | ||
|
|
||
| * **Events:** | ||
| `get_events(*, filter, page_size, max_results, ...)` → sync: generator; async: async generator. |
|
|
||
| * **Async:** Prefer `async with AsyncERClient(...) as client:` so the session is closed even on errors. | ||
| * **Errors:** Catch `ERClientException` and subclasses (`ERClientBadCredentials`, `ERClientNotFound`, `ERClientPermissionDenied`, `ERClientRateLimitExceeded`, `ERClientServiceUnreachable`, etc.) for robust handling. | ||
| * **Time ranges:** Use timezone-aware datetimes or ISO 8601 strings with timezone (e.g. `"2023-11-10T00:00:00-06:00"`) for `start`/`end` and filter `date_range` to avoid ambiguity. |
Comment on lines
+65
to
+66
| for obs in client.get_observations(start="2023-11-10T00:00:00Z", end="2023-11-11T00:00:00Z"): | ||
| ... |
Comment on lines
+101
to
+104
| # Post (await) | ||
| await client.post_sensor_observation(position) | ||
| await client.post_report(report) | ||
| await client.post_camera_trap_report(camera_trap_payload, file=file_handle) |
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.
README updates:
ERClientvsAsyncERClient; separate sections with constructor and usage patterns. Fixed async examples (correctclientreference,async with+asyncio.run(main())).get_events/get_observations, andpost_report/post_sensor_observation/post_event_file. Short reference for constructor and common method signatures.async withfor async client; handleERClientExceptionand subclasses; timezone-aware times for filters;provider_keyfor sensors; large-read and rate-limit notes; link to EarthRanger docs.