Open
Conversation
Replace password auth with a browser-based device authorization flow and persistent token caching (~/.config/brainstem/token). Export AuthenticationError and modernize BrainstemClient: session-backed requests, unified load/save/delete methods, auto-pagination (load_all), query param handling (filters/sort/include/limit/offset), model→app routing table, and many convenience loaders (load_project/subject/session/... ). Add a command-line interface (brainstem entrypoint), update README and tutorial for new usage, add pyproject.toml (remove setup.py), and include comprehensive unit tests for client behavior and auth flow.
Introduce request retries and a DEFAULT_TIMEOUT applied to all HTTP calls, add timeout parameters to get/post/patch/delete, and raise AuthenticationError on 401 during paginated loads. Add device auth polling timeout (max_wait), context-manager support (__enter__/__exit__), and validation for unknown kwargs in _convenience_load; change many convenience loader offsets to default to None. Add numerous new convenience loader helpers (procedurelog, subjectlog, equipment, consumablestock, behavioralassay, datastorage, setup, hardwaredevice, brainregion, species, strain, publication, laboratory). Bump package __version__ to 2.0.0 and require requests>=2.28, update tutorial to use placeholder UUIDs, add comprehensive unit tests for timeouts, auth polling, context manager, loader validation and new loaders, and add a GitHub Actions workflow to run tests on push/PR across Python versions.
There was a problem hiding this comment.
Pull request overview
This PR introduces “v2” of the BrainSTEM Python API tools by modernizing packaging, switching authentication to a browser-based device flow with token caching, expanding the client API (pagination + convenience loaders), and adding a CLI + CI test workflow.
Changes:
- Refactor
BrainstemClientto use device authorization + cached token, add retries/timeouts, addload_allauto-pagination, and add manyload_*convenience loaders. - Add a
brainstemCLI with login/logout/load/save/delete subcommands. - Migrate packaging metadata to
pyproject.toml, removesetup.py, and add a GitHub Actions test workflow plus a comprehensive unit test suite.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
brainstem_api_tools/brainstem_api_client.py |
New v2 client: model routing table, device auth, token caching, pagination, convenience loaders |
brainstem_api_tools/cli.py |
New CLI entrypoint for auth + CRUD commands |
brainstem_api_tools/__init__.py |
Export updates + package version |
tests/test_client.py |
New unit tests covering client behaviors and CLI flows |
pyproject.toml |
PEP 621 metadata + dependencies + console script definition |
setup.py |
Removed legacy packaging configuration |
README.md |
Updated docs for device auth, new API methods, and CLI usage |
brainstem_api_tutorial.py |
Tutorial updated to load/save/delete, pagination, convenience loaders |
brainstem_api_tutorial.ipynb |
Notebook updated similarly (auth + load/save/delete + pagination) |
.github/workflows/tests.yml |
Add CI to run pytest across multiple Python versions |
tests/__init__.py |
Test package marker |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Enforce and clarify pagination/parameter behavior and fix CLI parser inheritance. - brainstem_api_client: always pass options to _build_url; disallow load_all=True when an id is provided; raise a clear ValueError if auto-pagination expects a list but the API response contains no list-valued key; change filter merging to include falsy values (check for None instead of truthiness). - cli: make the logout subparser inherit common arguments (parents=[common]). - tests: set mocked response.status_code to 200 for pagination tests. - README: remove the Contributing section. These changes make load_all usage safer and errors clearer, ensure logout CLI gets shared options, and update tests to better mock HTTP responses.
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.
No description provided.