Feat/better client module - #55
Conversation
- Added streaming request support in BaseApi for large file handling. - Improved error handling with ResourceNotFoundError in API requests. - Updated ApiConfig to include detailed attribute documentation. - Enhanced entity request methods for better clarity and functionality. - Adjusted entity serialization methods to suppress warnings for unknown fields.
- Added `Api` class to serve as the main API client, providing access to endpoint handlers. - Introduced `AnnotationsApi` and `ResourcesApi` classes for handling annotation and resource-related API calls. - Enhanced `BaseApi` with asynchronous request - Created `Annotation` and `Resource` entity models to represent data structures returned by the API. - Implemented methods for uploading resources, including support for DICOM files and metadata handling.
- Added `Api` class to replace `APIHandler` for improved API interactions. - Updated `ApiConfig` to use `server_url` instead of `base_url`. - Introduced `AnnotationsApi` and `ResourcesApi` with pagination support. - Implemented asynchronous methods for uploading segmentations and files. - Enhanced error handling and logging for better debugging. - Updated entity models to support optional fields and missing values. - Added DTOs for annotations to streamline data handling. - Refactored upload logic in `datamint_upload.py` to utilize new API structure.
…ersion functionalities
…and improved error handling - Added `upload_segmentations` method to `AnnotationsApi` for uploading segmentations with detailed parameter handling. - Refactored existing upload methods in `AnnotationsApi` to use a unified async request method. - Introduced `upload_resource` method in `ResourcesApi` for single file uploads, simplifying the interface. - Updated `upload_resources` to enforce multiple file uploads and improved parameter processing. - Enhanced error handling across API methods, ensuring exceptions are raised appropriately. - Improved documentation and examples in the API and notebooks for clarity and usability. - Bumped version to 2.0.0 to reflect significant changes and enhancements.
- Updated import paths for Annotation and DatasetInfo entities. - Modified the DatamintDataset class to use new image resizing method. - Added new DatasetInfo model for dataset representation. - Enhanced Annotation model with additional properties and methods for better usability. - Updated documentation to reflect changes in API class names and structure. - Removed deprecated Experiment class documentation and related examples. - Improved resource upload and management methods in the API client. - Adjusted API key setup instructions to align with new class structure.
Enhances API implementations by refining type annotations, improving parameter type handling, and addressing potential edge cases. Removes unused or commented-out code for better code clarity. Adds new methods to extend functionality, such as resource status updates and project retrieval with archived inclusion. Optimizes error handling for consistency and implements minor adjustments to payload processing. Improves dataset handling by supporting additional file types and ensuring compatibility with various formats.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a major architectural refactor to modernize the DataMint Python API client. It replaces the monolithic APIHandler class with a modular API client architecture that provides better separation of concerns and improved usability.
- Implements a new modular API client with dedicated endpoint handlers (
Api.resources,Api.projects, etc.) - Introduces Pydantic-based entity models for type safety and data validation
- Adds comprehensive base classes for consistent CRUD operations across endpoints
- Updates documentation, examples, and notebooks to use the new API structure
Reviewed Changes
Copilot reviewed 46 out of 48 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Version bump to 2.0.0 and updated dependencies |
| notebooks/upload_data.ipynb | Complete migration from APIHandler to new Api client with updated examples |
| docs/ | Documentation restructuring and updates for new API structure |
| datamint/entities/ | New Pydantic entity models for type-safe data handling |
| datamint/api/ | New modular API client architecture with base classes and endpoint handlers |
| datamint/dataset/ | Updated to use new API client and entity models |
| datamint/apihandler/ | Marked as deprecated with migration warnings |
Comments suppressed due to low confidence (4)
datamint/dataset/base_dataset.py:1
- Variable name has a typo:
last_updaded_atshould belast_updated_at.
import os
datamint/dataset/base_dataset.py:1
- Variable name has a typo:
last_updaded_atshould belast_updated_at(multiple occurrences).
import os
datamint/dataset/base_dataset.py:1
- Variable name has a typo:
last_updaded_atshould belast_updated_at(multiple occurrences).
import os
datamint/dataset/base_dataset.py:1
- Variable name has a typo:
last_updaded_atshould belast_updated_at(multiple occurrences).
import os
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| async def _upload_segmentations_async(self, | ||
| resource: str | Resource, | ||
| frame_index: int | Sequence [int] | None, |
There was a problem hiding this comment.
There's an extra space in the type annotation. It should be Sequence[int] instead of Sequence [int].
| frame_index: int | Sequence [int] | None, | |
| frame_index: int | Sequence[int] | None, |
| metadata=metadata_files, | ||
| progress_bar=True | ||
| ) | ||
| print('>>>', segfiles) |
There was a problem hiding this comment.
Debug print statement should be removed from production code. This appears to be leftover debugging code.
| print('>>>', segfiles) | |
| _LOGGER.debug(f"Segmentation files: {segfiles}") |
| if 'scope' not in converted_data: | ||
| converted_data['scope'] = 'image' if converted_data.get('frame_index') is None else 'frame' | ||
|
|
||
| if converted_data['annotation_type'] in ['segmentation']: |
There was a problem hiding this comment.
The list ['segmentation'] contains only one item. Consider using a simple string comparison == 'segmentation' for better readability and performance.
| if converted_data['annotation_type'] in ['segmentation']: | |
| if converted_data['annotation_type'] == 'segmentation': |
More intuitive use: All project-related functions are located at
api.projects.*