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,68 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import date
4
+ from typing import Any, Optional, Protocol
5
+
6
+ from ..dataclasses.purchase_orders import (
7
+ PurchaseOrderCreate,
8
+ PurchaseOrderPaymentCreate,
9
+ PurchaseOrderProcurementCreate,
10
+ PurchaseOrderUpdate,
11
+ )
12
+
13
+
14
+ class _PurchaseOrderAPI(Protocol):
15
+ def create_purchase_order(
16
+ self,
17
+ purchase_order_data: PurchaseOrderCreate,
18
+ ) -> dict[str, Any]: ...
19
+
20
+ def list_purchase_orders(
21
+ self,
22
+ currency_id: int,
23
+ branch_id: Optional[int] = None,
24
+ limit: int = 10,
25
+ offset: int = 0,
26
+ start_date: Optional[date] = None,
27
+ end_date: Optional[date] = None,
28
+ ) -> dict[str, Any]: ...
29
+
30
+ def retrieve_purchase_order(
31
+ self,
32
+ purchase_order_id: int,
33
+ ) -> dict[str, Any]: ...
34
+
35
+ def update_purchase_order(
36
+ self,
37
+ purchase_order_id: int,
38
+ purchase_order_data: PurchaseOrderUpdate,
39
+ ) -> dict[str, Any]: ...
40
+
41
+ def delete_purchase_order(
42
+ self,
43
+ purchase_order_id: int,
44
+ ) -> dict[str, Any]: ...
45
+
46
+ def add_procurement(
47
+ self,
48
+ purchase_order_id: int,
49
+ procurement: PurchaseOrderProcurementCreate,
50
+ ) -> dict[str, Any]: ...
51
+
52
+ def update_procurement(self, procurement_id: int) -> dict[str, Any]: ...
53
+
54
+ def delete_procurement(self, procurement_id: int) -> dict[str, Any]: ...
55
+
56
+ def record_payment(
57
+ self,
58
+ purchase_order_id: int,
59
+ payment_data: PurchaseOrderPaymentCreate,
60
+ ) -> dict[str, Any]: ...
61
+
62
+ def delete_payment(
63
+ self,
64
+ purchase_order_id: int,
65
+ payment_id: int,
66
+ ) -> dict[str, Any]: ...
67
+
68
+ def export_payments(self) -> bytes: ...
@@ -0,0 +1,56 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, Protocol
4
+
5
+ from ..dataclasses.services import (
6
+ ServiceCategoryCreate,
7
+ ServiceCategoryUpdate,
8
+ ServiceCreate,
9
+ UpdateServiceData,
10
+ )
11
+
12
+
13
+ class _ServiceCategoryAPI(Protocol):
14
+ def create_category(self, category_data: ServiceCategoryCreate) -> dict[str, Any]: ...
15
+
16
+ def list_categories(
17
+ self,
18
+ limit: Optional[int] = 10,
19
+ ) -> dict[str, Any]: ...
20
+
21
+ def update_category(
22
+ self,
23
+ category_id: int,
24
+ category_data: ServiceCategoryUpdate,
25
+ ) -> dict[str, Any]: ...
26
+
27
+ def delete_category(
28
+ self,
29
+ category_id: int,
30
+ ) -> dict[str, Any]: ...
31
+
32
+
33
+ class _ServiceAPI(Protocol):
34
+ category: _ServiceCategoryAPI
35
+
36
+ def create_service(self, service_data: ServiceCreate) -> dict[str, Any]: ...
37
+
38
+ def list_services(
39
+ self,
40
+ limit: int = 10,
41
+ offset: int = 0,
42
+ search: Optional[str] = None,
43
+ sort: Optional[int] = None,
44
+ ) -> dict[str, Any]: ...
45
+
46
+ def retrieve_service(self, service_id: int) -> dict[str, Any]: ...
47
+
48
+ def update_service(
49
+ self,
50
+ service_id: int,
51
+ service_data: UpdateServiceData,
52
+ ) -> dict[str, Any]: ...
53
+
54
+ def delete_service(self, service_id: int) -> dict[str, Any]: ...
55
+
56
+ def delete_bulk_services(self, service_ids: list[int]) -> dict[str, Any]: ...
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any, Protocol, Optional
5
+
6
+ from ..dataclasses.vendors import VendorData, UpdateVendorData
7
+
8
+
9
+ class _VendorAPI(Protocol):
10
+ def create_vendor(self, vendor_data: VendorData) -> dict[str, Any]: ...
11
+
12
+ def import_csv(
13
+ self,
14
+ file_path: str | Path,
15
+ file_field: str = "Data",
16
+ ) -> dict[str, Any]: ...
17
+
18
+ def export(
19
+ self,
20
+ branch_id: Optional[int] = None,
21
+ email: Optional[str] = None,
22
+ file_type: Optional[str] = "csv",
23
+ ) -> bytes: ...
24
+
25
+ def list_vendors(
26
+ self,
27
+ limit: int = 10,
28
+ offset: int = 0,
29
+ ) -> dict[str, Any]: ...
30
+
31
+ def retrieve_vendor(self, vendor_id: int) -> dict[str, Any]: ...
32
+
33
+ def update_vendor(
34
+ self,
35
+ vendor_id: int,
36
+ vendor_data: UpdateVendorData,
37
+ ) -> dict[str, Any]: ...
38
+
39
+ def toggle_status(self, vendor_id: int) -> dict[str, Any]: ...
@@ -0,0 +1,52 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Protocol
4
+
5
+ from ..dataclasses.wallets import (
6
+ WalletBusinessTransferData,
7
+ WalletExternalTransferData,
8
+ WalletFundData,
9
+ WalletPersonalTransferData,
10
+ )
11
+
12
+
13
+ class _WalletAPI(Protocol):
14
+ def get_wallet_details(self, wallet_id: int) -> dict[str, Any]: ...
15
+
16
+ def get_transaction_details(
17
+ self,
18
+ wallet_id: int,
19
+ transaction_id: int,
20
+ ) -> dict[str, Any]: ...
21
+
22
+ def get_wallet_transactions(self, wallet_id: int) -> dict[str, Any]: ...
23
+
24
+ def export_wallet_transactions(self, wallet_id: int) -> bytes: ...
25
+
26
+ def fund_wallet(
27
+ self,
28
+ wallet_id: int,
29
+ funding_data: WalletFundData,
30
+ ) -> dict[str, Any]: ...
31
+
32
+ def transfer_to_business_wallet(
33
+ self,
34
+ wallet_id: int,
35
+ transfer_data: WalletBusinessTransferData,
36
+ ) -> dict[str, Any]: ...
37
+
38
+ def transfer_to_personal_wallet(
39
+ self,
40
+ wallet_id: int,
41
+ transfer_data: WalletPersonalTransferData,
42
+ ) -> dict[str, Any]: ...
43
+
44
+ def transfer_to_external_bank_account(
45
+ self,
46
+ wallet_id: int,
47
+ transfer_data: WalletExternalTransferData,
48
+ ) -> dict[str, Any]: ...
49
+
50
+ def get_platform_charges(self, amount: int) -> dict[str, Any]: ...
51
+
52
+ def get_debit_transaction_receipt(self, transaction_id: int) -> bytes: ...
@@ -0,0 +1,125 @@
1
+ from ..dataclasses import (
2
+ CustomerData,
3
+ POSCreate,
4
+ POSPaymentProcurement,
5
+ POSProcurement,
6
+ POSProcurementUpdate,
7
+ POSProductProcurement,
8
+ POSVoidData,
9
+ PosUpdate,
10
+ InvoiceCreate,
11
+ InvoiceCreateSend,
12
+ InvoiceUpdate,
13
+ ProcurementData,
14
+ ProductDistributionCreate,
15
+ ProductDistributionUpdate,
16
+ RecurringScheduleCreate,
17
+ RecurringScheduleUpdate,
18
+ SingleProductCreate,
19
+ UpdateCustomerData,
20
+ UpdateProductData,
21
+ UpdateProcurementData,
22
+ ServiceCategoryCreate,
23
+ ServiceCategoryUpdate,
24
+ ServiceCreate,
25
+ UpdateServiceData,
26
+ VendorData,
27
+ UpdateVendorData,
28
+ PurchaseOrderCreate,
29
+ PurchaseOrderPaymentCreate,
30
+ PurchaseOrderPaymentMethod,
31
+ PurchaseOrderProcurementCreate,
32
+ PurchaseOrderProduct,
33
+ PurchaseOrderUpdate,
34
+ ExpenseCreate,
35
+ ExpenseLineItem,
36
+ ExpensePaymentCreate,
37
+ ExpensePaymentMethod,
38
+ ExpenseProcurementCreate,
39
+ ExpenseProcurementUpdate,
40
+ ExpenseUpdate,
41
+ WalletBusinessTransferData,
42
+ WalletExternalTransferData,
43
+ WalletFundData,
44
+ WalletPersonalTransferData,
45
+ PaymentLinkCategoryCreate,
46
+ PaymentLinkCategoryData,
47
+ PaymentLinkCreate,
48
+ PaymentLinkPayData,
49
+ PaymentLinkSubscriptionDuration,
50
+ PaymentLinkUpdate,
51
+ )
52
+ from .customers import Customer
53
+ from .invoices import Invoice
54
+ from .products import Product
55
+ from .pos import POS
56
+ from .services import Service
57
+ from .vendors import Vendor
58
+ from .purchase_orders import PurchaseOrder
59
+ from .expenses import Expense
60
+ from .wallets import Wallet
61
+ from .payment_links import PaymentLink
62
+ from .analytics import Analytics
63
+
64
+ __all__ = [
65
+ "Customer",
66
+ "CustomerData",
67
+ "UpdateCustomerData",
68
+ "POS",
69
+ "POSCreate",
70
+ "POSPaymentProcurement",
71
+ "POSProcurement",
72
+ "POSProcurementUpdate",
73
+ "POSProductProcurement",
74
+ "POSVoidData",
75
+ "PosUpdate",
76
+ "Invoice",
77
+ "InvoiceCreate",
78
+ "InvoiceCreateSend",
79
+ "InvoiceUpdate",
80
+ "RecurringScheduleCreate",
81
+ "RecurringScheduleUpdate",
82
+ "Product",
83
+ "SingleProductCreate",
84
+ "UpdateProductData",
85
+ "ProcurementData",
86
+ "UpdateProcurementData",
87
+ "ProductDistributionCreate",
88
+ "ProductDistributionUpdate",
89
+ 'Service',
90
+ 'ServiceCategoryCreate',
91
+ "ServiceCategoryUpdate",
92
+ "ServiceCreate",
93
+ "UpdateServiceData",
94
+ "Vendor",
95
+ "VendorData",
96
+ "UpdateVendorData",
97
+ "PurchaseOrder",
98
+ "PurchaseOrderCreate",
99
+ "PurchaseOrderUpdate",
100
+ "PurchaseOrderProduct",
101
+ "PurchaseOrderProcurementCreate",
102
+ "PurchaseOrderPaymentCreate",
103
+ "PurchaseOrderPaymentMethod",
104
+ "Expense",
105
+ "ExpenseCreate",
106
+ "ExpenseUpdate",
107
+ "ExpenseLineItem",
108
+ "ExpenseProcurementCreate",
109
+ "ExpenseProcurementUpdate",
110
+ "ExpensePaymentCreate",
111
+ "ExpensePaymentMethod",
112
+ "Wallet",
113
+ "WalletFundData",
114
+ "WalletBusinessTransferData",
115
+ "WalletPersonalTransferData",
116
+ "WalletExternalTransferData",
117
+ "PaymentLink",
118
+ "Analytics",
119
+ "PaymentLinkCategoryCreate",
120
+ "PaymentLinkCategoryData",
121
+ "PaymentLinkCreate",
122
+ "PaymentLinkPayData",
123
+ "PaymentLinkSubscriptionDuration",
124
+ "PaymentLinkUpdate",
125
+ ]
@@ -0,0 +1,10 @@
1
+
2
+
3
+ def validate_pagination(limit: int, offset: int) -> None:
4
+ for name, value in (("limit", limit), ("offset", offset)):
5
+ if isinstance(value, bool) or not isinstance(value, int):
6
+ raise TypeError(f"{name} must be an integer")
7
+ if limit < 1:
8
+ raise ValueError("limit must be greater than 0")
9
+ if offset < 0:
10
+ raise ValueError("offset must be greater than or equal to 0")
@@ -0,0 +1,198 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import date, datetime
4
+ from typing import Any
5
+
6
+ import httpx
7
+
8
+ from ..exceptions import handle_api_exception
9
+
10
+
11
+ class Analytics:
12
+ def __init__(self, client: httpx.Client) -> None:
13
+ self.client = client
14
+
15
+ @staticmethod
16
+ def _branch_id(branch_id: int) -> int:
17
+ if isinstance(branch_id, bool) or not isinstance(branch_id, int):
18
+ raise TypeError("branch_id must be an integer")
19
+ if branch_id < 1:
20
+ raise ValueError("branch_id must be greater than 0")
21
+ return branch_id
22
+
23
+ @staticmethod
24
+ def _date_param(name: str, value: date | None) -> str | None:
25
+ if value is None:
26
+ return None
27
+ if isinstance(value, datetime) or not isinstance(value, date):
28
+ raise TypeError(f"{name} must be a datetime.date instance")
29
+ return value.isoformat()
30
+
31
+ @classmethod
32
+ def _required_date_param(cls, name: str, value: date) -> str:
33
+ result = cls._date_param(name, value)
34
+ if result is None:
35
+ raise ValueError(f"{name} is required")
36
+ return result
37
+
38
+ @staticmethod
39
+ def _required_text(name: str, value: str) -> str:
40
+ if not isinstance(value, str):
41
+ raise TypeError(f"{name} must be a string")
42
+ if not value.strip():
43
+ raise ValueError(f"{name} must not be empty")
44
+ return value
45
+
46
+ def _get(
47
+ self,
48
+ path: str,
49
+ params: dict[str, int | str | None],
50
+ ) -> dict[str, Any]:
51
+ response = self.client.request(
52
+ "GET",
53
+ path,
54
+ params={key: value for key, value in params.items() if value is not None},
55
+ )
56
+ if not response.is_success:
57
+ raise handle_api_exception(response)
58
+ return response.json()
59
+
60
+ def get_profit_and_loss(
61
+ self,
62
+ branch_id: int,
63
+ duration: str,
64
+ start_date: date | None = None,
65
+ end_date: date | None = None,
66
+ ) -> dict[str, Any]:
67
+ """Get profit and loss for a branch and reporting duration."""
68
+ branch_id = self._branch_id(branch_id)
69
+ duration = self._required_text("duration", duration)
70
+ return self._get(
71
+ "/api/v1/analytics/profit-and-loss",
72
+ {
73
+ "branchId": branch_id,
74
+ "duration": duration,
75
+ "startDate": self._date_param("start_date", start_date),
76
+ "endDate": self._date_param("end_date", end_date),
77
+ },
78
+ )
79
+
80
+ def get_sales_and_income(
81
+ self,
82
+ branch_id: int,
83
+ start_date: date,
84
+ end_date: date,
85
+ resolution: str | None = None,
86
+ ) -> dict[str, Any]:
87
+ """Get sales and income over a date range."""
88
+ branch_id = self._branch_id(branch_id)
89
+ if resolution is not None:
90
+ resolution = self._required_text("resolution", resolution)
91
+ return self._get(
92
+ "/api/v1/analytics/sales-and-income",
93
+ {
94
+ "branchId": branch_id,
95
+ "resolution": resolution,
96
+ "startDate": self._required_date_param(
97
+ "start_date",
98
+ start_date,
99
+ ),
100
+ "endDate": self._required_date_param("end_date", end_date),
101
+ },
102
+ )
103
+
104
+ def get_performance_overview(
105
+ self,
106
+ start_date: date | None = None,
107
+ end_date: date | None = None,
108
+ ) -> dict[str, Any]:
109
+ """Get performance metrics for an optional date range."""
110
+ return self._get(
111
+ "/api/v1/analytics/performance/overview/",
112
+ {
113
+ "startDate": self._date_param("start_date", start_date),
114
+ "endDate": self._date_param("end_date", end_date),
115
+ },
116
+ )
117
+
118
+ def get_total_payment_distribution(
119
+ self,
120
+ start_date: date,
121
+ end_date: date,
122
+ branch_id: int,
123
+ ) -> dict[str, Any]:
124
+ """Get payment totals grouped by payment method."""
125
+ branch_id = self._branch_id(branch_id)
126
+ return self._get(
127
+ "/api/v1/analytics/payment/distribution",
128
+ {
129
+ "startDate": self._required_date_param(
130
+ "start_date",
131
+ start_date,
132
+ ),
133
+ "endDate": self._required_date_param("end_date", end_date),
134
+ "branchId": branch_id,
135
+ },
136
+ )
137
+
138
+ def get_orders_by_team(
139
+ self,
140
+ branch_id: int,
141
+ team_email: str,
142
+ start_date: date | None = None,
143
+ end_date: date | None = None,
144
+ ) -> dict[str, Any]:
145
+ """Get orders attributed to a team member."""
146
+ branch_id = self._branch_id(branch_id)
147
+ team_email = self._required_text("team_email", team_email)
148
+ return self._get(
149
+ "/api/v1/analytics/order/team",
150
+ {
151
+ "branchId": branch_id,
152
+ "teamEmail": team_email,
153
+ "startDate": self._date_param("start_date", start_date),
154
+ "endDate": self._date_param("end_date", end_date),
155
+ },
156
+ )
157
+
158
+ def get_leaderboard(
159
+ self,
160
+ start_date: date | None = None,
161
+ end_date: date | None = None,
162
+ ) -> dict[str, Any]:
163
+ """Get leaderboard metrics for an optional date range."""
164
+ return self._get(
165
+ "/api/v1/analytics/leader-board",
166
+ {
167
+ "startDate": self._date_param("start_date", start_date),
168
+ "endDate": self._date_param("end_date", end_date),
169
+ },
170
+ )
171
+
172
+ def get_banking_and_wallet(
173
+ self,
174
+ start_date: date | None = None,
175
+ end_date: date | None = None,
176
+ ) -> dict[str, Any]:
177
+ """Get banking and wallet activity for an optional date range."""
178
+ return self._get(
179
+ "/api/v1/analytics/banking-and-wallet/",
180
+ {
181
+ "startDate": self._date_param("start_date", start_date),
182
+ "endDate": self._date_param("end_date", end_date),
183
+ },
184
+ )
185
+
186
+ def get_cpv(
187
+ self,
188
+ start_date: date | None = None,
189
+ end_date: date | None = None,
190
+ ) -> dict[str, Any]:
191
+ """Get customer purchase value metrics for an optional date range."""
192
+ return self._get(
193
+ "/api/v1/analytics/cpv",
194
+ {
195
+ "startDate": self._date_param("start_date", start_date),
196
+ "endDate": self._date_param("end_date", end_date),
197
+ },
198
+ )