Skip to content

Commit bc8d441

Browse files
authored
Bundle neptune-api 0.26.0 inside neptune-query (#175)
* Copy code from neptune-api 0.26.0 to src/neptune_query/generated/neptune_api/ * Update nq code to use the bundled neptune_api rather than one from PyPI * formatting fix
1 parent e060a65 commit bc8d441

File tree

153 files changed

+13683
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+13683
-96
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
exclude: ^src/neptune_query/generated/
12
repos:
23
- repo: https://github.com/pre-commit/pre-commit-hooks
34
rev: v6.0.0

pyproject.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ pattern = "default-unprefixed"
1111
[tool.poetry.dependencies]
1212
python = "^3.10"
1313

14-
# Base neptune package
15-
neptune-api = ">=0.26.0,<0.27.0"
1614
azure-storage-blob = "^12.7.0"
1715
pandas = ">=1.4.0"
1816

17+
# neptune-api dependencies:
18+
httpx = { version = ">=0.15.4,<0.28.2", extras = ["http2"] }
19+
attrs = ">=21.3.0"
20+
python-dateutil = "^2.8.0"
21+
PyJWT = "^2.0.0"
22+
protobuf = ">=4.21.1,<7"
23+
1924
# Optional for default progress update handling
2025
tqdm = { version = ">=4.66.0" }
2126

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2025, Neptune Labs Sp. z o.o.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""A client library for accessing Neptune Leaderboard REST API"""
17+
18+
from .client import (
19+
AuthenticatedClient,
20+
Client,
21+
)
22+
23+
__all__ = (
24+
"AuthenticatedClient",
25+
"Client",
26+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2025, Neptune Labs Sp. z o.o.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
"""Contains methods for accessing the API"""
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2025, Neptune Labs Sp. z o.o.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#
2+
# Copyright (c) 2025, Neptune Labs Sp. z o.o.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from http import HTTPStatus
17+
from typing import (
18+
Any,
19+
Dict,
20+
Optional,
21+
Union,
22+
cast,
23+
)
24+
25+
import httpx
26+
27+
from ... import errors
28+
from ...client import (
29+
AuthenticatedClient,
30+
Client,
31+
)
32+
from ...models.error import Error
33+
from ...models.neptune_oauth_token import NeptuneOauthToken
34+
from ...types import Response
35+
36+
37+
def _get_kwargs(
38+
*,
39+
x_neptune_api_token: str,
40+
) -> Dict[str, Any]:
41+
headers: Dict[str, Any] = {}
42+
headers["X-Neptune-Api-Token"] = x_neptune_api_token
43+
44+
_kwargs: Dict[str, Any] = {
45+
"method": "get",
46+
"url": "/api/backend/v1/authorization/oauth-token",
47+
}
48+
49+
_kwargs["headers"] = headers
50+
return _kwargs
51+
52+
53+
def _parse_response(
54+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
55+
) -> Optional[Union[Any, Error, NeptuneOauthToken]]:
56+
try:
57+
if response.status_code == HTTPStatus.OK:
58+
response_200 = NeptuneOauthToken.from_dict(response.json())
59+
60+
return response_200
61+
if response.status_code == HTTPStatus.BAD_REQUEST:
62+
response_400 = Error.from_dict(response.json())
63+
64+
return response_400
65+
if response.status_code == HTTPStatus.UNAUTHORIZED:
66+
response_401 = cast(Any, None)
67+
return response_401
68+
if response.status_code == HTTPStatus.FORBIDDEN:
69+
response_403 = cast(Any, None)
70+
return response_403
71+
if response.status_code == HTTPStatus.NOT_FOUND:
72+
response_404 = cast(Any, None)
73+
return response_404
74+
if response.status_code == HTTPStatus.REQUEST_TIMEOUT:
75+
response_408 = cast(Any, None)
76+
return response_408
77+
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
78+
response_422 = cast(Any, None)
79+
return response_422
80+
except Exception as e:
81+
raise errors.UnableToParseResponse(e, response) from e
82+
83+
if client.raise_on_unexpected_status:
84+
raise errors.UnexpectedStatus(response.status_code, response.content)
85+
else:
86+
return None
87+
88+
89+
def _build_response(
90+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
91+
) -> Response[Union[Any, Error, NeptuneOauthToken]]:
92+
return Response(
93+
status_code=HTTPStatus(response.status_code),
94+
content=response.content,
95+
headers=response.headers,
96+
parsed=_parse_response(client=client, response=response),
97+
)
98+
99+
100+
def sync_detailed(
101+
*,
102+
client: AuthenticatedClient,
103+
x_neptune_api_token: str,
104+
) -> Response[Union[Any, Error, NeptuneOauthToken]]:
105+
"""
106+
Args:
107+
x_neptune_api_token (str):
108+
109+
Raises:
110+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
111+
httpx.TimeoutException: If the request takes longer than Client.timeout.
112+
113+
Returns:
114+
Response[Union[Any, Error, NeptuneOauthToken]]
115+
"""
116+
117+
kwargs = _get_kwargs(
118+
x_neptune_api_token=x_neptune_api_token,
119+
)
120+
121+
response = client.get_httpx_client().request(
122+
**kwargs,
123+
)
124+
125+
return _build_response(client=client, response=response)
126+
127+
128+
def sync(
129+
*,
130+
client: AuthenticatedClient,
131+
x_neptune_api_token: str,
132+
) -> Optional[Union[Any, Error, NeptuneOauthToken]]:
133+
"""
134+
Args:
135+
x_neptune_api_token (str):
136+
137+
Raises:
138+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
139+
httpx.TimeoutException: If the request takes longer than Client.timeout.
140+
141+
Returns:
142+
Union[Any, Error, NeptuneOauthToken]
143+
"""
144+
145+
return sync_detailed(
146+
client=client,
147+
x_neptune_api_token=x_neptune_api_token,
148+
).parsed
149+
150+
151+
async def asyncio_detailed(
152+
*,
153+
client: AuthenticatedClient,
154+
x_neptune_api_token: str,
155+
) -> Response[Union[Any, Error, NeptuneOauthToken]]:
156+
"""
157+
Args:
158+
x_neptune_api_token (str):
159+
160+
Raises:
161+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
162+
httpx.TimeoutException: If the request takes longer than Client.timeout.
163+
164+
Returns:
165+
Response[Union[Any, Error, NeptuneOauthToken]]
166+
"""
167+
168+
kwargs = _get_kwargs(
169+
x_neptune_api_token=x_neptune_api_token,
170+
)
171+
172+
response = await client.get_async_httpx_client().request(**kwargs)
173+
174+
return _build_response(client=client, response=response)
175+
176+
177+
async def asyncio(
178+
*,
179+
client: AuthenticatedClient,
180+
x_neptune_api_token: str,
181+
) -> Optional[Union[Any, Error, NeptuneOauthToken]]:
182+
"""
183+
Args:
184+
x_neptune_api_token (str):
185+
186+
Raises:
187+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
188+
httpx.TimeoutException: If the request takes longer than Client.timeout.
189+
190+
Returns:
191+
Union[Any, Error, NeptuneOauthToken]
192+
"""
193+
194+
return (
195+
await asyncio_detailed(
196+
client=client,
197+
x_neptune_api_token=x_neptune_api_token,
198+
)
199+
).parsed

0 commit comments

Comments
 (0)