From bca442d5b26a3077e7e1d6b4ded874f4ae8a0054 Mon Sep 17 00:00:00 2001 From: luandalmazo Date: Thu, 20 Aug 2026 11:20:00 -0300 Subject: [PATCH 1/2] removed channels api --- datamint/api/client.py | 6 ---- datamint/api/endpoints/__init__.py | 2 -- datamint/api/endpoints/channels_api.py | 31 ------------------- datamint/api/endpoints/resources_api.py | 29 ++++++++++++++++- datamint/entities/channel.py | 16 +++++----- docs/source/client_api_content.rst | 18 +++-------- docs/source/datamint.api.endpoints.rst | 8 ----- .../01_getting_started/01_upload_data.ipynb | 1 - tests/test_entity_pickling.py | 18 ----------- 9 files changed, 40 insertions(+), 89 deletions(-) delete mode 100644 datamint/api/endpoints/channels_api.py diff --git a/datamint/api/client.py b/datamint/api/client.py index 4e59d14a..ab7a6483 100644 --- a/datamint/api/client.py +++ b/datamint/api/client.py @@ -8,7 +8,6 @@ from .endpoints import ( AnnotationsApi, AnnotationWorklistApi, - ChannelsApi, DatasetsInfoApi, DeployModelApi, InferenceApi, @@ -29,7 +28,6 @@ class Api: 'projects': ProjectsApi, 'resources': ResourcesApi, 'annotations': AnnotationsApi, - 'channels': ChannelsApi, 'users': UsersApi, 'datasets': DatasetsInfoApi, 'models': ModelsApi, @@ -176,10 +174,6 @@ def resources(self) -> ResourcesApi: def annotations(self) -> AnnotationsApi: return self._get_endpoint('annotations') - @property - def channels(self) -> ChannelsApi: - return self._get_endpoint('channels') - @property def users(self) -> UsersApi: return self._get_endpoint('users') diff --git a/datamint/api/endpoints/__init__.py b/datamint/api/endpoints/__init__.py index a708a5e6..1d75b3f6 100644 --- a/datamint/api/endpoints/__init__.py +++ b/datamint/api/endpoints/__init__.py @@ -2,7 +2,6 @@ from .annotations_api import AnnotationsApi from .annotationsets_api import AnnotationWorklistApi -from .channels_api import ChannelsApi from .datasetsinfo_api import DatasetsInfoApi from .deploy_model_api import DeployModelApi from .inference_api import InferenceApi @@ -13,7 +12,6 @@ __all__ = [ 'AnnotationWorklistApi', 'AnnotationsApi', - 'ChannelsApi', 'DatasetsInfoApi', 'DeployModelApi', 'InferenceApi', diff --git a/datamint/api/endpoints/channels_api.py b/datamint/api/endpoints/channels_api.py deleted file mode 100644 index 26d66b3f..00000000 --- a/datamint/api/endpoints/channels_api.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Channels API endpoint for managing channel resources. - -This module provides functionality to interact with channels, -which are collections of resources grouped together for -batch processing or organization purposes. -""" - -import logging - -import httpx - -from datamint.entities.channel import Channel - -from ..entity_base_api import EntityBaseApi - -logger = logging.getLogger(__name__) - - -class ChannelsApi(EntityBaseApi[Channel]): - """API client for channel-related operations. - """ - - def __init__(self, config, client: httpx.Client | None = None) -> None: - """Initialize the Channels API client. - - Args: - config: API configuration containing base URL, API key, etc. - client: Optional HTTP client instance. If None, a new one will be created. - """ - super().__init__(config, Channel, 'resources/channels', client) diff --git a/datamint/api/endpoints/resources_api.py b/datamint/api/endpoints/resources_api.py index b791cdc7..6979b6b5 100644 --- a/datamint/api/endpoints/resources_api.py +++ b/datamint/api/endpoints/resources_api.py @@ -21,7 +21,7 @@ from pydicom import config as pydicom_config from tqdm.auto import tqdm -from datamint.entities import Project, Resource +from datamint.entities import Channel, Project, Resource from datamint.entities.annotations import AnnotationType from datamint.entities.annotations.annotation import Annotation from datamint.exceptions import ItemNotFoundError, ServerError, ValidationError @@ -1400,6 +1400,33 @@ def get_not_annotated(self, all_items.extend(items) return [self._init_entity_obj(**item) for item in all_items] + def list_channels(self, + limit: int | None = None, + **kwargs) -> list[Channel]: + """List upload channels. + + A channel is a grouping over resources (set via ``upload_channel`` + at upload time). + + Args: + limit: Maximum number of channels to return. + **kwargs: Additional query parameters forwarded to the endpoint + (e.g. ``project_name``). + + Returns: + List of Channel instances. + """ + params = {k: v for k, v in kwargs.items() if v is not None} + items_gen = self._make_request_with_pagination('GET', + f'/{self.endpoint_base}/channels', + return_field='channels', + limit=limit, + params=params or None) + all_items = [] + for _, items in items_gen: + all_items.extend(items) + return [Channel(**item) for item in all_items] + def rank_resources(self, resources: Sequence[Resource], score_fn: Callable[[Resource], float | None], diff --git a/datamint/entities/channel.py b/datamint/entities/channel.py index 51df3fc9..24d235c2 100644 --- a/datamint/entities/channel.py +++ b/datamint/entities/channel.py @@ -1,12 +1,10 @@ from pydantic import BaseModel, ConfigDict -from datamint.entities.base_entity import BaseEntity - class ChannelResourceData(BaseModel): """Represents resource data within a channel. - + Attributes: created_by: Email of the user who created the resource. customer_id: UUID of the customer. @@ -23,12 +21,12 @@ class ChannelResourceData(BaseModel): resource_mimetype: str -class Channel(BaseEntity): +class Channel(BaseModel): """Represents a channel containing multiple resources. - + A channel is a collection of resources grouped together, typically for batch processing or organization purposes. - + Attributes: channel_name: Name identifier for the channel. resource_data: List of resources contained in this channel. @@ -36,7 +34,9 @@ class Channel(BaseEntity): created_at: Timestamp when the channel was created. updated_at: Timestamp when the channel was last updated. """ - channel_name: str + model_config = ConfigDict(extra='allow') + + channel_name: str | None = None resource_data: list[ChannelResourceData] deleted: bool = False created_at: str | None = None @@ -44,4 +44,4 @@ class Channel(BaseEntity): def get_resource_ids(self) -> list[str]: """Get list of all resource IDs in this channel.""" - return [resource.resource_id for resource in self.resource_data] if self.resource_data else [] \ No newline at end of file + return [resource.resource_id for resource in self.resource_data] if self.resource_data else [] diff --git a/docs/source/client_api_content.rst b/docs/source/client_api_content.rst index 69aeff58..bc7f200c 100644 --- a/docs/source/client_api_content.rst +++ b/docs/source/client_api_content.rst @@ -20,8 +20,6 @@ The |ApiClass| class provides access to different endpoint handlers: +------------------------+--------------------------------------------------+ | ``api.projects`` | Organize resources into projects | +------------------------+--------------------------------------------------+ -| ``api.channels`` | Group resources by category | -+------------------------+--------------------------------------------------+ | ``api.models`` | Register and manage ML models | +------------------------+--------------------------------------------------+ | ``api.deploy`` | Deploy models | @@ -439,23 +437,15 @@ available with calls such as ``dataset.split(train=0.8, val=0.2, seed=42)``. Working with Channels --------------------- -Organize resources with channels -++++++++++++++++++++++++++++++++ +A channel is a grouping over resources, set via ``upload_channel`` at +upload time (see ``datamint upload --channel``), .. code-block:: python - # List all channels - channels = api.channels.get_list() + channels = api.resources.list_channels(project_name="MyProject") - # Create a new channel - api.channels.create(name="CT Scans", description="CT scan images") - - # List channels with resources for channel in channels: - print(channel.name, channel.resource_count) - - # Delete a channel - api.channels.delete(channel) + print(channel.channel_name, len(channel.get_resource_ids())) See also the tutorial notebooks: `upload_data.ipynb `_ diff --git a/docs/source/datamint.api.endpoints.rst b/docs/source/datamint.api.endpoints.rst index b5c6affa..0ad39fbf 100644 --- a/docs/source/datamint.api.endpoints.rst +++ b/docs/source/datamint.api.endpoints.rst @@ -27,14 +27,6 @@ Annotations API :undoc-members: :show-inheritance: -Channels API ------------- - -.. automodule:: datamint.api.endpoints.channels_api - :members: - :undoc-members: - :show-inheritance: - Users API --------- diff --git a/notebooks/01_getting_started/01_upload_data.ipynb b/notebooks/01_getting_started/01_upload_data.ipynb index 203815dc..24cb471e 100644 --- a/notebooks/01_getting_started/01_upload_data.ipynb +++ b/notebooks/01_getting_started/01_upload_data.ipynb @@ -36,7 +36,6 @@ "- `api.resources` - Resource management (upload, download, etc.)\n", "- `api.projects` - Project management and collaboration\n", "- `api.annotations` - Annotation handling and segmentations\n", - "- `api.channels` - Channel organization\n", "- `api.users` - User management\n", "\n", "Make sure you've run `datamint config` in your terminal first." diff --git a/tests/test_entity_pickling.py b/tests/test_entity_pickling.py index 9f107661..3922fe76 100644 --- a/tests/test_entity_pickling.py +++ b/tests/test_entity_pickling.py @@ -25,7 +25,6 @@ from datamint.entities.annotations.base_geometry import BaseGeometryAnnotation from datamint.entities.annotations.base_segmentation import BaseSegmentationAnnotation from datamint.entities.base_entity import BaseEntity, BaseEntityModel -from datamint.entities.channel import Channel, ChannelResourceData from datamint.entities.datasetinfo import DatasetInfo from datamint.entities.deployjob import DeployJob from datamint.entities.inferencejob import InferenceJob @@ -141,22 +140,6 @@ def _make_box_annotation() -> BoxAnnotation: ) -def _make_channel() -> Channel: - return Channel( - id='channel-1', - channel_name='uploads', - resource_data=[ - ChannelResourceData( - created_by='tester@datamint.io', - customer_id='customer-1', - resource_id='resource-1', - resource_file_name='scan.png', - resource_mimetype='image/png', - ) - ], - ) - - def _make_dataset_info() -> DatasetInfo: return DatasetInfo( id='dataset-1', @@ -336,7 +319,6 @@ def _make_sliced_video_resource() -> SlicedVideoResource: _ENTITY_FACTORIES: dict[type[object], Factory] = { Annotation: _make_annotation, BoxAnnotation: _make_box_annotation, - Channel: _make_channel, DatasetInfo: _make_dataset_info, DICOMResource: _make_dicom_resource, DeployJob: _make_deploy_job, From 601431b5a3cab4bc24d550e4da1283e5aa3ca2f1 Mon Sep 17 00:00:00 2001 From: luandalmazo Date: Thu, 20 Aug 2026 11:22:12 -0300 Subject: [PATCH 2/2] updated client_api_content channels desc --- docs/source/client_api_content.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/client_api_content.rst b/docs/source/client_api_content.rst index bc7f200c..35d7a0d5 100644 --- a/docs/source/client_api_content.rst +++ b/docs/source/client_api_content.rst @@ -437,11 +437,12 @@ available with calls such as ``dataset.split(train=0.8, val=0.2, seed=42)``. Working with Channels --------------------- -A channel is a grouping over resources, set via ``upload_channel`` at -upload time (see ``datamint upload --channel``), +A channel is just a grouping over resources, set via ``upload_channel`` at +upload time (see ``datamint upload --channel``). .. code-block:: python + # List channels (optionally scoped to a project) channels = api.resources.list_channels(project_name="MyProject") for channel in channels: