From 6d99eaacc946f60cc38e251e74d3df1878c85231 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 00:12:44 -0400 Subject: [PATCH 1/9] chore(internal): fix --- .stats.yml | 4 +- api.md | 8 + .../resources/markets/markets.py | 90 ++++++++ src/neptune_api_v2/types/__init__.py | 3 + .../types/market_get_overview_response.py | 51 +---- .../types/market_get_supply_params.py | 12 ++ .../types/market_get_supply_response.py | 40 ++++ .../types/market_supply_pool.py | 36 ++++ src/neptune_api_v2/types/markets/__init__.py | 2 + .../types/markets/borrow/__init__.py | 3 + .../borrow/borrow_collateral_market_supply.py | 20 ++ .../borrow/borrow_collateral_overview.py | 19 ++ .../markets/borrow/borrow_debt_overview.py | 19 ++ .../borrow/collateral_list_response.py | 143 +------------ .../markets/borrow/debt_list_response.py | 49 +---- .../types/markets/borrow_market_overview.py | 192 +----------------- .../types/markets/lend_list_response.py | 44 +--- .../types/markets/lend_market_supply.py | 31 +++ .../types/markets/lend_overview.py | 19 ++ tests/api_resources/test_markets.py | 73 +++++++ 20 files changed, 394 insertions(+), 464 deletions(-) create mode 100644 src/neptune_api_v2/types/market_get_supply_params.py create mode 100644 src/neptune_api_v2/types/market_get_supply_response.py create mode 100644 src/neptune_api_v2/types/market_supply_pool.py create mode 100644 src/neptune_api_v2/types/markets/borrow/borrow_collateral_market_supply.py create mode 100644 src/neptune_api_v2/types/markets/borrow/borrow_collateral_overview.py create mode 100644 src/neptune_api_v2/types/markets/borrow/borrow_debt_overview.py create mode 100644 src/neptune_api_v2/types/markets/lend_market_supply.py create mode 100644 src/neptune_api_v2/types/markets/lend_overview.py diff --git a/.stats.yml b/.stats.yml index 01f7b9a..fa4911e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 49 +configured_endpoints: 50 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech%2Fneptune-api-v2-05e0ec4b9b945a8c8e3542d34f0759f4eed2046a37750700fd40619f8a0cd6d7.yml openapi_spec_hash: 3911018927f898449898cc6cc5685273 -config_hash: f5ca3bc259f95069f0db4114d34e29ef +config_hash: fdcc5ae6c783dda7176ace266f7ad0fd diff --git a/api.md b/api.md index 43d3bea..732afe5 100644 --- a/api.md +++ b/api.md @@ -62,12 +62,14 @@ Types: from neptune_api_v2.types import ( GlobalMarketConfig, MarketRate, + MarketSupplyPool, MergedMarket, Tvl, MarketGetMergedResponse, MarketGetMergedByAssetResponse, MarketGetOverviewResponse, MarketGetParamsResponse, + MarketGetSupplyResponse, ) ``` @@ -77,6 +79,7 @@ Methods: - client.markets.get_merged_by_asset(\*\*params) -> MarketGetMergedByAssetResponse - client.markets.get_overview(\*\*params) -> MarketGetOverviewResponse - client.markets.get_params(\*\*params) -> MarketGetParamsResponse +- client.markets.get_supply(\*\*params) -> MarketGetSupplyResponse ## Lend @@ -87,6 +90,8 @@ from neptune_api_v2.types.markets import ( LendMarket, LendMarketData, LendMarketState, + LendMarketSupply, + LendOverview, LendListResponse, LendGetByAssetResponse, LendGetRateHistoryResponse, @@ -125,6 +130,8 @@ from neptune_api_v2.types.markets.borrow import ( BorrowCollateralConfig, BorrowCollateralMarket, BorrowCollateralMarketData, + BorrowCollateralMarketSupply, + BorrowCollateralOverview, BorrowCollateralState, CollateralListResponse, CollateralGetByAssetResponse, @@ -145,6 +152,7 @@ from neptune_api_v2.types.markets.borrow import ( BorrowDebtConfig, BorrowDebtMarket, BorrowDebtMarketData, + BorrowDebtOverview, BorrowDebtState, DebtListResponse, DebtGetByAssetResponse, diff --git a/src/neptune_api_v2/resources/markets/markets.py b/src/neptune_api_v2/resources/markets/markets.py index 95d3787..20bd8d9 100644 --- a/src/neptune_api_v2/resources/markets/markets.py +++ b/src/neptune_api_v2/resources/markets/markets.py @@ -15,6 +15,7 @@ from ...types import ( market_get_merged_params, market_get_params_params, + market_get_supply_params, market_get_overview_params, market_get_merged_by_asset_params, ) @@ -39,6 +40,7 @@ from ..._base_client import make_request_options from ...types.market_get_merged_response import MarketGetMergedResponse from ...types.market_get_params_response import MarketGetParamsResponse +from ...types.market_get_supply_response import MarketGetSupplyResponse from ...types.market_get_overview_response import MarketGetOverviewResponse from ...types.market_get_merged_by_asset_response import MarketGetMergedByAssetResponse @@ -252,6 +254,43 @@ def get_params( cast_to=MarketGetParamsResponse, ) + def get_supply( + self, + *, + with_text: bool | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> MarketGetSupplyResponse: + """ + Get market supply + + Args: + with_text: Include text variation fields + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return self._get( + "/api/v1/markets/supply", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=maybe_transform({"with_text": with_text}, market_get_supply_params.MarketGetSupplyParams), + ), + cast_to=MarketGetSupplyResponse, + ) + class AsyncMarketsResource(AsyncAPIResource): @cached_property @@ -462,6 +501,45 @@ async def get_params( cast_to=MarketGetParamsResponse, ) + async def get_supply( + self, + *, + with_text: bool | Omit = omit, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = not_given, + ) -> MarketGetSupplyResponse: + """ + Get market supply + + Args: + with_text: Include text variation fields + + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + return await self._get( + "/api/v1/markets/supply", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + query=await async_maybe_transform( + {"with_text": with_text}, market_get_supply_params.MarketGetSupplyParams + ), + ), + cast_to=MarketGetSupplyResponse, + ) + class MarketsResourceWithRawResponse: def __init__(self, markets: MarketsResource) -> None: @@ -479,6 +557,9 @@ def __init__(self, markets: MarketsResource) -> None: self.get_params = to_raw_response_wrapper( markets.get_params, ) + self.get_supply = to_raw_response_wrapper( + markets.get_supply, + ) @cached_property def lend(self) -> LendResourceWithRawResponse: @@ -505,6 +586,9 @@ def __init__(self, markets: AsyncMarketsResource) -> None: self.get_params = async_to_raw_response_wrapper( markets.get_params, ) + self.get_supply = async_to_raw_response_wrapper( + markets.get_supply, + ) @cached_property def lend(self) -> AsyncLendResourceWithRawResponse: @@ -531,6 +615,9 @@ def __init__(self, markets: MarketsResource) -> None: self.get_params = to_streamed_response_wrapper( markets.get_params, ) + self.get_supply = to_streamed_response_wrapper( + markets.get_supply, + ) @cached_property def lend(self) -> LendResourceWithStreamingResponse: @@ -557,6 +644,9 @@ def __init__(self, markets: AsyncMarketsResource) -> None: self.get_params = async_to_streamed_response_wrapper( markets.get_params, ) + self.get_supply = async_to_streamed_response_wrapper( + markets.get_supply, + ) @cached_property def lend(self) -> AsyncLendResourceWithStreamingResponse: diff --git a/src/neptune_api_v2/types/__init__.py b/src/neptune_api_v2/types/__init__.py index c9c2909..6f00c0f 100644 --- a/src/neptune_api_v2/types/__init__.py +++ b/src/neptune_api_v2/types/__init__.py @@ -20,6 +20,7 @@ from .asset_metadata import AssetMetadata as AssetMetadata from .staking_pool_full import StakingPoolFull as StakingPoolFull from .asset_rate_history import AssetRateHistory as AssetRateHistory +from .market_supply_pool import MarketSupplyPool as MarketSupplyPool from .staking_pool_state import StakingPoolState as StakingPoolState from .asset_list_response import AssetListResponse as AssetListResponse from .asset_price_history import AssetPriceHistory as AssetPriceHistory @@ -35,11 +36,13 @@ from .asset_list_prices_params import AssetListPricesParams as AssetListPricesParams from .market_get_merged_params import MarketGetMergedParams as MarketGetMergedParams from .market_get_params_params import MarketGetParamsParams as MarketGetParamsParams +from .market_get_supply_params import MarketGetSupplyParams as MarketGetSupplyParams from .nept_get_params_response import NeptGetParamsResponse as NeptGetParamsResponse from .asset_list_prices_response import AssetListPricesResponse as AssetListPricesResponse from .market_get_merged_response import MarketGetMergedResponse as MarketGetMergedResponse from .market_get_overview_params import MarketGetOverviewParams as MarketGetOverviewParams from .market_get_params_response import MarketGetParamsResponse as MarketGetParamsResponse +from .market_get_supply_response import MarketGetSupplyResponse as MarketGetSupplyResponse from .user_get_tx_history_params import UserGetTxHistoryParams as UserGetTxHistoryParams from .market_get_overview_response import MarketGetOverviewResponse as MarketGetOverviewResponse from .status_check_health_response import StatusCheckHealthResponse as StatusCheckHealthResponse diff --git a/src/neptune_api_v2/types/market_get_overview_response.py b/src/neptune_api_v2/types/market_get_overview_response.py index 9531826..72ae565 100644 --- a/src/neptune_api_v2/types/market_get_overview_response.py +++ b/src/neptune_api_v2/types/market_get_overview_response.py @@ -1,57 +1,12 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional - from .tvl import Tvl from .._models import BaseModel -from .markets.lend_market import LendMarket from .global_market_config import GlobalMarketConfig +from .markets.lend_overview import LendOverview from .markets.borrow_market_overview import BorrowMarketOverview -__all__ = [ - "MarketGetOverviewResponse", - "Data", - "DataLend", - "DataLendSupply", - "DataLendSupplyExtra", - "DataLendSupplyExtraText", -] - - -class DataLendSupplyExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - principal: str - - -class DataLendSupplyExtra(BaseModel): - text: Optional[DataLendSupplyExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DataLendSupply(BaseModel): - """Supply breakdown for lending markets""" - - extra: DataLendSupplyExtra - - principal: str - """Sum USD value of lending principal""" - - -class DataLend(BaseModel): - """Lending markets overview""" - - contents: List[LendMarket] - """Lending markets""" - - supply: DataLendSupply - """Supply breakdown for lending markets""" +__all__ = ["MarketGetOverviewResponse", "Data"] class Data(BaseModel): @@ -61,7 +16,7 @@ class Data(BaseModel): global_config: GlobalMarketConfig """Market runtime parameters""" - lend: DataLend + lend: LendOverview """Lending markets overview""" tvl: Tvl diff --git a/src/neptune_api_v2/types/market_get_supply_params.py b/src/neptune_api_v2/types/market_get_supply_params.py new file mode 100644 index 0000000..e0455ba --- /dev/null +++ b/src/neptune_api_v2/types/market_get_supply_params.py @@ -0,0 +1,12 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import TypedDict + +__all__ = ["MarketGetSupplyParams"] + + +class MarketGetSupplyParams(TypedDict, total=False): + with_text: bool + """Include text variation fields""" diff --git a/src/neptune_api_v2/types/market_get_supply_response.py b/src/neptune_api_v2/types/market_get_supply_response.py new file mode 100644 index 0000000..057dce0 --- /dev/null +++ b/src/neptune_api_v2/types/market_get_supply_response.py @@ -0,0 +1,40 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .tvl import Tvl +from .._models import BaseModel +from .market_supply_pool import MarketSupplyPool +from .markets.lend_market_supply import LendMarketSupply +from .markets.borrow.borrow_collateral_market_supply import BorrowCollateralMarketSupply + +__all__ = ["MarketGetSupplyResponse", "Data"] + + +class Data(BaseModel): + borrow_collateral: BorrowCollateralMarketSupply + """Borrowing market supply - collaterals""" + + borrow_debt: MarketSupplyPool + """Borrowing market supply - debts""" + + lend: LendMarketSupply + """Lending market supply""" + + tvl: Tvl + """Market TVL""" + + +class MarketGetSupplyResponse(BaseModel): + data: Data + + error: None = None + """Error data. Guaranteed `null` for successful response.""" + + status: int + """HTTP status. + + Successful responses are guaranteed to be < `400`. Conversely, error responses + are guaranteed to be >= `400`. + """ + + status_text: str + """HTTP status text""" diff --git a/src/neptune_api_v2/types/market_supply_pool.py b/src/neptune_api_v2/types/market_supply_pool.py new file mode 100644 index 0000000..9f32101 --- /dev/null +++ b/src/neptune_api_v2/types/market_supply_pool.py @@ -0,0 +1,36 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from .._models import BaseModel + +__all__ = ["MarketSupplyPool", "Extra", "ExtraText"] + + +class ExtraText(BaseModel): + """Human-readable field variants. + + Will not be null when query param `with_text` is `true`. + """ + + balance: str + + shares: str + + +class Extra(BaseModel): + text: Optional[ExtraText] = None + """Human-readable field variants. + + Will not be null when query param `with_text` is `true`. + """ + + +class MarketSupplyPool(BaseModel): + balance: str + """Sum USD value of market balance""" + + extra: Extra + + shares: str + """Sum USD value of market shares""" diff --git a/src/neptune_api_v2/types/markets/__init__.py b/src/neptune_api_v2/types/markets/__init__.py index d64c771..ce8b749 100644 --- a/src/neptune_api_v2/types/markets/__init__.py +++ b/src/neptune_api_v2/types/markets/__init__.py @@ -3,10 +3,12 @@ from __future__ import annotations from .lend_market import LendMarket as LendMarket +from .lend_overview import LendOverview as LendOverview from .lend_list_params import LendListParams as LendListParams from .lend_market_data import LendMarketData as LendMarketData from .lend_market_state import LendMarketState as LendMarketState from .lend_list_response import LendListResponse as LendListResponse +from .lend_market_supply import LendMarketSupply as LendMarketSupply from .borrow_market_overview import BorrowMarketOverview as BorrowMarketOverview from .lend_get_by_asset_params import LendGetByAssetParams as LendGetByAssetParams from .borrow_get_overview_params import BorrowGetOverviewParams as BorrowGetOverviewParams diff --git a/src/neptune_api_v2/types/markets/borrow/__init__.py b/src/neptune_api_v2/types/markets/borrow/__init__.py index 221b631..dc915d7 100644 --- a/src/neptune_api_v2/types/markets/borrow/__init__.py +++ b/src/neptune_api_v2/types/markets/borrow/__init__.py @@ -7,6 +7,7 @@ from .borrow_debt_config import BorrowDebtConfig as BorrowDebtConfig from .borrow_debt_market import BorrowDebtMarket as BorrowDebtMarket from .debt_list_response import DebtListResponse as DebtListResponse +from .borrow_debt_overview import BorrowDebtOverview as BorrowDebtOverview from .collateral_list_params import CollateralListParams as CollateralListParams from .borrow_collateral_state import BorrowCollateralState as BorrowCollateralState from .borrow_debt_market_data import BorrowDebtMarketData as BorrowDebtMarketData @@ -14,7 +15,9 @@ from .borrow_collateral_market import BorrowCollateralMarket as BorrowCollateralMarket from .collateral_list_response import CollateralListResponse as CollateralListResponse from .debt_get_by_asset_params import DebtGetByAssetParams as DebtGetByAssetParams +from .borrow_collateral_overview import BorrowCollateralOverview as BorrowCollateralOverview from .debt_get_by_asset_response import DebtGetByAssetResponse as DebtGetByAssetResponse from .borrow_collateral_market_data import BorrowCollateralMarketData as BorrowCollateralMarketData from .collateral_get_by_asset_params import CollateralGetByAssetParams as CollateralGetByAssetParams +from .borrow_collateral_market_supply import BorrowCollateralMarketSupply as BorrowCollateralMarketSupply from .collateral_get_by_asset_response import CollateralGetByAssetResponse as CollateralGetByAssetResponse diff --git a/src/neptune_api_v2/types/markets/borrow/borrow_collateral_market_supply.py b/src/neptune_api_v2/types/markets/borrow/borrow_collateral_market_supply.py new file mode 100644 index 0000000..44646e3 --- /dev/null +++ b/src/neptune_api_v2/types/markets/borrow/borrow_collateral_market_supply.py @@ -0,0 +1,20 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from ...._models import BaseModel +from ...market_supply_pool import MarketSupplyPool + +__all__ = ["BorrowCollateralMarketSupply"] + + +class BorrowCollateralMarketSupply(BaseModel): + non_receipt: MarketSupplyPool + """Supply of all collaterals (excluding receipt tokens)""" + + receipt: MarketSupplyPool + """Supply of receipt token collaterals""" + + total: MarketSupplyPool + """Total supply for collaterals, regardless of type. + + Equivalent to `non_receipt + receipt` + """ diff --git a/src/neptune_api_v2/types/markets/borrow/borrow_collateral_overview.py b/src/neptune_api_v2/types/markets/borrow/borrow_collateral_overview.py new file mode 100644 index 0000000..4731558 --- /dev/null +++ b/src/neptune_api_v2/types/markets/borrow/borrow_collateral_overview.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List + +from ...._models import BaseModel +from .borrow_collateral_market import BorrowCollateralMarket +from .borrow_collateral_market_supply import BorrowCollateralMarketSupply + +__all__ = ["BorrowCollateralOverview"] + + +class BorrowCollateralOverview(BaseModel): + """Borrowing market collaterals overview""" + + contents: List[BorrowCollateralMarket] + """Borrowing collateral markets""" + + supply: BorrowCollateralMarketSupply + """Supply breakdown for collaterals""" diff --git a/src/neptune_api_v2/types/markets/borrow/borrow_debt_overview.py b/src/neptune_api_v2/types/markets/borrow/borrow_debt_overview.py new file mode 100644 index 0000000..56e8dae --- /dev/null +++ b/src/neptune_api_v2/types/markets/borrow/borrow_debt_overview.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List + +from ...._models import BaseModel +from .borrow_debt_market import BorrowDebtMarket +from ...market_supply_pool import MarketSupplyPool + +__all__ = ["BorrowDebtOverview"] + + +class BorrowDebtOverview(BaseModel): + """Borrowing market debts overview""" + + contents: List[BorrowDebtMarket] + """Borrowing debt markets""" + + supply: MarketSupplyPool + """Supply breakdown for debt markets""" diff --git a/src/neptune_api_v2/types/markets/borrow/collateral_list_response.py b/src/neptune_api_v2/types/markets/borrow/collateral_list_response.py index 5a8afc5..6812228 100644 --- a/src/neptune_api_v2/types/markets/borrow/collateral_list_response.py +++ b/src/neptune_api_v2/types/markets/borrow/collateral_list_response.py @@ -1,150 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional - from ...._models import BaseModel -from .borrow_collateral_market import BorrowCollateralMarket - -__all__ = [ - "CollateralListResponse", - "Data", - "DataSupply", - "DataSupplyNonReceipt", - "DataSupplyNonReceiptExtra", - "DataSupplyNonReceiptExtraText", - "DataSupplyReceipt", - "DataSupplyReceiptExtra", - "DataSupplyReceiptExtraText", - "DataSupplyTotal", - "DataSupplyTotalExtra", - "DataSupplyTotalExtraText", -] - - -class DataSupplyNonReceiptExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class DataSupplyNonReceiptExtra(BaseModel): - text: Optional[DataSupplyNonReceiptExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DataSupplyNonReceipt(BaseModel): - """Supply of all collaterals (excluding receipt tokens)""" - - balance: str - """Sum USD value of market balance""" - - extra: DataSupplyNonReceiptExtra - - shares: str - """Sum USD value of market shares""" - - -class DataSupplyReceiptExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class DataSupplyReceiptExtra(BaseModel): - text: Optional[DataSupplyReceiptExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DataSupplyReceipt(BaseModel): - """Supply of receipt token collaterals""" - - balance: str - """Sum USD value of market balance""" - - extra: DataSupplyReceiptExtra - - shares: str - """Sum USD value of market shares""" - - -class DataSupplyTotalExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class DataSupplyTotalExtra(BaseModel): - text: Optional[DataSupplyTotalExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DataSupplyTotal(BaseModel): - """Total supply for collaterals, regardless of type. - - Equivalent to `non_receipt + receipt` - """ - - balance: str - """Sum USD value of market balance""" - - extra: DataSupplyTotalExtra - - shares: str - """Sum USD value of market shares""" - - -class DataSupply(BaseModel): - """Supply breakdown for collaterals""" - - non_receipt: DataSupplyNonReceipt - """Supply of all collaterals (excluding receipt tokens)""" - - receipt: DataSupplyReceipt - """Supply of receipt token collaterals""" - - total: DataSupplyTotal - """Total supply for collaterals, regardless of type. - - Equivalent to `non_receipt + receipt` - """ - - -class Data(BaseModel): - """Borrowing market collaterals overview""" - - contents: List[BorrowCollateralMarket] - """Borrowing collateral markets""" +from .borrow_collateral_overview import BorrowCollateralOverview - supply: DataSupply - """Supply breakdown for collaterals""" +__all__ = ["CollateralListResponse"] class CollateralListResponse(BaseModel): - data: Data + data: BorrowCollateralOverview """Borrowing market collaterals overview""" error: None = None diff --git a/src/neptune_api_v2/types/markets/borrow/debt_list_response.py b/src/neptune_api_v2/types/markets/borrow/debt_list_response.py index 0ba0ba5..6e6b2a3 100644 --- a/src/neptune_api_v2/types/markets/borrow/debt_list_response.py +++ b/src/neptune_api_v2/types/markets/borrow/debt_list_response.py @@ -1,56 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional - from ...._models import BaseModel -from .borrow_debt_market import BorrowDebtMarket - -__all__ = ["DebtListResponse", "Data", "DataSupply", "DataSupplyExtra", "DataSupplyExtraText"] - - -class DataSupplyExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class DataSupplyExtra(BaseModel): - text: Optional[DataSupplyExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DataSupply(BaseModel): - """Supply breakdown for debt markets""" - - balance: str - """Sum USD value of market balance""" - - extra: DataSupplyExtra - - shares: str - """Sum USD value of market shares""" - - -class Data(BaseModel): - """Borrowing market debts overview""" - - contents: List[BorrowDebtMarket] - """Borrowing debt markets""" +from .borrow_debt_overview import BorrowDebtOverview - supply: DataSupply - """Supply breakdown for debt markets""" +__all__ = ["DebtListResponse"] class DebtListResponse(BaseModel): - data: Data + data: BorrowDebtOverview """Borrowing market debts overview""" error: None = None diff --git a/src/neptune_api_v2/types/markets/borrow_market_overview.py b/src/neptune_api_v2/types/markets/borrow_market_overview.py index 16131a6..bde7dc4 100644 --- a/src/neptune_api_v2/types/markets/borrow_market_overview.py +++ b/src/neptune_api_v2/types/markets/borrow_market_overview.py @@ -1,197 +1,15 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional - from ..._models import BaseModel -from .borrow.borrow_debt_market import BorrowDebtMarket -from .borrow.borrow_collateral_market import BorrowCollateralMarket - -__all__ = [ - "BorrowMarketOverview", - "Collaterals", - "CollateralsSupply", - "CollateralsSupplyNonReceipt", - "CollateralsSupplyNonReceiptExtra", - "CollateralsSupplyNonReceiptExtraText", - "CollateralsSupplyReceipt", - "CollateralsSupplyReceiptExtra", - "CollateralsSupplyReceiptExtraText", - "CollateralsSupplyTotal", - "CollateralsSupplyTotalExtra", - "CollateralsSupplyTotalExtraText", - "Debts", - "DebtsSupply", - "DebtsSupplyExtra", - "DebtsSupplyExtraText", -] - - -class CollateralsSupplyNonReceiptExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class CollateralsSupplyNonReceiptExtra(BaseModel): - text: Optional[CollateralsSupplyNonReceiptExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class CollateralsSupplyNonReceipt(BaseModel): - """Supply of all collaterals (excluding receipt tokens)""" - - balance: str - """Sum USD value of market balance""" - - extra: CollateralsSupplyNonReceiptExtra - - shares: str - """Sum USD value of market shares""" - - -class CollateralsSupplyReceiptExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class CollateralsSupplyReceiptExtra(BaseModel): - text: Optional[CollateralsSupplyReceiptExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class CollateralsSupplyReceipt(BaseModel): - """Supply of receipt token collaterals""" - - balance: str - """Sum USD value of market balance""" - - extra: CollateralsSupplyReceiptExtra - - shares: str - """Sum USD value of market shares""" - - -class CollateralsSupplyTotalExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class CollateralsSupplyTotalExtra(BaseModel): - text: Optional[CollateralsSupplyTotalExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class CollateralsSupplyTotal(BaseModel): - """Total supply for collaterals, regardless of type. - - Equivalent to `non_receipt + receipt` - """ - - balance: str - """Sum USD value of market balance""" - - extra: CollateralsSupplyTotalExtra - - shares: str - """Sum USD value of market shares""" - - -class CollateralsSupply(BaseModel): - """Supply breakdown for collaterals""" - - non_receipt: CollateralsSupplyNonReceipt - """Supply of all collaterals (excluding receipt tokens)""" - - receipt: CollateralsSupplyReceipt - """Supply of receipt token collaterals""" - - total: CollateralsSupplyTotal - """Total supply for collaterals, regardless of type. - - Equivalent to `non_receipt + receipt` - """ - - -class Collaterals(BaseModel): - """Borrowing market collaterals overview""" - - contents: List[BorrowCollateralMarket] - """Borrowing collateral markets""" - - supply: CollateralsSupply - """Supply breakdown for collaterals""" - - -class DebtsSupplyExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - balance: str - - shares: str - - -class DebtsSupplyExtra(BaseModel): - text: Optional[DebtsSupplyExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DebtsSupply(BaseModel): - """Supply breakdown for debt markets""" - - balance: str - """Sum USD value of market balance""" - - extra: DebtsSupplyExtra - - shares: str - """Sum USD value of market shares""" - - -class Debts(BaseModel): - """Borrowing market debts overview""" - - contents: List[BorrowDebtMarket] - """Borrowing debt markets""" +from .borrow.borrow_debt_overview import BorrowDebtOverview +from .borrow.borrow_collateral_overview import BorrowCollateralOverview - supply: DebtsSupply - """Supply breakdown for debt markets""" +__all__ = ["BorrowMarketOverview"] class BorrowMarketOverview(BaseModel): - collaterals: Collaterals + collaterals: BorrowCollateralOverview """Borrowing market collaterals overview""" - debts: Debts + debts: BorrowDebtOverview """Borrowing market debts overview""" diff --git a/src/neptune_api_v2/types/markets/lend_list_response.py b/src/neptune_api_v2/types/markets/lend_list_response.py index a5612ec..2589ba1 100644 --- a/src/neptune_api_v2/types/markets/lend_list_response.py +++ b/src/neptune_api_v2/types/markets/lend_list_response.py @@ -1,51 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional - from ..._models import BaseModel -from .lend_market import LendMarket - -__all__ = ["LendListResponse", "Data", "DataSupply", "DataSupplyExtra", "DataSupplyExtraText"] - - -class DataSupplyExtraText(BaseModel): - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - principal: str - - -class DataSupplyExtra(BaseModel): - text: Optional[DataSupplyExtraText] = None - """Human-readable field variants. - - Will not be null when query param `with_text` is `true`. - """ - - -class DataSupply(BaseModel): - """Supply breakdown for lending markets""" - - extra: DataSupplyExtra - - principal: str - """Sum USD value of lending principal""" - - -class Data(BaseModel): - """Lending markets overview""" - - contents: List[LendMarket] - """Lending markets""" +from .lend_overview import LendOverview - supply: DataSupply - """Supply breakdown for lending markets""" +__all__ = ["LendListResponse"] class LendListResponse(BaseModel): - data: Data + data: LendOverview """Lending markets overview""" error: None = None diff --git a/src/neptune_api_v2/types/markets/lend_market_supply.py b/src/neptune_api_v2/types/markets/lend_market_supply.py new file mode 100644 index 0000000..b74e412 --- /dev/null +++ b/src/neptune_api_v2/types/markets/lend_market_supply.py @@ -0,0 +1,31 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from ..._models import BaseModel + +__all__ = ["LendMarketSupply", "Extra", "ExtraText"] + + +class ExtraText(BaseModel): + """Human-readable field variants. + + Will not be null when query param `with_text` is `true`. + """ + + principal: str + + +class Extra(BaseModel): + text: Optional[ExtraText] = None + """Human-readable field variants. + + Will not be null when query param `with_text` is `true`. + """ + + +class LendMarketSupply(BaseModel): + extra: Extra + + principal: str + """Sum USD value of lending principal""" diff --git a/src/neptune_api_v2/types/markets/lend_overview.py b/src/neptune_api_v2/types/markets/lend_overview.py new file mode 100644 index 0000000..b00eff9 --- /dev/null +++ b/src/neptune_api_v2/types/markets/lend_overview.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List + +from ..._models import BaseModel +from .lend_market import LendMarket +from .lend_market_supply import LendMarketSupply + +__all__ = ["LendOverview"] + + +class LendOverview(BaseModel): + """Lending markets overview""" + + contents: List[LendMarket] + """Lending markets""" + + supply: LendMarketSupply + """Supply breakdown for lending markets""" diff --git a/tests/api_resources/test_markets.py b/tests/api_resources/test_markets.py index 0a5f4cf..c3ca26e 100644 --- a/tests/api_resources/test_markets.py +++ b/tests/api_resources/test_markets.py @@ -12,6 +12,7 @@ from neptune_api_v2.types import ( MarketGetMergedResponse, MarketGetParamsResponse, + MarketGetSupplyResponse, MarketGetOverviewResponse, MarketGetMergedByAssetResponse, ) @@ -176,6 +177,42 @@ def test_streaming_response_get_params(self, client: NeptuneAPIV2) -> None: assert cast(Any, response.is_closed) is True + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_get_supply(self, client: NeptuneAPIV2) -> None: + market = client.markets.get_supply() + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_method_get_supply_with_all_params(self, client: NeptuneAPIV2) -> None: + market = client.markets.get_supply( + with_text=True, + ) + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_raw_response_get_supply(self, client: NeptuneAPIV2) -> None: + response = client.markets.with_raw_response.get_supply() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + market = response.parse() + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + def test_streaming_response_get_supply(self, client: NeptuneAPIV2) -> None: + with client.markets.with_streaming_response.get_supply() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + market = response.parse() + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + assert cast(Any, response.is_closed) is True + class TestAsyncMarkets: parametrize = pytest.mark.parametrize( @@ -335,3 +372,39 @@ async def test_streaming_response_get_params(self, async_client: AsyncNeptuneAPI assert_matches_type(MarketGetParamsResponse, market, path=["response"]) assert cast(Any, response.is_closed) is True + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_get_supply(self, async_client: AsyncNeptuneAPIV2) -> None: + market = await async_client.markets.get_supply() + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_method_get_supply_with_all_params(self, async_client: AsyncNeptuneAPIV2) -> None: + market = await async_client.markets.get_supply( + with_text=True, + ) + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_raw_response_get_supply(self, async_client: AsyncNeptuneAPIV2) -> None: + response = await async_client.markets.with_raw_response.get_supply() + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + market = await response.parse() + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + @pytest.mark.skip(reason="Mock server tests are disabled") + @parametrize + async def test_streaming_response_get_supply(self, async_client: AsyncNeptuneAPIV2) -> None: + async with async_client.markets.with_streaming_response.get_supply() as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + market = await response.parse() + assert_matches_type(MarketGetSupplyResponse, market, path=["response"]) + + assert cast(Any, response.is_closed) is True From e3b44635c279a772f8626572cd192601b0b4d62f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 18 Apr 2026 05:45:33 +0000 Subject: [PATCH 2/9] perf(client): optimize file structure copying in multipart requests --- src/neptune_api_v2/_files.py | 56 ++++++++++++++- src/neptune_api_v2/_utils/__init__.py | 1 - src/neptune_api_v2/_utils/_utils.py | 15 ---- tests/test_deepcopy.py | 58 ---------------- tests/test_files.py | 99 ++++++++++++++++++++++++++- 5 files changed, 151 insertions(+), 78 deletions(-) delete mode 100644 tests/test_deepcopy.py diff --git a/src/neptune_api_v2/_files.py b/src/neptune_api_v2/_files.py index cc14c14..0fdce17 100644 --- a/src/neptune_api_v2/_files.py +++ b/src/neptune_api_v2/_files.py @@ -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 @@ -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]: @@ -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": } + } + } + 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] == ""] + + # 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 diff --git a/src/neptune_api_v2/_utils/__init__.py b/src/neptune_api_v2/_utils/__init__.py index 10cb66d..1c090e5 100644 --- a/src/neptune_api_v2/_utils/__init__.py +++ b/src/neptune_api_v2/_utils/__init__.py @@ -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, diff --git a/src/neptune_api_v2/_utils/_utils.py b/src/neptune_api_v2/_utils/_utils.py index 63b8cd6..771859f 100644 --- a/src/neptune_api_v2/_utils/_utils.py +++ b/src/neptune_api_v2/_utils/_utils.py @@ -177,21 +177,6 @@ def is_iterable(obj: object) -> TypeGuard[Iterable[object]]: return isinstance(obj, Iterable) -def deepcopy_minimal(item: _T) -> _T: - """Minimal reimplementation of copy.deepcopy() that will only copy certain object types: - - - mappings, e.g. `dict` - - list - - This is done for performance reasons. - """ - if is_mapping(item): - return cast(_T, {k: deepcopy_minimal(v) for k, v in item.items()}) - if is_list(item): - return cast(_T, [deepcopy_minimal(entry) for entry in item]) - return item - - # copied from https://github.com/Rapptz/RoboDanny def human_join(seq: Sequence[str], *, delim: str = ", ", final: str = "or") -> str: size = len(seq) diff --git a/tests/test_deepcopy.py b/tests/test_deepcopy.py deleted file mode 100644 index 9b46a9d..0000000 --- a/tests/test_deepcopy.py +++ /dev/null @@ -1,58 +0,0 @@ -from neptune_api_v2._utils import deepcopy_minimal - - -def assert_different_identities(obj1: object, obj2: object) -> None: - assert obj1 == obj2 - assert id(obj1) != id(obj2) - - -def test_simple_dict() -> None: - obj1 = {"foo": "bar"} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - - -def test_nested_dict() -> None: - obj1 = {"foo": {"bar": True}} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1["foo"], obj2["foo"]) - - -def test_complex_nested_dict() -> None: - obj1 = {"foo": {"bar": [{"hello": "world"}]}} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1["foo"], obj2["foo"]) - assert_different_identities(obj1["foo"]["bar"], obj2["foo"]["bar"]) - assert_different_identities(obj1["foo"]["bar"][0], obj2["foo"]["bar"][0]) - - -def test_simple_list() -> None: - obj1 = ["a", "b", "c"] - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - - -def test_nested_list() -> None: - obj1 = ["a", [1, 2, 3]] - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert_different_identities(obj1[1], obj2[1]) - - -class MyObject: ... - - -def test_ignores_other_types() -> None: - # custom classes - my_obj = MyObject() - obj1 = {"foo": my_obj} - obj2 = deepcopy_minimal(obj1) - assert_different_identities(obj1, obj2) - assert obj1["foo"] is my_obj - - # tuples - obj3 = ("a", "b") - obj4 = deepcopy_minimal(obj3) - assert obj3 is obj4 diff --git a/tests/test_files.py b/tests/test_files.py index 3333f86..1540a76 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -4,7 +4,8 @@ import pytest from dirty_equals import IsDict, IsList, IsBytes, IsTuple -from neptune_api_v2._files import to_httpx_files, async_to_httpx_files +from neptune_api_v2._files import to_httpx_files, deepcopy_with_paths, async_to_httpx_files +from neptune_api_v2._utils import extract_files readme_path = Path(__file__).parent.parent.joinpath("README.md") @@ -49,3 +50,99 @@ def test_string_not_allowed() -> None: "file": "foo", # type: ignore } ) + + +def assert_different_identities(obj1: object, obj2: object) -> None: + assert obj1 == obj2 + assert obj1 is not obj2 + + +class TestDeepcopyWithPaths: + def test_copies_top_level_dict(self) -> None: + original = {"file": b"data", "other": "value"} + result = deepcopy_with_paths(original, [["file"]]) + assert_different_identities(result, original) + + def test_file_value_is_same_reference(self) -> None: + file_bytes = b"contents" + original = {"file": file_bytes} + result = deepcopy_with_paths(original, [["file"]]) + assert_different_identities(result, original) + assert result["file"] is file_bytes + + def test_list_popped_wholesale(self) -> None: + files = [b"f1", b"f2"] + original = {"files": files, "title": "t"} + result = deepcopy_with_paths(original, [["files", ""]]) + assert_different_identities(result, original) + result_files = result["files"] + assert isinstance(result_files, list) + assert_different_identities(result_files, files) + + def test_nested_array_path_copies_list_and_elements(self) -> None: + elem1 = {"file": b"f1", "extra": 1} + elem2 = {"file": b"f2", "extra": 2} + original = {"items": [elem1, elem2]} + result = deepcopy_with_paths(original, [["items", "", "file"]]) + assert_different_identities(result, original) + result_items = result["items"] + assert isinstance(result_items, list) + assert_different_identities(result_items, original["items"]) + assert_different_identities(result_items[0], elem1) + assert_different_identities(result_items[1], elem2) + + def test_empty_paths_returns_same_object(self) -> None: + original = {"foo": "bar"} + result = deepcopy_with_paths(original, []) + assert result is original + + def test_multiple_paths(self) -> None: + f1 = b"file1" + f2 = b"file2" + original = {"a": f1, "b": f2, "c": "unchanged"} + result = deepcopy_with_paths(original, [["a"], ["b"]]) + assert_different_identities(result, original) + assert result["a"] is f1 + assert result["b"] is f2 + assert result["c"] is original["c"] + + def test_extract_files_does_not_mutate_original_top_level(self) -> None: + file_bytes = b"contents" + original = {"file": file_bytes, "other": "value"} + + copied = deepcopy_with_paths(original, [["file"]]) + extracted = extract_files(copied, paths=[["file"]]) + + assert extracted == [("file", file_bytes)] + assert original == {"file": file_bytes, "other": "value"} + assert copied == {"other": "value"} + + def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None: + file1 = b"f1" + file2 = b"f2" + original = { + "items": [ + {"file": file1, "extra": 1}, + {"file": file2, "extra": 2}, + ], + "title": "example", + } + + copied = deepcopy_with_paths(original, [["items", "", "file"]]) + extracted = extract_files(copied, paths=[["items", "", "file"]]) + + assert extracted == [("items[][file]", file1), ("items[][file]", file2)] + assert original == { + "items": [ + {"file": file1, "extra": 1}, + {"file": file2, "extra": 2}, + ], + "title": "example", + } + assert copied == { + "items": [ + {"extra": 1}, + {"extra": 2}, + ], + "title": "example", + } From f0b98d296af0176f85591c6a2cabd1a32bcb56ec Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 03:15:47 +0000 Subject: [PATCH 3/9] chore(internal): more robust bootstrap script --- scripts/bootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/bootstrap b/scripts/bootstrap index 4638ec6..5a23841 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -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 From e892969e96a26dd08f61f88dac7812e73df8e16e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 03:29:42 +0000 Subject: [PATCH 4/9] fix: use correct field name format for multipart file arrays --- src/neptune_api_v2/_qs.py | 8 ++---- src/neptune_api_v2/_types.py | 3 +++ src/neptune_api_v2/_utils/_utils.py | 42 +++++++++++++++++++++++------ tests/test_extract_files.py | 28 +++++++++++++++---- tests/test_files.py | 2 +- 5 files changed, 63 insertions(+), 20 deletions(-) diff --git a/src/neptune_api_v2/_qs.py b/src/neptune_api_v2/_qs.py index de8c99b..4127c19 100644 --- a/src/neptune_api_v2/_qs.py +++ b/src/neptune_api_v2/_qs.py @@ -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 diff --git a/src/neptune_api_v2/_types.py b/src/neptune_api_v2/_types.py index ecd9396..2acc6c7 100644 --- a/src/neptune_api_v2/_types.py +++ b/src/neptune_api_v2/_types.py @@ -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 diff --git a/src/neptune_api_v2/_utils/_utils.py b/src/neptune_api_v2/_utils/_utils.py index 771859f..199cd23 100644 --- a/src/neptune_api_v2/_utils/_utils.py +++ b/src/neptune_api_v2/_utils/_utils.py @@ -17,11 +17,11 @@ ) from pathlib import Path from datetime import date, datetime -from typing_extensions import TypeGuard +from typing_extensions import TypeGuard, get_args import sniffio -from .._types import Omit, NotGiven, FileTypes, HeadersLike +from .._types import Omit, NotGiven, FileTypes, ArrayFormat, HeadersLike _T = TypeVar("_T") _TupleT = TypeVar("_TupleT", bound=Tuple[object, ...]) @@ -40,25 +40,45 @@ def extract_files( query: Mapping[str, object], *, paths: Sequence[Sequence[str]], + array_format: ArrayFormat = "brackets", ) -> list[tuple[str, FileTypes]]: """Recursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', '', 'data']. + ``array_format`` controls how ```` segments contribute to the emitted + field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and + ``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``). + Note: this mutates the given dictionary. """ files: list[tuple[str, FileTypes]] = [] for path in paths: - files.extend(_extract_items(query, path, index=0, flattened_key=None)) + files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format)) return files +def _array_suffix(array_format: ArrayFormat, array_index: int) -> str: + if array_format == "brackets": + return "[]" + if array_format == "indices": + return f"[{array_index}]" + if array_format == "repeat" or array_format == "comma": + # Both repeat the bare field name for each file part; there is no + # meaningful way to comma-join binary parts. + return "" + raise NotImplementedError( + f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}" + ) + + def _extract_items( obj: object, path: Sequence[str], *, index: int, flattened_key: str | None, + array_format: ArrayFormat, ) -> list[tuple[str, FileTypes]]: try: key = path[index] @@ -75,9 +95,11 @@ def _extract_items( if is_list(obj): files: list[tuple[str, FileTypes]] = [] - for entry in obj: - assert_is_file_content(entry, key=flattened_key + "[]" if flattened_key else "") - files.append((flattened_key + "[]", cast(FileTypes, entry))) + for array_index, entry in enumerate(obj): + suffix = _array_suffix(array_format, array_index) + emitted_key = (flattened_key + suffix) if flattened_key else suffix + assert_is_file_content(entry, key=emitted_key) + files.append((emitted_key, cast(FileTypes, entry))) return files assert_is_file_content(obj, key=flattened_key) @@ -106,6 +128,7 @@ def _extract_items( path, index=index, flattened_key=flattened_key, + array_format=array_format, ) elif is_list(obj): if key != "": @@ -117,9 +140,12 @@ def _extract_items( item, path, index=index, - flattened_key=flattened_key + "[]" if flattened_key is not None else "[]", + flattened_key=( + (flattened_key if flattened_key is not None else "") + _array_suffix(array_format, array_index) + ), + array_format=array_format, ) - for item in obj + for array_index, item in enumerate(obj) ] ) diff --git a/tests/test_extract_files.py b/tests/test_extract_files.py index 587f87d..0c43190 100644 --- a/tests/test_extract_files.py +++ b/tests/test_extract_files.py @@ -4,7 +4,7 @@ import pytest -from neptune_api_v2._types import FileTypes +from neptune_api_v2._types import FileTypes, ArrayFormat from neptune_api_v2._utils import extract_files @@ -37,10 +37,7 @@ def test_multiple_files() -> None: def test_top_level_file_array() -> None: query = {"files": [b"file one", b"file two"], "title": "hello"} - assert extract_files(query, paths=[["files", ""]]) == [ - ("files[]", b"file one"), - ("files[]", b"file two"), - ] + assert extract_files(query, paths=[["files", ""]]) == [("files[]", b"file one"), ("files[]", b"file two")] assert query == {"title": "hello"} @@ -71,3 +68,24 @@ def test_ignores_incorrect_paths( expected: list[tuple[str, FileTypes]], ) -> None: assert extract_files(query, paths=paths) == expected + + +@pytest.mark.parametrize( + "array_format,expected_top_level,expected_nested", + [ + ("brackets", [("files[]", b"a"), ("files[]", b"b")], [("items[][file]", b"a"), ("items[][file]", b"b")]), + ("repeat", [("files", b"a"), ("files", b"b")], [("items[file]", b"a"), ("items[file]", b"b")]), + ("comma", [("files", b"a"), ("files", b"b")], [("items[file]", b"a"), ("items[file]", b"b")]), + ("indices", [("files[0]", b"a"), ("files[1]", b"b")], [("items[0][file]", b"a"), ("items[1][file]", b"b")]), + ], +) +def test_array_format_controls_file_field_names( + array_format: ArrayFormat, + expected_top_level: list[tuple[str, FileTypes]], + expected_nested: list[tuple[str, FileTypes]], +) -> None: + top_level = {"files": [b"a", b"b"]} + assert extract_files(top_level, paths=[["files", ""]], array_format=array_format) == expected_top_level + + nested = {"items": [{"file": b"a"}, {"file": b"b"}]} + assert extract_files(nested, paths=[["items", "", "file"]], array_format=array_format) == expected_nested diff --git a/tests/test_files.py b/tests/test_files.py index 1540a76..01c3190 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -131,7 +131,7 @@ def test_extract_files_does_not_mutate_original_nested_array_path(self) -> None: copied = deepcopy_with_paths(original, [["items", "", "file"]]) extracted = extract_files(copied, paths=[["items", "", "file"]]) - assert extracted == [("items[][file]", file1), ("items[][file]", file2)] + assert [entry for _, entry in extracted] == [file1, file2] assert original == { "items": [ {"file": file1, "extra": 1}, From b5ef88979d72f7a372f340502025a1be6c69216d Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 28 Apr 2026 03:31:13 +0000 Subject: [PATCH 5/9] feat: support setting headers via env --- src/neptune_api_v2/_client.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/neptune_api_v2/_client.py b/src/neptune_api_v2/_client.py index 2fea046..411d150 100644 --- a/src/neptune_api_v2/_client.py +++ b/src/neptune_api_v2/_client.py @@ -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 @@ -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, @@ -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, From f66578c82ed25eff2d2475d04f1871956a3d7a6e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 30 Apr 2026 05:02:33 +0000 Subject: [PATCH 6/9] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index fa4911e..63ddec5 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 50 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech%2Fneptune-api-v2-05e0ec4b9b945a8c8e3542d34f0759f4eed2046a37750700fd40619f8a0cd6d7.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech/neptune-api-v2-05e0ec4b9b945a8c8e3542d34f0759f4eed2046a37750700fd40619f8a0cd6d7.yml openapi_spec_hash: 3911018927f898449898cc6cc5685273 config_hash: fdcc5ae6c783dda7176ace266f7ad0fd From 1a4ab7097105f66a9102df44a7760045799db19c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 03:58:56 +0000 Subject: [PATCH 7/9] codegen metadata --- .stats.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.stats.yml b/.stats.yml index 63ddec5..8f8703e 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 50 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech/neptune-api-v2-05e0ec4b9b945a8c8e3542d34f0759f4eed2046a37750700fd40619f8a0cd6d7.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cryptech/neptune-api-v2-55bfdf6d48920a09ac1c9566abf3b62b4c8b5af0de51e38bcda32c1fd68357ef.yml openapi_spec_hash: 3911018927f898449898cc6cc5685273 config_hash: fdcc5ae6c783dda7176ace266f7ad0fd From 94347608eb5c9304bec7a087ad631a453186b421 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 04:02:19 +0000 Subject: [PATCH 8/9] chore(internal): reformat pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 69e2350..ff31822 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 From 7d597489154cc4557c4650f66d0ffbcf17342a90 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 04:02:41 +0000 Subject: [PATCH 9/9] release: 0.7.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 25 +++++++++++++++++++++++++ pyproject.toml | 2 +- src/neptune_api_v2/_version.py | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4208b5c..1b77f50 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.6.0" + ".": "0.7.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c5df7fd..d29805c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## 0.7.0 (2026-05-01) + +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 + +* 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) diff --git a/pyproject.toml b/pyproject.toml index ff31822..d7d9a32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/neptune_api_v2/_version.py b/src/neptune_api_v2/_version.py index 8f4a369..fb0f13f 100644 --- a/src/neptune_api_v2/_version.py +++ b/src/neptune_api_v2/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "neptune_api_v2" -__version__ = "0.6.0" # x-release-please-version +__version__ = "0.7.0" # x-release-please-version