branddrive-python-sdk 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. branddrive/__init__.py +33 -0
  2. branddrive/client.py +134 -0
  3. branddrive/config.py +15 -0
  4. branddrive/dataclasses/__init__.py +118 -0
  5. branddrive/dataclasses/_utils.py +8 -0
  6. branddrive/dataclasses/customers.py +66 -0
  7. branddrive/dataclasses/expenses.py +155 -0
  8. branddrive/dataclasses/invoices.py +131 -0
  9. branddrive/dataclasses/payment_links.py +134 -0
  10. branddrive/dataclasses/pos.py +141 -0
  11. branddrive/dataclasses/products.py +166 -0
  12. branddrive/dataclasses/purchase_orders.py +141 -0
  13. branddrive/dataclasses/services.py +76 -0
  14. branddrive/dataclasses/vendors.py +48 -0
  15. branddrive/dataclasses/wallets.py +72 -0
  16. branddrive/exceptions.py +35 -0
  17. branddrive/protocols/__init__.py +43 -0
  18. branddrive/protocols/analytics.py +61 -0
  19. branddrive/protocols/customers.py +42 -0
  20. branddrive/protocols/expenses.py +69 -0
  21. branddrive/protocols/invoices.py +81 -0
  22. branddrive/protocols/payment_links.py +49 -0
  23. branddrive/protocols/pos.py +88 -0
  24. branddrive/protocols/products.py +150 -0
  25. branddrive/protocols/purchase_orders.py +68 -0
  26. branddrive/protocols/services.py +56 -0
  27. branddrive/protocols/vendors.py +39 -0
  28. branddrive/protocols/wallets.py +52 -0
  29. branddrive/resources/__init__.py +125 -0
  30. branddrive/resources/_utils.py +10 -0
  31. branddrive/resources/analytics.py +198 -0
  32. branddrive/resources/customers.py +194 -0
  33. branddrive/resources/expenses.py +209 -0
  34. branddrive/resources/invoices.py +268 -0
  35. branddrive/resources/payment_links.py +265 -0
  36. branddrive/resources/pos.py +353 -0
  37. branddrive/resources/products.py +612 -0
  38. branddrive/resources/purchase_orders.py +235 -0
  39. branddrive/resources/services.py +184 -0
  40. branddrive/resources/vendors.py +152 -0
  41. branddrive/resources/wallets.py +204 -0
  42. branddrive_python_sdk-0.1.0.dist-info/METADATA +132 -0
  43. branddrive_python_sdk-0.1.0.dist-info/RECORD +45 -0
  44. branddrive_python_sdk-0.1.0.dist-info/WHEEL +5 -0
  45. branddrive_python_sdk-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,204 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ from typing import Any
5
+ from urllib.parse import quote
6
+
7
+ import httpx
8
+
9
+ from ..exceptions import handle_api_exception
10
+ from ..dataclasses.wallets import (
11
+ WalletBusinessTransferData,
12
+ WalletExternalTransferData,
13
+ WalletFundData,
14
+ WalletPersonalTransferData,
15
+ )
16
+
17
+
18
+ class Wallet:
19
+ def __init__(self, client: httpx.Client) -> None:
20
+ self.client = client
21
+
22
+ @staticmethod
23
+ def _path_id(name: str, value: int) -> str:
24
+ if isinstance(value, bool) or not isinstance(value, int):
25
+ raise TypeError(f"{name} must be an integer")
26
+ if value < 1:
27
+ raise ValueError(f"{name} must be greater than 0")
28
+ return quote(str(value), safe="")
29
+
30
+ @staticmethod
31
+ def _validate_amount(amount: int | float) -> None:
32
+ if isinstance(amount, bool) or not isinstance(amount, (int, float)):
33
+ raise TypeError("amount must be a number")
34
+ if isinstance(amount, float) and not math.isfinite(amount):
35
+ raise ValueError("amount must be finite")
36
+ if amount <= 0:
37
+ raise ValueError("amount must be greater than 0")
38
+
39
+ @staticmethod
40
+ def _validate_tx_pin(tx_pin: int) -> None:
41
+ if isinstance(tx_pin, bool) or not isinstance(tx_pin, int):
42
+ raise TypeError("tx_pin must be an integer")
43
+
44
+ @staticmethod
45
+ def _validate_bank_field(name: str, value: str | int) -> None:
46
+ if isinstance(value, bool) or not isinstance(value, (str, int)):
47
+ raise TypeError(f"{name} must be a string or integer")
48
+ if isinstance(value, str) and not value.strip():
49
+ raise ValueError(f"{name} must not be empty")
50
+ if isinstance(value, int) and value < 1:
51
+ raise ValueError(f"{name} must be greater than 0")
52
+
53
+ def _handle_response(self, response: httpx.Response) -> dict[str, Any]:
54
+ if not response.is_success:
55
+ raise handle_api_exception(response)
56
+ return response.json()
57
+
58
+ def _handle_binary_response(self, response: httpx.Response) -> bytes:
59
+ if not response.is_success:
60
+ raise handle_api_exception(response)
61
+ return response.content
62
+
63
+ def get_wallet_details(self, wallet_id: int) -> dict[str, Any]:
64
+ """Get wallet details."""
65
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
66
+ response = self.client.request(
67
+ "GET",
68
+ f"/api/v1/wallet/{wallet_path_id}",
69
+ )
70
+ return self._handle_response(response)
71
+
72
+ def get_transaction_details(
73
+ self,
74
+ wallet_id: int,
75
+ transaction_id: int,
76
+ ) -> dict[str, Any]:
77
+ """Get transaction details for a wallet."""
78
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
79
+ transaction_path_id = self._path_id(
80
+ "transaction_id",
81
+ transaction_id,
82
+ )
83
+ response = self.client.request(
84
+ "GET",
85
+ f"/api/v1/wallet/{wallet_path_id}/transaction/{transaction_path_id}",
86
+ )
87
+ return self._handle_response(response)
88
+
89
+ def get_wallet_transactions(self, wallet_id: int) -> dict[str, Any]:
90
+ """Get transactions for a wallet."""
91
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
92
+ response = self.client.request(
93
+ "GET",
94
+ f"/api/v1/wallet/{wallet_path_id}/transaction",
95
+ )
96
+ return self._handle_response(response)
97
+
98
+ def export_wallet_transactions(self, wallet_id: int) -> bytes:
99
+ """Export transactions for a wallet."""
100
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
101
+ response = self.client.request(
102
+ "GET",
103
+ f"/api/v1/wallet/{wallet_path_id}/transaction/export",
104
+ )
105
+ return self._handle_binary_response(response)
106
+
107
+ def fund_wallet(
108
+ self,
109
+ wallet_id: int,
110
+ funding_data: WalletFundData,
111
+ ) -> dict[str, Any]:
112
+ """Fund a wallet."""
113
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
114
+ self._validate_amount(funding_data.amount)
115
+ response = self.client.request(
116
+ "POST",
117
+ f"/api/v1/wallet/{wallet_path_id}/fund",
118
+ json=funding_data.to_dict(),
119
+ )
120
+ return self._handle_response(response)
121
+
122
+ def transfer_to_business_wallet(
123
+ self,
124
+ wallet_id: int,
125
+ transfer_data: WalletBusinessTransferData,
126
+ ) -> dict[str, Any]:
127
+ """Transfer funds to another business wallet."""
128
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
129
+ self._path_id("to_wallet_id", transfer_data.to_wallet_id)
130
+ self._validate_amount(transfer_data.amount)
131
+ self._validate_tx_pin(transfer_data.tx_pin)
132
+ response = self.client.request(
133
+ "POST",
134
+ f"/api/v1/wallet/{wallet_path_id}/transfer/business",
135
+ json=transfer_data.to_dict(),
136
+ )
137
+ return self._handle_response(response)
138
+
139
+ def transfer_to_personal_wallet(
140
+ self,
141
+ wallet_id: int,
142
+ transfer_data: WalletPersonalTransferData,
143
+ ) -> dict[str, Any]:
144
+ """Transfer funds to a personal wallet."""
145
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
146
+ self._path_id(
147
+ "to_personal_wallet_id",
148
+ transfer_data.to_personal_wallet_id,
149
+ )
150
+ self._validate_amount(transfer_data.amount)
151
+ self._validate_tx_pin(transfer_data.tx_pin)
152
+ response = self.client.request(
153
+ "POST",
154
+ f"/api/v1/wallet/{wallet_path_id}/transfer/personal",
155
+ json=transfer_data.to_dict(),
156
+ )
157
+ return self._handle_response(response)
158
+
159
+ def transfer_to_external_bank_account(
160
+ self,
161
+ wallet_id: int,
162
+ transfer_data: WalletExternalTransferData,
163
+ ) -> dict[str, Any]:
164
+ """Transfer funds to an external bank account."""
165
+ wallet_path_id = self._path_id("wallet_id", wallet_id)
166
+ self._validate_amount(transfer_data.amount)
167
+ self._validate_tx_pin(transfer_data.tx_pin)
168
+ self._validate_bank_field(
169
+ "account_number",
170
+ transfer_data.account_number,
171
+ )
172
+ self._validate_bank_field("bank_code", transfer_data.bank_code)
173
+ if transfer_data.beneficiary_id is not None:
174
+ if not isinstance(transfer_data.beneficiary_id, str):
175
+ raise TypeError("beneficiary_id must be a string")
176
+ if not transfer_data.beneficiary_id.strip():
177
+ raise ValueError("beneficiary_id must not be empty")
178
+ response = self.client.request(
179
+ "POST",
180
+ f"/api/v1/wallet/{wallet_path_id}/transfer/external",
181
+ json=transfer_data.to_dict(),
182
+ )
183
+ return self._handle_response(response)
184
+
185
+ def get_platform_charges(self, amount: int) -> dict[str, Any]:
186
+ """Get platform charges for a transaction amount."""
187
+ amount_path = self._path_id("amount", amount)
188
+ response = self.client.request(
189
+ "GET",
190
+ f"/api/v1/wallet/transaction/fees/{amount_path}",
191
+ )
192
+ return self._handle_response(response)
193
+
194
+ def get_debit_transaction_receipt(self, transaction_id: int) -> bytes:
195
+ """Download a debit transaction receipt."""
196
+ transaction_path_id = self._path_id(
197
+ "transaction_id",
198
+ transaction_id,
199
+ )
200
+ response = self.client.request(
201
+ "GET",
202
+ f"/api/v1/wallet/transaction/{transaction_path_id}/receipt",
203
+ )
204
+ return self._handle_binary_response(response)
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: branddrive-python-sdk
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the BrandDrive API
5
+ Author: Ogenna Israel
6
+ License-Expression: LicenseRef-Proprietary
7
+ Keywords: branddrive,sdk,api,business
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: httpx>=0.29.0
16
+ Requires-Dist: python-dotenv>=1.0.0
17
+ Provides-Extra: dev
18
+ Requires-Dist: build>=1.2; extra == "dev"
19
+ Requires-Dist: pytest>=9.2.0; extra == "dev"
20
+
21
+ # BrandDrive Python SDK
22
+
23
+ A Python client for BrandDrive business resources, including customers, products,
24
+ invoices, POS, services, vendors, purchase orders, expenses, wallets, payment
25
+ links, and analytics.
26
+
27
+ ## Requirements
28
+
29
+ - Python 3.12 or newer
30
+ - A BrandDrive API key
31
+
32
+ ## Installation
33
+
34
+ Install the package from the repository:
35
+
36
+ ```bash
37
+ python -m pip install .
38
+ ```
39
+
40
+ For local development:
41
+
42
+ ```bash
43
+ python -m pip install -e ".[dev]"
44
+ ```
45
+
46
+ ## Configuration
47
+
48
+ Set credentials in environment variables or pass them directly:
49
+
50
+ ```bash
51
+ BRANDDRIVE_API_KEY=your-api-key
52
+ BRANDDRIVE_BASE_URL=https://api.branddrive.com
53
+ ```
54
+
55
+ Copy `.env.example` to `.env` for local development. `.env` is ignored by Git.
56
+
57
+ ## Quick start
58
+
59
+ ```python
60
+ from branddrive import BrandDriveClient
61
+ from branddrive.dataclasses import CustomerData
62
+
63
+ with BrandDriveClient() as client:
64
+ customer = CustomerData(
65
+ first_name="Amina",
66
+ branch_id=2,
67
+ birth_day=3,
68
+ birth_month=6,
69
+ email="amina@example.com",
70
+ )
71
+ created = client.customers.create_customer(customer)
72
+ print(created)
73
+ ```
74
+
75
+ Credentials can also be supplied explicitly:
76
+
77
+ ```python
78
+ client = BrandDriveClient(
79
+ api_key="your-api-key",
80
+ base_url="https://api.branddrive.com",
81
+ timeout=10,
82
+ max_retries=3,
83
+ )
84
+ ```
85
+
86
+ Always close a client that is not used as a context manager:
87
+
88
+ ```python
89
+ client.close()
90
+ ```
91
+
92
+ ## Resources
93
+
94
+ - `client.customers`
95
+ - `client.invoices`
96
+ - `client.products`
97
+ - `client.pos`
98
+ - `client.services`
99
+ - `client.vendors`
100
+ - `client.purchase_orders`
101
+ - `client.expenses`
102
+ - `client.wallets`
103
+ - `client.payment_links`
104
+ - `client.analytics`
105
+
106
+ Payload dataclasses are available under `branddrive.dataclasses`, for example
107
+ `from branddrive.dataclasses import CustomerData`.
108
+
109
+ ## Error handling
110
+
111
+ ```python
112
+ from branddrive.exceptions import APIException
113
+
114
+ try:
115
+ client.customers.list_cusotmers(limit=10)
116
+ except APIException as exc:
117
+ print(exc.status_code, exc.request_id, exc)
118
+ ```
119
+
120
+ API methods return decoded JSON dictionaries. Export and download methods may
121
+ return `bytes`.
122
+
123
+ ## Development
124
+
125
+ ```bash
126
+ python -m pytest
127
+ python -m build
128
+ ```
129
+
130
+ The build produces an installable wheel and source distribution in `dist/`.
131
+
132
+ See [deployment notes](docs/deployment.md) and [API usage](docs/api.md).
@@ -0,0 +1,45 @@
1
+ branddrive/__init__.py,sha256=HWasZn9BRiZOruxDzz2Kf32O7B5XZEMUERJFGcXJfZg,840
2
+ branddrive/client.py,sha256=YcQYVJUtUdSUaHyWOG0btjFtMorATqqX-BK9MhuXABc,4428
3
+ branddrive/config.py,sha256=TgJGcs09_PoXdNvB4kC3oJep2rUE2jJxFII5YhvkzpQ,359
4
+ branddrive/exceptions.py,sha256=nCFaE16x7PZei48P2rrAVZi08y5_P7OJ2QnCpQeZG2w,1200
5
+ branddrive/dataclasses/__init__.py,sha256=yDWN7QcmRjTj0tdi_jAxnurR66-nL0lnDJAHzBAALRM,2870
6
+ branddrive/dataclasses/_utils.py,sha256=Jb7bAF4_jLufEuyHPzkOP3EvgdbTTSP4mkDTjzdU6oo,265
7
+ branddrive/dataclasses/customers.py,sha256=VJo30F9khUkO1JalmYzX9D2Lfr6c9HUOi7Qo5mfx_zw,1899
8
+ branddrive/dataclasses/expenses.py,sha256=myWmG-H7myeNpW-_-PQjqCeqWQpG-7wT6c7TtxtmALw,4344
9
+ branddrive/dataclasses/invoices.py,sha256=vSc6XfqIUGmU_pUYGufSiwZzVJx-qpJc6uaM-EKBwcQ,3977
10
+ branddrive/dataclasses/payment_links.py,sha256=ZP6xb9nKnzz4RcBdBHDLgXn7UtP-tFHekFdQTtv6Ulk,3810
11
+ branddrive/dataclasses/pos.py,sha256=3iFEA33puKfuudlKTTpS-ftjpoRkuvA0pDwf6UVmnog,4092
12
+ branddrive/dataclasses/products.py,sha256=b-0Y7wOjiD9sAc6RCebKqLPZHp8u4g-TEhAlMaWV9yU,4500
13
+ branddrive/dataclasses/purchase_orders.py,sha256=SKR70nct0oEEDBQ830M27VTwPQ3NsZe2ua8Uc278wK0,4049
14
+ branddrive/dataclasses/services.py,sha256=4ctQT3oPN8b7-sW6COtz6hzX9HHZAuqySeWRk03CJBA,1947
15
+ branddrive/dataclasses/vendors.py,sha256=sGuVewsyVZCAfhNRp9I0dkxqvgDdgDUs-omCz4P3d-Q,1189
16
+ branddrive/dataclasses/wallets.py,sha256=z3WWp87glXGqr_DYD3DDrPEQhR0fzd-y1U543Dncqro,1775
17
+ branddrive/protocols/__init__.py,sha256=CBX_FIqB2l24kNVT6OUvvNBtLWkuuvKw2YVlMlQXlOA,1052
18
+ branddrive/protocols/analytics.py,sha256=cPibJJuYxAYIC7HuCr5AJsjmqoxrRBijGBZUtUMIT5g,1465
19
+ branddrive/protocols/customers.py,sha256=vxw8I21KysXZiaKQHZ2-EjbaGu4oPCPKk-IqkuiD2M8,1092
20
+ branddrive/protocols/expenses.py,sha256=H8FgPkuNzTj4ninwiFj8NpcG8Tb3a8FUSdhzDEV9dnA,1603
21
+ branddrive/protocols/invoices.py,sha256=VtbkEqxooQTykE5ZuktWzMjG47NeIrP7BFJ_Y_GO-VU,2031
22
+ branddrive/protocols/payment_links.py,sha256=M_-QVg5TY5d0bQMOVpRXKBj08clV9aj5qdzvzIYDx68,1207
23
+ branddrive/protocols/pos.py,sha256=WIqI1IJM7_aVIiKOFIA9BFM2yimbfMn0xrQg9Jai1Qo,2202
24
+ branddrive/protocols/products.py,sha256=xK_ko12kP_6R8_IQXqeKcHnw5hYb6H68xXH8hHwFyZg,3527
25
+ branddrive/protocols/purchase_orders.py,sha256=ZphPFuAca4HMKw8Pb3ApzIy3FZDQuxM9SkCFl3tUENw,1709
26
+ branddrive/protocols/services.py,sha256=9I8od7tyb-GP7tUhE3e1gRa2i7kwkut7kYr7uiGdTg0,1381
27
+ branddrive/protocols/vendors.py,sha256=SvE2oZRcmH80SiHsWenxNXyMeB6mI4_yqEbOfKSKjcg,958
28
+ branddrive/protocols/wallets.py,sha256=OIJ1e0bczKqMgbvN3Fj_FXjQU4fhyF6LUNo7AnvutAI,1359
29
+ branddrive/resources/__init__.py,sha256=9WdlIg_8zMlbK_jcLieMqd2GjsQdJbB0u5UGpN8rglA,3118
30
+ branddrive/resources/_utils.py,sha256=2kcd2isqkxMfY7taqv39FQjfDNMa7ZMx7kXCZwD4eXA,411
31
+ branddrive/resources/analytics.py,sha256=_-O2Q3KKNyhuu0I0BT_74glxvCbdaqC41EPmNp0iqs0,6507
32
+ branddrive/resources/customers.py,sha256=LrDrlLlYO5AVUIi1_kfT45Tnqb90iq6JjnD0xFhsaCw,6403
33
+ branddrive/resources/expenses.py,sha256=VbQxP-1lmb99g7GSahnoMIrrodq9X7HmI2iN61c2rko,7077
34
+ branddrive/resources/invoices.py,sha256=P6NVQ583Z_Cw2ZmiK42wZ5wShcuB_3-464PWKtf-K04,9350
35
+ branddrive/resources/payment_links.py,sha256=_FkkkwZt_QN8PGjRCLmhdaGsM6oIrferF1rQAT_0Fl0,9951
36
+ branddrive/resources/pos.py,sha256=UjDEE3Kqgul7mTiU3YsT_Y7W_Ufi4UxzwSxJ_PcuAFc,12395
37
+ branddrive/resources/products.py,sha256=1MPkrMmQiwpP7MV5Q7RsQxiePB1hjrVLdoHrAgmQcAc,19549
38
+ branddrive/resources/purchase_orders.py,sha256=D4oYhTujryBM3zrERoNhhn5x12-qZE63aaZVMpuYFxY,7798
39
+ branddrive/resources/services.py,sha256=Fp6CoggBQuF0bWw9FrRH0AyTFWUGs6PPD8kPRNuLRX4,6038
40
+ branddrive/resources/vendors.py,sha256=82BwhOH5VhG2uWNszyw0whZgvIbPV92PIAXUvjU7wXA,5027
41
+ branddrive/resources/wallets.py,sha256=Jqd3apFG4QRxpIyAeO7qaXqEHOcheeMxBlnq2TxfqLM,7551
42
+ branddrive_python_sdk-0.1.0.dist-info/METADATA,sha256=risjnEjEmvEdNqX864W9VZpgzO3ZVNuW8SHS_ENgC48,2958
43
+ branddrive_python_sdk-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
44
+ branddrive_python_sdk-0.1.0.dist-info/top_level.txt,sha256=o1U1sOh0VFCbuEZod68i7GXWNnFmDv_8__cWMoy7uDs,11
45
+ branddrive_python_sdk-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ branddrive