Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for bulk check of statuses #18

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.0] - 2024-08-20

### Added
- Support for request status bulk checks endpoint ([#18](https://github.com/neptune-ai/neptune-api/pull/18))

## [0.4.0] - 2024-08-13

### Added
Expand All @@ -25,7 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added initial package setup and OpenAPI client ([#1](https://github.com/neptune-ai/neptune-api/pull/1))

[unreleased]: https://github.com/neptune-ai/neptune-api/compare/0.4.0...HEAD
[unreleased]: https://github.com/neptune-ai/neptune-api/compare/0.5.0...HEAD
[0.5.0]: https://github.com/neptune-ai/neptune-api/compare/0.4.0...0.5.0
[0.4.0]: https://github.com/neptune-ai/neptune-api/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/neptune-ai/neptune-api/compare/0.2.0...0.3.0
[0.2.0]: https://github.com/neptune-ai/neptune-api/compare/0.1.0...0.2.0
Expand Down
1 change: 1 addition & 0 deletions scripts/preserve_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ neptune_api/credentials.py
neptune_api/auth_helpers.py
neptune_api/proto/
neptune_api/api/data_ingestion/check_request_status.py
neptune_api/api/data_ingestion/check_request_status_bulk.py
neptune_api/api/data_ingestion/submit_operation.py
2 changes: 1 addition & 1 deletion src/neptune_api/api/data_ingestion/check_request_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
AuthenticatedClient,
Client,
)
from neptune_api.proto.neptune_pb.ingest.v1.request_status_pb2 import RequestStatus
from neptune_api.proto.neptune_pb.ingest.v1.pub.request_status_pb2 import RequestStatus
from neptune_api.types import (
UNSET,
Response,
Expand Down
181 changes: 181 additions & 0 deletions src/neptune_api/api/data_ingestion/check_request_status_bulk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
from http import HTTPStatus
from typing import (
Any,
Dict,
Optional,
Union,
)

import httpx

from neptune_api import errors
from neptune_api.client import (
AuthenticatedClient,
Client,
)
from neptune_api.proto.neptune_pb.ingest.v1.pub.client_pb2 import (
BulkRequestStatus,
RequestIdList,
)
from neptune_api.types import Response


def _get_kwargs(
*,
body: RequestIdList,
project_identifier: str,
) -> Dict[str, Any]:
return {
"method": "post",
"url": "/api/client/v1/ingest/check",
"params": {
"projectIdentifier": project_identifier,
},
"content": body.SerializeToString(),
"headers": {
"Content-Type": "application/x-protobuf",
},
}


def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[BulkRequestStatus]:
if response.status_code == HTTPStatus.OK:
response_200 = BulkRequestStatus()
response_200.ParseFromString(response.content)

return response_200
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[BulkRequestStatus]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: AuthenticatedClient,
body: RequestIdList,
project_identifier: str,
) -> Response[BulkRequestStatus]:
"""Checks the processing status of multiple operations

Args:
project_identifier (str):
body (RequestIdList):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[BulkRequestStatus]
"""

kwargs = _get_kwargs(
body=body,
project_identifier=project_identifier,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
*,
client: AuthenticatedClient,
body: RequestIdList,
project_identifier: str,
) -> Optional[BulkRequestStatus]:
"""Checks the processing status of multiple operations

Args:
project_identifier (str):
body (RequestIdList):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
BulkRequestStatus
"""

return sync_detailed(
client=client,
body=body,
project_identifier=project_identifier,
).parsed


async def asyncio_detailed(
*,
client: AuthenticatedClient,
body: RequestIdList,
project_identifier: str,
) -> Response[BulkRequestStatus]:
"""Checks the processing status of multiple operations

Args:
project_identifier (str):
body (RequestIdList):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[BulkRequestStatus]
"""

kwargs = _get_kwargs(
body=body,
project_identifier=project_identifier,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
*,
client: AuthenticatedClient,
body: RequestIdList,
project_identifier: str,
) -> Optional[BulkRequestStatus]:
"""Checks the processing status of multiple operations

Args:
project_identifier (str):
body (RequestIdList):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
BulkRequestStatus
"""

return (
await asyncio_detailed(
client=client,
body=body,
project_identifier=project_identifier,
)
).parsed
4 changes: 4 additions & 0 deletions src/neptune_api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
"""Contains all the data models used in inputs/outputs"""

from .bulk_request_status import BulkRequestStatus
from .client_config import ClientConfig
from .client_versions_config_dto import ClientVersionsConfigDTO
from .error import Error
from .neptune_oauth_token import NeptuneOauthToken
from .project_dto import ProjectDTO
from .request_id import RequestId
from .request_id_list import RequestIdList
from .request_status import RequestStatus
from .run_operation import RunOperation
from .security_dto import SecurityDTO

__all__ = (
"BulkRequestStatus",
"ClientConfig",
"ClientVersionsConfigDTO",
"Error",
"NeptuneOauthToken",
"ProjectDTO",
"RequestId",
"RequestIdList",
"RequestStatus",
"RunOperation",
"SecurityDTO",
Expand Down
49 changes: 49 additions & 0 deletions src/neptune_api/models/bulk_request_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from typing import (
Any,
Dict,
List,
Type,
TypeVar,
)

from attrs import define as _attrs_define
from attrs import field as _attrs_field

T = TypeVar("T", bound="BulkRequestStatus")


@_attrs_define
class BulkRequestStatus:
""" """

additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
bulk_request_status = cls()

bulk_request_status.additional_properties = d
return bulk_request_status

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
49 changes: 49 additions & 0 deletions src/neptune_api/models/request_id_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from typing import (
Any,
Dict,
List,
Type,
TypeVar,
)

from attrs import define as _attrs_define
from attrs import field as _attrs_field

T = TypeVar("T", bound="RequestIdList")


@_attrs_define
class RequestIdList:
""" """

additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
request_id_list = cls()

request_id_list.additional_properties = d
return request_id_list

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
4 changes: 2 additions & 2 deletions src/neptune_api/proto/google_rpc/code_pb2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'google_rpc.code_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
_globals['DESCRIPTOR']._options = None
if not _descriptor._USE_C_DESCRIPTORS:
_globals['DESCRIPTOR']._loaded_options = None
_globals['DESCRIPTOR']._serialized_options = b'\n\x0ecom.google.rpcB\tCodeProtoP\x01Z3google.golang.org/genproto/googleapis/rpc/code;code\xa2\x02\x03RPC'
_globals['_CODE']._serialized_start = 38
_globals['_CODE']._serialized_end = 349
1 change: 0 additions & 1 deletion src/neptune_api/proto/neptune_pb/ingest/v1/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from . import request_status_pb2
from . import pub
from . import common_pb2
Loading
Loading