Skip to content
Open
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.6.0"
".": "0.7.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 49
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech%2Fneptune-api-v2-05e0ec4b9b945a8c8e3542d34f0759f4eed2046a37750700fd40619f8a0cd6d7.yml
configured_endpoints: 50
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech/neptune-api-v2-55bfdf6d48920a09ac1c9566abf3b62b4c8b5af0de51e38bcda32c1fd68357ef.yml
openapi_spec_hash: 3911018927f898449898cc6cc5685273
config_hash: f5ca3bc259f95069f0db4114d34e29ef
config_hash: fdcc5ae6c783dda7176ace266f7ad0fd
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 0.7.0 (2026-05-09)

Full Changelog: [v0.6.0...v0.7.0](https://github.com/cryptechdev/neptune-api-v2-python/compare/v0.6.0...v0.7.0)

### Features

* support setting headers via env ([b5ef889](https://github.com/cryptechdev/neptune-api-v2-python/commit/b5ef88979d72f7a372f340502025a1be6c69216d))


### Bug Fixes

* **client:** add missing f-string prefix in file type error message ([305e8fe](https://github.com/cryptechdev/neptune-api-v2-python/commit/305e8fe198c890cb71ee05a3eddb4c8e6d2a19f0))
* use correct field name format for multipart file arrays ([e892969](https://github.com/cryptechdev/neptune-api-v2-python/commit/e892969e96a26dd08f61f88dac7812e73df8e16e))


### Performance Improvements

* **client:** optimize file structure copying in multipart requests ([e3b4463](https://github.com/cryptechdev/neptune-api-v2-python/commit/e3b44635c279a772f8626572cd192601b0b4d62f))


### Chores

* **internal:** fix ([6d99eaa](https://github.com/cryptechdev/neptune-api-v2-python/commit/6d99eaacc946f60cc38e251e74d3df1878c85231))
* **internal:** more robust bootstrap script ([f0b98d2](https://github.com/cryptechdev/neptune-api-v2-python/commit/f0b98d296af0176f85591c6a2cabd1a32bcb56ec))
* **internal:** reformat pyproject.toml ([9434760](https://github.com/cryptechdev/neptune-api-v2-python/commit/94347608eb5c9304bec7a087ad631a453186b421))

## 0.6.0 (2026-04-17)

Full Changelog: [v0.5.0...v0.6.0](https://github.com/cryptechdev/neptune-api-v2-python/compare/v0.5.0...v0.6.0)
Expand Down
8 changes: 8 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ Types:
from neptune_api_v2.types import (
GlobalMarketConfig,
MarketRate,
MarketSupplyPool,
MergedMarket,
Tvl,
MarketGetMergedResponse,
MarketGetMergedByAssetResponse,
MarketGetOverviewResponse,
MarketGetParamsResponse,
MarketGetSupplyResponse,
)
```

Expand All @@ -77,6 +79,7 @@ Methods:
- <code title="get /api/v1/markets/merged/lookup">client.markets.<a href="./src/neptune_api_v2/resources/markets/markets.py">get_merged_by_asset</a>(\*\*<a href="src/neptune_api_v2/types/market_get_merged_by_asset_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/market_get_merged_by_asset_response.py">MarketGetMergedByAssetResponse</a></code>
- <code title="get /api/v1/markets">client.markets.<a href="./src/neptune_api_v2/resources/markets/markets.py">get_overview</a>(\*\*<a href="src/neptune_api_v2/types/market_get_overview_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/market_get_overview_response.py">MarketGetOverviewResponse</a></code>
- <code title="get /api/v1/markets/config">client.markets.<a href="./src/neptune_api_v2/resources/markets/markets.py">get_params</a>(\*\*<a href="src/neptune_api_v2/types/market_get_params_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/market_get_params_response.py">MarketGetParamsResponse</a></code>
- <code title="get /api/v1/markets/supply">client.markets.<a href="./src/neptune_api_v2/resources/markets/markets.py">get_supply</a>(\*\*<a href="src/neptune_api_v2/types/market_get_supply_params.py">params</a>) -> <a href="./src/neptune_api_v2/types/market_get_supply_response.py">MarketGetSupplyResponse</a></code>

## Lend

Expand All @@ -87,6 +90,8 @@ from neptune_api_v2.types.markets import (
LendMarket,
LendMarketData,
LendMarketState,
LendMarketSupply,
LendOverview,
LendListResponse,
LendGetByAssetResponse,
LendGetRateHistoryResponse,
Expand Down Expand Up @@ -125,6 +130,8 @@ from neptune_api_v2.types.markets.borrow import (
BorrowCollateralConfig,
BorrowCollateralMarket,
BorrowCollateralMarketData,
BorrowCollateralMarketSupply,
BorrowCollateralOverview,
BorrowCollateralState,
CollateralListResponse,
CollateralGetByAssetResponse,
Expand All @@ -145,6 +152,7 @@ from neptune_api_v2.types.markets.borrow import (
BorrowDebtConfig,
BorrowDebtMarket,
BorrowDebtMarketData,
BorrowDebtOverview,
BorrowDebtState,
DebtListResponse,
DebtGetByAssetResponse,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "neptune_api_v2"
version = "0.6.0"
version = "0.7.0"
description = "The official Python library for the neptune-api-v2 API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -154,7 +154,7 @@ show_error_codes = true
#
# We also exclude our `tests` as mypy doesn't always infer
# types correctly and Pyright will still catch any type errors.
exclude = ['src/neptune_api_v2/_files.py', '_dev/.*.py', 'tests/.*']
exclude = ["src/neptune_api_v2/_files.py", "_dev/.*.py", "tests/.*"]

strict_equality = true
implicit_reexport = true
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

cd "$(dirname "$0")/.."

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then
brew bundle check >/dev/null 2>&1 || {
echo -n "==> Install Homebrew dependencies? (y/N): "
read -r response
Expand Down
24 changes: 23 additions & 1 deletion src/neptune_api_v2/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
RequestOptions,
not_given,
)
from ._utils import is_given, get_async_library
from ._utils import (
is_given,
is_mapping_t,
get_async_library,
)
from ._compat import cached_property
from ._version import __version__
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
Expand Down Expand Up @@ -83,6 +87,15 @@ def __init__(
if base_url is None:
base_url = f"https://api-v2.nept.finance"

custom_headers_env = os.environ.get("NEPTUNE_API_V2_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down Expand Up @@ -272,6 +285,15 @@ def __init__(
if base_url is None:
base_url = f"https://api-v2.nept.finance"

custom_headers_env = os.environ.get("NEPTUNE_API_V2_CUSTOM_HEADERS")
if custom_headers_env is not None:
parsed: dict[str, str] = {}
for line in custom_headers_env.split("\n"):
colon = line.find(":")
if colon >= 0:
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}

super().__init__(
version=__version__,
base_url=base_url,
Expand Down
58 changes: 54 additions & 4 deletions src/neptune_api_v2/_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import io
import os
import pathlib
from typing import overload
from typing_extensions import TypeGuard
from typing import Sequence, cast, overload
from typing_extensions import TypeVar, TypeGuard

import anyio

Expand All @@ -17,7 +17,9 @@
HttpxFileContent,
HttpxRequestFiles,
)
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t
from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t

_T = TypeVar("_T")


def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
Expand Down Expand Up @@ -97,7 +99,7 @@ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles
elif is_sequence_t(files):
files = [(key, await _async_transform_file(file)) for key, file in files]
else:
raise TypeError("Unexpected file type input {type(files)}, expected mapping or sequence")
raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence")

return files

Expand All @@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
return await anyio.Path(file).read_bytes()

return file


def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T:
"""Copy only the containers along the given paths.

Used to guard against mutation by extract_files without copying the entire structure.
Only dicts and lists that lie on a path are copied; everything else
is returned by reference.

For example, given paths=[["foo", "files", "file"]] and the structure:
{
"foo": {
"bar": {"baz": {}},
"files": {"file": <content>}
}
}
The root dict, "foo", and "files" are copied (they lie on the path).
"bar" and "baz" are returned by reference (off the path).
"""
return _deepcopy_with_paths(item, paths, 0)


def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:
if not paths:
return item
if is_mapping(item):
key_to_paths: dict[str, list[Sequence[str]]] = {}
for path in paths:
if index < len(path):
key_to_paths.setdefault(path[index], []).append(path)

# if no path continues through this mapping, it won't be mutated and copying it is redundant
if not key_to_paths:
return item

result = dict(item)
for key, subpaths in key_to_paths.items():
if key in result:
result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1)
return cast(_T, result)
if is_list(item):
array_paths = [path for path in paths if index < len(path) and path[index] == "<array>"]

# if no path expects a list here, nothing will be mutated inside it - return by reference
if not array_paths:
return cast(_T, item)
return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item])
return item
8 changes: 2 additions & 6 deletions src/neptune_api_v2/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

from typing import Any, List, Tuple, Union, Mapping, TypeVar
from urllib.parse import parse_qs, urlencode
from typing_extensions import Literal, get_args
from typing_extensions import get_args

from ._types import NotGiven, not_given
from ._types import NotGiven, ArrayFormat, NestedFormat, not_given
from ._utils import flatten

_T = TypeVar("_T")


ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]

PrimitiveData = Union[str, int, float, bool, None]
# this should be Data = Union[PrimitiveData, "List[Data]", "Tuple[Data]", "Mapping[str, Data]"]
# https://github.com/microsoft/pyright/issues/3555
Expand Down
3 changes: 3 additions & 0 deletions src/neptune_api_v2/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
ModelT = TypeVar("ModelT", bound=pydantic.BaseModel)
_T = TypeVar("_T")

ArrayFormat = Literal["comma", "repeat", "indices", "brackets"]
NestedFormat = Literal["dots", "brackets"]


# Approximates httpx internal ProxiesTypes and RequestFiles types
# while adding support for `PathLike` instances
Expand Down
1 change: 0 additions & 1 deletion src/neptune_api_v2/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
coerce_integer as coerce_integer,
file_from_path as file_from_path,
strip_not_given as strip_not_given,
deepcopy_minimal as deepcopy_minimal,
get_async_library as get_async_library,
maybe_coerce_float as maybe_coerce_float,
get_required_header as get_required_header,
Expand Down
Loading
Loading