From 98831bc213b09bfbeb4a6c0533633b8d39f81543 Mon Sep 17 00:00:00 2001 From: lykmapipo Date: Tue, 23 Jun 2026 02:47:03 +0300 Subject: [PATCH] refactor: support Region usage across resources and loosen kwargs typing This: - Update `bulk_downloads`, `events`, and `fourwings` resources to support the `Region` - Refactor `**kwargs` type annotations from `Dict[str, Any]` to `Any` --- src/gfwapiclient/base/models.py | 2 +- .../resources/bulk_downloads/resources.py | 18 +++++------ .../resources/datasets/resources.py | 2 +- .../resources/events/resources.py | 24 +++++++-------- .../resources/fourwings/resources.py | 30 +++++++++---------- .../resources/insights/resources.py | 4 +-- .../resources/references/resources.py | 6 ++-- .../resources/vessels/resources.py | 6 ++-- 8 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/gfwapiclient/base/models.py b/src/gfwapiclient/base/models.py index 9a4b022..5eac440 100644 --- a/src/gfwapiclient/base/models.py +++ b/src/gfwapiclient/base/models.py @@ -347,7 +347,7 @@ def from_file_or_geojson( cls, *, source: Union[str, Path, Dict[str, Any], SupportsGeoJsonInterface], - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> Self: """Create a `GeoJson` instance from a spatial data source. diff --git a/src/gfwapiclient/resources/bulk_downloads/resources.py b/src/gfwapiclient/resources/bulk_downloads/resources.py index 249a4d9..ba7f04f 100644 --- a/src/gfwapiclient/resources/bulk_downloads/resources.py +++ b/src/gfwapiclient/resources/bulk_downloads/resources.py @@ -5,7 +5,7 @@ import pydantic -from gfwapiclient.base.models import GeoJson, Geometry, SupportsGeoJsonInterface +from gfwapiclient.base.models import GeoJson, Geometry, Region, SupportsGeoJsonInterface from gfwapiclient.exceptions import ( RequestBodyValidationError, RequestParamsValidationError, @@ -97,9 +97,9 @@ async def create_bulk_report( Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, format: Optional[Union[BulkReportFormat, str]] = None, - region: Optional[Union[BulkReportRegion, Dict[str, Any]]] = None, + region: Optional[Union[BulkReportRegion, Region, Dict[str, Any]]] = None, filters: Optional[List[str]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> BulkReportCreateResult: """Create a bulk report based on specified filters and spatial parameters. @@ -141,7 +141,7 @@ async def create_bulk_report( Allowed values: `"JSON"`, `"CSV"`. Example: `"JSON"`. - region (Optional[Union[BulkReportRegion, Dict[str, Any]]], default=None): + region (Optional[Union[BulkReportRegion, Region, Dict[str, Any]]], default=None): Predefined region information to filter the bulk report. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": 8466}`. @@ -242,7 +242,7 @@ async def get_all_bulk_reports( offset: Optional[int] = None, sort: Optional[str] = None, status: Optional[Union[BulkReportStatus, str]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> BulkReportListResult: """Get all bulk reports created by user or application. @@ -314,7 +314,7 @@ async def get_bulk_report_file_download_url( *, id: str, file: Optional[Union[BulkReportFileType, str]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> BulkReportFileResult: """Get signed URL to download file of the previously created bulk report. @@ -377,7 +377,7 @@ async def query_bulk_fixed_infrastructure_data_report( offset: Optional[int] = None, sort: Optional[str] = None, includes: Optional[List[str]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> BulkFixedInfrastructureDataQueryResult: """Get bulk fixed infrastructure data report in JSON Format. @@ -465,7 +465,7 @@ def _prepare_create_bulk_report_request_body( Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, format: Optional[Union[BulkReportFormat, str]] = None, - region: Optional[Union[BulkReportRegion, Dict[str, Any]]] = None, + region: Optional[Union[BulkReportRegion, Region, Dict[str, Any]]] = None, filters: Optional[List[str]] = None, ) -> BulkReportCreateBody: """Prepare and return create a bulk report request body.""" @@ -481,7 +481,7 @@ def _prepare_create_bulk_report_request_body( "dataset": _dataset, "geojson": _geojson, "format": format or BulkReportFormat.JSON, - "region": region or None, + "region": region.model_dump() if isinstance(region, Region) else region, "filters": filters or None, } request_body: BulkReportCreateBody = BulkReportCreateBody(**_request_body) diff --git a/src/gfwapiclient/resources/datasets/resources.py b/src/gfwapiclient/resources/datasets/resources.py index a8d4bc4..57ce8a0 100644 --- a/src/gfwapiclient/resources/datasets/resources.py +++ b/src/gfwapiclient/resources/datasets/resources.py @@ -34,7 +34,7 @@ async def get_sar_fixed_infrastructure( geometry: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> SARFixedInfrastructureResult: """Get SAR (Synthetic-aperture radar) fixed infrastructure data. diff --git a/src/gfwapiclient/resources/events/resources.py b/src/gfwapiclient/resources/events/resources.py index 913b893..57a7a8e 100644 --- a/src/gfwapiclient/resources/events/resources.py +++ b/src/gfwapiclient/resources/events/resources.py @@ -7,7 +7,7 @@ import pydantic -from gfwapiclient.base.models import GeoJson, Geometry, SupportsGeoJsonInterface +from gfwapiclient.base.models import GeoJson, Geometry, Region, SupportsGeoJsonInterface from gfwapiclient.exceptions.validation import ( RequestBodyValidationError, RequestParamsValidationError, @@ -72,11 +72,11 @@ async def get_all_events( geometry: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[EventRegion, Dict[str, Any]]] = None, + region: Optional[Union[EventRegion, Region, Dict[str, Any]]] = None, limit: Optional[int] = None, offset: Optional[int] = None, sort: Optional[str] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> EventListResult: """Get All Events. @@ -146,7 +146,7 @@ async def get_all_events( (e.g., JSON string or dictionary) or `GeoJson` model instance. Defaults to `None`. Example: `{"type": "Polygon", "coordinates": [...]}`, or `/path/to/your/custom/region.shp`. - region (Optional[Union[EventRegion, Dict[str, Any]]], default=None): + region (Optional[Union[EventRegion, Region, Dict[str, Any]]], default=None): Region to filter events. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": "5690"}`. @@ -215,7 +215,7 @@ async def get_event_by_id( *, id: str, dataset: Union[EventDataset, str], - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> EventDetailResult: """Get one by Event ID. @@ -278,9 +278,9 @@ async def get_events_stats( geometry: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[EventRegion, Dict[str, Any]]] = None, + region: Optional[Union[EventRegion, Region, Dict[str, Any]]] = None, includes: Optional[Union[List[EventStatsInclude], List[str]]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> EventStatsResult: """Get events statistics worldwide or for a specific region. @@ -353,7 +353,7 @@ async def get_events_stats( (e.g., JSON string or dictionary) or `GeoJson` model instance. Defaults to `None`. Example: `{"type": "Polygon", "coordinates": [...]}`, or `/path/to/your/custom/region.shp`. - region (Optional[Union[EventRegion, Dict[str, Any]]], default=None): + region (Optional[Union[EventRegion, Region, Dict[str, Any]]], default=None): Region to filter statistics. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": "5690"}`. @@ -442,7 +442,7 @@ def _prepare_get_all_events_request_body( geometry: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[EventRegion, Dict[str, Any]]] = None, + region: Optional[Union[EventRegion, Region, Dict[str, Any]]] = None, ) -> EventListBody: """Prepares and returns the request body for the get all events endpoint.""" try: @@ -462,7 +462,7 @@ def _prepare_get_all_events_request_body( "vessel_groups": vessel_groups, "flags": flags, "geometry": _geometry, - "region": region, + "region": region.model_dump() if isinstance(region, Region) else region, } request_body: EventListBody = EventListBody(**_request_body) except pydantic.ValidationError as exc: @@ -508,7 +508,7 @@ def _prepare_get_events_stats_request_body( geometry: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[EventRegion, Dict[str, Any]]] = None, + region: Optional[Union[EventRegion, Region, Dict[str, Any]]] = None, includes: Optional[Union[List[EventStatsInclude], List[str]]] = None, ) -> EventStatsBody: """Prepares and returns the request body for the get events statistics endpoint.""" @@ -530,7 +530,7 @@ def _prepare_get_events_stats_request_body( "vessel_groups": vessel_groups, "flags": flags, "geometry": _geometry, - "region": region, + "region": region.model_dump() if isinstance(region, Region) else region, "includes": includes, } request_body: EventStatsBody = EventStatsBody(**_request_body) diff --git a/src/gfwapiclient/resources/fourwings/resources.py b/src/gfwapiclient/resources/fourwings/resources.py index c2834b4..c501d6c 100644 --- a/src/gfwapiclient/resources/fourwings/resources.py +++ b/src/gfwapiclient/resources/fourwings/resources.py @@ -7,7 +7,7 @@ import pydantic -from gfwapiclient.base.models import GeoJson, SupportsGeoJsonInterface +from gfwapiclient.base.models import GeoJson, Region, SupportsGeoJsonInterface from gfwapiclient.exceptions import ( RequestBodyValidationError, RequestParamsValidationError, @@ -75,8 +75,8 @@ async def create_fishing_effort_report( geojson: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[FourWingsReportRegion, Dict[str, Any]]] = None, - **kwargs: Dict[str, Any], + region: Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]] = None, + **kwargs: Any, ) -> FourWingsReportResult: """Create 4Wings AIS apparent fishing effort report for a specified region. @@ -144,7 +144,7 @@ async def create_fishing_effort_report( (e.g., JSON string or dictionary) or `GeoJson` model instance. Defaults to `None`. Example: `{"type": "Polygon", "coordinates": [...]}`, or `/path/to/your/custom/region.shp`. - region (Optional[Union[FourWingsReportRegion, Dict[str, Any]]], default=None): + region (Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]], default=None): Predefined region information to filter the report. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": "5690"}`. @@ -198,8 +198,8 @@ async def create_ais_presence_report( geojson: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[FourWingsReportRegion, Dict[str, Any]]] = None, - **kwargs: Dict[str, Any], + region: Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]] = None, + **kwargs: Any, ) -> FourWingsReportResult: """Create 4Wings AIS vessel presence report for a specified region. @@ -267,7 +267,7 @@ async def create_ais_presence_report( (e.g., JSON string or dictionary) or `GeoJson` model instance. Defaults to `None`. Example: `{"type": "Polygon", "coordinates": [...]}`, or `/path/to/your/custom/region.shp`. - region (Optional[Union[FourWingsReportRegion, Dict[str, Any]]], default=None): + region (Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]], default=None): Predefined region information to filter the report. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": "5690"}`. @@ -321,8 +321,8 @@ async def create_sar_presence_report( geojson: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[FourWingsReportRegion, Dict[str, Any]]] = None, - **kwargs: Dict[str, Any], + region: Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]] = None, + **kwargs: Any, ) -> FourWingsReportResult: """Create 4Wings SAR vessel detections report for a specified region. @@ -389,7 +389,7 @@ async def create_sar_presence_report( (e.g., JSON string or dictionary) or `GeoJson` model instance. Defaults to `None`. Example: `{"type": "Polygon", "coordinates": [...]}`, or `/path/to/your/custom/region.shp`. - region (Optional[Union[FourWingsReportRegion, Dict[str, Any]]], default=None): + region (Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]], default=None): Predefined region information to filter the report. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": "5690"}`. @@ -445,8 +445,8 @@ async def create_report( geojson: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[FourWingsReportRegion, Dict[str, Any]]] = None, - **kwargs: Dict[str, Any], + region: Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]] = None, + **kwargs: Any, ) -> FourWingsReportResult: """Create 4Wings report for a specified region. @@ -540,7 +540,7 @@ async def create_report( (e.g., JSON string or dictionary) or `GeoJson` model instance. Defaults to `None`. Example: `{"type": "Polygon", "coordinates": [...]}`, or `/path/to/your/custom/region.shp`. - region (Optional[Union[FourWingsReportRegion, Dict[str, Any]]], default=None): + region (Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]], default=None): Predefined region information to filter the report. Defaults to `None`. Example: `{"dataset": "public-eez-areas", "id": "5690"}`. @@ -594,7 +594,7 @@ def _prepare_create_report_request_body( geojson: Optional[ Union[GeoJson, str, Path, Dict[str, Any], SupportsGeoJsonInterface] ] = None, - region: Optional[Union[FourWingsReportRegion, Dict[str, Any]]] = None, + region: Optional[Union[FourWingsReportRegion, Region, Dict[str, Any]]] = None, ) -> FourWingsReportBody: """Prepare request body for the 4Wings report endpoint.""" try: @@ -603,7 +603,7 @@ def _prepare_create_report_request_body( ) _request_body: Dict[str, Any] = { "geojson": _geojson, - "region": region, + "region": region.model_dump() if isinstance(region, Region) else region, } request_body: FourWingsReportBody = FourWingsReportBody(**_request_body) except pydantic.ValidationError as exc: diff --git a/src/gfwapiclient/resources/insights/resources.py b/src/gfwapiclient/resources/insights/resources.py index 6193afa..120d0d9 100644 --- a/src/gfwapiclient/resources/insights/resources.py +++ b/src/gfwapiclient/resources/insights/resources.py @@ -55,7 +55,7 @@ async def get_vessel_insights( vessels: Union[ List[VesselInsightDatasetVessel], List[Dict[str, Any]], List[str] ], - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> VesselInsightResult: """Get insights for one or several vessels. @@ -163,7 +163,7 @@ def _prepare_get_vessel_insights_request_body( vessels: Union[ List[VesselInsightDatasetVessel], List[Dict[str, Any]], List[str] ], - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> VesselInsightBody: """Prepare and returns get vessel insights request body.""" try: diff --git a/src/gfwapiclient/resources/references/resources.py b/src/gfwapiclient/resources/references/resources.py index ef61a0d..7de0ee1 100644 --- a/src/gfwapiclient/resources/references/resources.py +++ b/src/gfwapiclient/resources/references/resources.py @@ -77,7 +77,7 @@ async def get_eez_regions( Union[str, Pattern[str], List[str], List[Pattern[str]]] ] = None, predicate: Optional[Callable[[EEZRegionItem], bool]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> EEZRegionResult: """Get available Exclusive Economic Zone (EEZ) regions data. @@ -178,7 +178,7 @@ async def get_mpa_regions( id: Optional[Union[str, Pattern[str], List[str], List[Pattern[str]]]] = None, label: Optional[Union[str, Pattern[str], List[str], List[Pattern[str]]]] = None, predicate: Optional[Callable[[MPARegionItem], bool]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> MPARegionResult: """Get available Marine Protected Area (MPA) regions data. @@ -246,7 +246,7 @@ async def get_rfmo_regions( id: Optional[Union[str, Pattern[str], List[str], List[Pattern[str]]]] = None, label: Optional[Union[str, Pattern[str], List[str], List[Pattern[str]]]] = None, predicate: Optional[Callable[[RFMORegionItem], bool]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> RFMORegionResult: """Get available Regional Fisheries Management Organization (RFMO) regions data. diff --git a/src/gfwapiclient/resources/vessels/resources.py b/src/gfwapiclient/resources/vessels/resources.py index 7d50cd0..4d34316 100644 --- a/src/gfwapiclient/resources/vessels/resources.py +++ b/src/gfwapiclient/resources/vessels/resources.py @@ -70,7 +70,7 @@ async def search_vessels( where: Optional[str] = None, match_fields: Optional[Union[List[VesselMatchField], List[str]]] = None, includes: Optional[Union[List[VesselSearchInclude], List[str]]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> VesselSearchResult: """Search vessels based on provided parameters. @@ -163,7 +163,7 @@ async def get_vessels_by_ids( includes: Optional[List[VesselInclude]] = None, match_fields: Optional[List[VesselMatchField]] = None, vessel_groups: Optional[List[str]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> VesselListResult: """Get a list of vessels by their IDs. @@ -258,7 +258,7 @@ async def get_vessel_by_id( registries_info_data: Optional[Union[VesselRegistryInfoData, str]] = None, includes: Optional[Union[List[VesselInclude], List[str]]] = None, match_fields: Optional[Union[List[VesselMatchField], List[str]]] = None, - **kwargs: Dict[str, Any], + **kwargs: Any, ) -> VesselDetailResult: """Get vessel details by ID.