Skip to content

Python api tool v2#14

Open
petersenpeter wants to merge 3 commits intomainfrom
python_api_tool_v2
Open

Python api tool v2#14
petersenpeter wants to merge 3 commits intomainfrom
python_api_tool_v2

Conversation

@petersenpeter
Copy link
Copy Markdown
Collaborator

No description provided.

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 BrainstemClient to use device authorization + cached token, add retries/timeouts, add load_all auto-pagination, and add many load_* convenience loaders.
  • Add a brainstem CLI with login/logout/load/save/delete subcommands.
  • Migrate packaging metadata to pyproject.toml, remove setup.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.
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