From 5aca18333276ea374bbea6fb9f3f202f7f98f143 Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Thu, 15 May 2025 14:26:23 -0500 Subject: [PATCH 1/3] Add support for multiple custom categories --- ntropy_sdk/account_holders.py | 8 ++++ ntropy_sdk/categories.py | 72 +++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/ntropy_sdk/account_holders.py b/ntropy_sdk/account_holders.py index 609d35e..9ff9778 100644 --- a/ntropy_sdk/account_holders.py +++ b/ntropy_sdk/account_holders.py @@ -33,6 +33,10 @@ class AccountHolderCreate(BaseModel): default=None, description="The name of the account holder", ) + category_id: Optional[str] = Field( + default=None, + description="The Categories ID that will be used for this account holder's transactions", + ) request_id: Optional[str] = None @@ -107,6 +111,7 @@ def create( id: str, type: Union[AccountHolderType, str], name: Optional[str] = None, + category_id: Optional[str] = None, **extra_kwargs: "Unpack[ExtraKwargs]", ) -> AccountHolderResponse: """Create an account holder""" @@ -123,6 +128,7 @@ def create( id=id, type=type, name=name, + category_id=category_id, ) ), **extra_kwargs, @@ -231,6 +237,7 @@ async def create( id: str, type: Union[AccountHolderType, str], name: Optional[str] = None, + category_id: Optional[str] = None, **extra_kwargs: "Unpack[ExtraKwargsAsync]", ) -> AccountHolderResponse: """Create an account holder""" @@ -247,6 +254,7 @@ async def create( id=id, type=type, name=name, + category_id=category_id, ) ), **extra_kwargs, diff --git a/ntropy_sdk/categories.py b/ntropy_sdk/categories.py index ca40403..f73dbc1 100644 --- a/ntropy_sdk/categories.py +++ b/ntropy_sdk/categories.py @@ -1,3 +1,4 @@ +import sys from typing import TYPE_CHECKING, Union import uuid @@ -6,7 +7,12 @@ if TYPE_CHECKING: from ntropy_sdk import ExtraKwargs, ExtraKwargsAsync, SDK from ntropy_sdk.async_.sdk import AsyncSDK - from typing_extensions import Unpack + from typing_extensions import Unpack, deprecated +elif sys.version_info >= (3, 13): + from warnings import deprecated +else: + def deprecated(msg): + return lambda f: f class CategoriesResource: @@ -15,25 +21,25 @@ def __init__(self, sdk: "SDK"): def get( self, - account_holder_type: Union[AccountHolderType, str], + category_id: Union[AccountHolderType, str], **extra_kwargs: "Unpack[ExtraKwargs]", ) -> dict: request_id = extra_kwargs.get("request_id") if request_id is None: request_id = uuid.uuid4().hex extra_kwargs["request_id"] = request_id - if not isinstance(account_holder_type, AccountHolderType): - account_holder_type = AccountHolderType(account_holder_type) + if isinstance(category_id, AccountHolderType): + category_id = category_id.value resp = self._sdk.retry_ratelimited_request( method="GET", - url=f"/v3/categories/{account_holder_type.value}", + url=f"/v3/categories/{category_id}", **extra_kwargs, ) return resp.json() def set( self, - account_holder_type: Union[AccountHolderType, str], + category_id: Union[AccountHolderType, str], categories: dict, **extra_kwargs: "Unpack[ExtraKwargs]", ): @@ -41,30 +47,38 @@ def set( if request_id is None: request_id = uuid.uuid4().hex extra_kwargs["request_id"] = request_id - if not isinstance(account_holder_type, AccountHolderType): - account_holder_type = AccountHolderType(account_holder_type) + if isinstance(category_id, AccountHolderType): + category_id = category_id.value resp = self._sdk.retry_ratelimited_request( method="POST", - url=f"/v3/categories/{account_holder_type.value}", + url=f"/v3/categories/{category_id}", payload=categories, **extra_kwargs, ) return resp.json() + @deprecated("Use the delete method instead") def reset( self, - account_holder_type: Union[AccountHolderType, str], + category_id: Union[AccountHolderType, str], + **extra_kwargs: "Unpack[ExtraKwargs]", + ): + return self.delete(category_id, **extra_kwargs) + + def delete( + self, + category_id: Union[AccountHolderType, str], **extra_kwargs: "Unpack[ExtraKwargs]", ): request_id = extra_kwargs.get("request_id") if request_id is None: request_id = uuid.uuid4().hex extra_kwargs["request_id"] = request_id - if not isinstance(account_holder_type, AccountHolderType): - account_holder_type = AccountHolderType(account_holder_type) + if isinstance(category_id, AccountHolderType): + category_id = category_id.value resp = self._sdk.retry_ratelimited_request( method="POST", - url=f"/v3/categories/{account_holder_type.value}/reset", + url=f"/v3/categories/{category_id}/reset", **extra_kwargs, ) return resp.json() @@ -76,18 +90,18 @@ def __init__(self, sdk: "AsyncSDK"): async def get( self, - account_holder_type: Union[AccountHolderType, str], + category_id: Union[AccountHolderType, str], **extra_kwargs: "Unpack[ExtraKwargsAsync]", ) -> dict: request_id = extra_kwargs.get("request_id") if request_id is None: request_id = uuid.uuid4().hex extra_kwargs["request_id"] = request_id - if not isinstance(account_holder_type, AccountHolderType): - account_holder_type = AccountHolderType(account_holder_type) + if isinstance(category_id, AccountHolderType): + category_id = category_id.value resp = await self._sdk.retry_ratelimited_request( method="GET", - url=f"/v3/categories/{account_holder_type.value}", + url=f"/v3/categories/{category_id}", **extra_kwargs, ) async with resp: @@ -95,7 +109,7 @@ async def get( async def set( self, - account_holder_type: Union[AccountHolderType, str], + category_id: Union[AccountHolderType, str], categories: dict, **extra_kwargs: "Unpack[ExtraKwargsAsync]", ): @@ -103,31 +117,39 @@ async def set( if request_id is None: request_id = uuid.uuid4().hex extra_kwargs["request_id"] = request_id - if not isinstance(account_holder_type, AccountHolderType): - account_holder_type = AccountHolderType(account_holder_type) + if isinstance(category_id, AccountHolderType): + category_id = category_id.value resp = await self._sdk.retry_ratelimited_request( method="POST", - url=f"/v3/categories/{account_holder_type.value}", + url=f"/v3/categories/{category_id}", payload=categories, **extra_kwargs, ) async with resp: return await resp.json() + @deprecated("Use the delete method instead") async def reset( self, - account_holder_type: Union[AccountHolderType, str], + category_id: Union[AccountHolderType, str], + **extra_kwargs: "Unpack[ExtraKwargsAsync]", + ): + return await self.delete(category_id, **extra_kwargs) + + async def delete( + self, + category_id: Union[AccountHolderType, str], **extra_kwargs: "Unpack[ExtraKwargsAsync]", ): request_id = extra_kwargs.get("request_id") if request_id is None: request_id = uuid.uuid4().hex extra_kwargs["request_id"] = request_id - if not isinstance(account_holder_type, AccountHolderType): - account_holder_type = AccountHolderType(account_holder_type) + if isinstance(category_id, AccountHolderType): + category_id = category_id.value resp = await self._sdk.retry_ratelimited_request( method="POST", - url=f"/v3/categories/{account_holder_type.value}/reset", + url=f"/v3/categories/{category_id}/reset", **extra_kwargs, ) async with resp: From f1afc0ac8c79ef55ce9703ab2ca965450b21290f Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Tue, 20 May 2025 11:35:32 -0500 Subject: [PATCH 2/3] Update runner --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 8adee38..8a9f984 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -15,7 +15,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 7cac4d2f2795ecea66e2d945f15083d589a2347d Mon Sep 17 00:00:00 2001 From: Matthew Tran <0e4ef622@gmail.com> Date: Thu, 22 May 2025 23:28:44 -0500 Subject: [PATCH 3/3] =?UTF-8?q?Bump=20version:=205.1.3=20=E2=86=92=205.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ntropy_sdk/__init__.py | 2 +- setup.cfg | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ntropy_sdk/__init__.py b/ntropy_sdk/__init__.py index 851e3f1..86539ad 100644 --- a/ntropy_sdk/__init__.py +++ b/ntropy_sdk/__init__.py @@ -1,4 +1,4 @@ -__version__ = "5.1.3" +__version__ = "5.2.0" from typing import TYPE_CHECKING, Optional diff --git a/setup.cfg b/setup.cfg index 258e6f6..1cf2281 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 5.1.3 +current_version = 5.2.0 commit = True tag = True parse = (?P\d+)\.(?P\d+)\.(?P\d+)(rc(?P
\d+))?
diff --git a/setup.py b/setup.py
index 9a48a47..299e8c4 100644
--- a/setup.py
+++ b/setup.py
@@ -55,6 +55,6 @@
     test_suite="tests",
     tests_require=test_requirements,
     url="https://github.com/ntropy-network/ntropy-sdk",
-    version="5.1.3",
+    version="5.2.0",
     zip_safe=False,
 )