Skip to content

Commit bc30ec3

Browse files
refactor: simplify models and update SDK documentation; remove obsolete model files and enhance client initialization
1 parent c2b898c commit bc30ec3

56 files changed

Lines changed: 716 additions & 1717 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lomi/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
"""
2-
lomi. Python SDK
3-
AUTO-GENERATED - Do not edit manually
4-
"""
1+
"""lomi Python SDK — public merchant API surface."""
52

63
from .client import LomiClient
74
from .exceptions import LomiError, LomiAuthError, LomiNotFoundError
8-
from .models import *
95

10-
__version__ = "1.0.0"
6+
__all__ = ["LomiClient", "LomiError", "LomiAuthError", "LomiNotFoundError"]

lomi/client.py

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,96 @@
1-
"""
2-
lomi. Python SDK Client
3-
AUTO-GENERATED - Do not edit manually
4-
"""
1+
"""lomi. Python SDK — generated from OpenAPI + public allowlist."""
52

63
import requests
7-
from typing import Optional, Dict, Any, List, Type, TypeVar
4+
from typing import Optional, Dict, Any
5+
86
from .exceptions import LomiError, LomiAuthError, LomiNotFoundError
9-
from .models import *
107
from .services import *
11-
from pydantic import BaseModel
128

13-
T = TypeVar("T", bound=BaseModel)
9+
def _flatten_data(data):
10+
if data is None:
11+
return None
12+
if hasattr(data, "model_dump"):
13+
return data.model_dump(exclude_unset=True)
14+
if hasattr(data, "dict"):
15+
return data.dict(exclude_unset=True)
16+
return data
17+
1418

1519
class LomiClient:
16-
"""Main lomi. SDK client"""
17-
20+
"""Merchant API client (public routes only)."""
21+
1822
def __init__(
1923
self,
2024
api_key: str,
2125
base_url: str = "https://api.lomi.africa",
22-
environment: str = "live"
26+
environment: str = "live",
2327
):
2428
self.api_key = api_key
25-
self.base_url = base_url if environment != "test" else "https://sandbox.api.lomi.africa"
29+
test_host = environment in ("test", "sandbox") or (
30+
isinstance(environment, str) and environment.lower() == "test"
31+
)
32+
self.base_url = (
33+
base_url if not test_host else "https://sandbox.api.lomi.africa"
34+
)
2635
self.session = requests.Session()
27-
self.session.headers.update({
28-
"X-API-KEY": api_key,
29-
"Content-Type": "application/json",
30-
})
31-
32-
# Initialize service instances
36+
self.session.headers.update(
37+
{"X-API-KEY": api_key, "Content-Type": "application/json"}
38+
)
3339
self.accounts = AccountsService(self)
34-
self.organizations = OrganizationsService(self)
40+
self.beneficiary_payouts = BeneficiaryPayoutsService(self)
41+
self.charges = ChargesService(self)
42+
self.checkout_sessions = CheckoutSessionsService(self)
3543
self.customers = CustomersService(self)
36-
self.payment_requests = PaymentRequestsService(self)
37-
self.transactions = TransactionsService(self)
38-
self.refunds = RefundsService(self)
39-
self.products = ProductsService(self)
40-
self.subscriptions = SubscriptionsService(self)
4144
self.discount_coupons = DiscountCouponsService(self)
42-
self.checkout_sessions = CheckoutSessionsService(self)
45+
self.organizations = OrganizationsService(self)
46+
self.payment_intents = PaymentIntentsService(self)
4347
self.payment_links = PaymentLinksService(self)
48+
self.payment_requests = PaymentRequestsService(self)
4449
self.payouts = PayoutsService(self)
45-
self.beneficiary_payouts = BeneficiaryPayoutsService(self)
46-
self.webhooks = WebhooksService(self)
50+
self.products = ProductsService(self)
51+
self.refunds = RefundsService(self)
52+
self.subscriptions = SubscriptionsService(self)
53+
self.transactions = TransactionsService(self)
4754
self.webhook_delivery_logs = WebhookDeliveryLogsService(self)
48-
55+
self.webhooks = WebhooksService(self)
56+
4957
def _request(
5058
self,
5159
method: str,
5260
path: str,
53-
model: Type[T] = None,
5461
params: Optional[Dict[str, Any]] = None,
5562
data: Optional[Dict[str, Any]] = None,
5663
) -> Any:
57-
"""Make an HTTP request to the API"""
5864
url = f"{self.base_url}{path}"
59-
60-
# Convert Pydantic models to dict if passed as data
61-
json_data = data
62-
if hasattr(data, 'dict'):
63-
json_data = data.dict(exclude_unset=True)
64-
65+
json_data = _flatten_data(data)
6566
try:
6667
response = self.session.request(
6768
method=method,
6869
url=url,
6970
params=params,
7071
json=json_data,
7172
)
72-
73+
7374
if response.status_code == 401:
74-
raise LomiAuthError("Invalid API key", response.status_code, response.json())
75-
elif response.status_code == 404:
76-
raise LomiNotFoundError("Resource not found", response.status_code, response.json())
77-
elif response.status_code >= 400:
78-
raise LomiError(f"API error: {response.text}", response.status_code, response.json() if response.text else None)
79-
80-
resp_data = response.json() if response.text else None
81-
82-
# If model class provided, parse response
83-
if model and resp_data:
84-
if isinstance(resp_data, list):
85-
return [model(**item) for item in resp_data]
86-
return model(**resp_data)
87-
88-
return resp_data
89-
75+
raise LomiAuthError(
76+
"Invalid API key",
77+
response.status_code,
78+
response.json() if response.content else None,
79+
)
80+
if response.status_code == 404:
81+
raise LomiNotFoundError(
82+
"Resource not found",
83+
response.status_code,
84+
response.json() if response.content else None,
85+
)
86+
if response.status_code >= 400:
87+
raise LomiError(
88+
f"API error: {response.text}",
89+
response.status_code,
90+
response.json() if response.text else None,
91+
)
92+
93+
return response.json() if response.content else None
9094
except requests.RequestException as e:
91-
raise LomiError(f"Request failed: {str(e)}")
95+
raise LomiError(f"Request failed: {type(e).__name__}: {e}") from e
96+

lomi/client_base.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11

2-
from typing import Optional, Dict, Any, List, Type, TypeVar, TYPE_CHECKING
2+
from typing import Optional, Dict, Any, TYPE_CHECKING
3+
import warnings
34
import requests
5+
46
from .exceptions import LomiError, LomiAuthError, LomiNotFoundError
5-
from pydantic import BaseModel
67

78
if TYPE_CHECKING:
89
from .client import LomiClient
910

10-
T = TypeVar("T", bound=BaseModel)
1111

1212
class ClientBase:
13-
def __init__(self, client: 'LomiClient'):
13+
"""HTTP helpers shared by generated services."""
14+
15+
def __init__(self, client: "LomiClient"):
1416
self._client = client
1517

16-
def _request(self, method: str, path: str, model: Type[T] = None, params: Optional[Dict[str, Any]] = None, data: Optional[Dict[str, Any]] = None) -> Any:
17-
return self._client._request(method, path, model, params, data)
18+
def _request(
19+
self,
20+
method: str,
21+
path: str,
22+
params: Optional[Dict[str, Any]] = None,
23+
data: Optional[Dict[str, Any]] = None,
24+
) -> Any:
25+
"""Make an HTTP request to the merchant API."""
26+
return self._client._request(method, path, params=params, data=data)

lomi/exceptions.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
"""
2-
lomi. SDK Exceptions
3-
AUTO-GENERATED - Do not edit manually
4-
"""
1+
"""lomi-sdk exceptions."""
2+
3+
from typing import Optional, Any
4+
55

66
class LomiError(Exception):
7-
"""Base exception for lomi. SDK"""
8-
def __init__(self, message: str, status_code: int = None, body: dict = None):
7+
"""Base SDK error."""
8+
9+
def __init__(self, message: str, status_code: Optional[int] = None, body: Any = None):
910
super().__init__(message)
1011
self.status_code = status_code
1112
self.body = body
1213

14+
1315
class LomiAuthError(LomiError):
14-
"""Authentication error"""
15-
pass
16+
"""Invalid API credentials."""
17+
1618

1719
class LomiNotFoundError(LomiError):
18-
"""Resource not found error"""
19-
pass
20+
"""Resource missing."""

lomi/models/__init__.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
"""
2-
lomi. Models
3-
"""
4-
from typing import *
1+
"""Types are dictated by the public API OpenAPI schema; use Dict[str, Any] or narrow in your app."""
2+
from typing import Any, Dict
53

6-
from .accounts import Accounts, AccountsCreate, AccountsUpdate
7-
from .organizations import Organizations, OrganizationsCreate, OrganizationsUpdate
8-
from .customers import Customers, CustomersCreate, CustomersUpdate
9-
from .payment_requests import PaymentRequests, PaymentRequestsCreate, PaymentRequestsUpdate
10-
from .transactions import Transactions, TransactionsCreate, TransactionsUpdate
11-
from .refunds import Refunds, RefundsCreate, RefundsUpdate
12-
from .products import Products, ProductsCreate, ProductsUpdate
13-
from .subscriptions import Subscriptions, SubscriptionsCreate, SubscriptionsUpdate
14-
from .discount_coupons import DiscountCoupons, DiscountCouponsCreate, DiscountCouponsUpdate
15-
from .checkout_sessions import CheckoutSessions, CheckoutSessionsCreate, CheckoutSessionsUpdate
16-
from .payment_links import PaymentLinks, PaymentLinksCreate, PaymentLinksUpdate
17-
from .payouts import Payouts, PayoutsCreate, PayoutsUpdate
18-
from .beneficiary_payouts import BeneficiaryPayouts, BeneficiaryPayoutsCreate, BeneficiaryPayoutsUpdate
19-
from .webhooks import Webhooks, WebhooksCreate, WebhooksUpdate
20-
from .webhook_delivery_logs import WebhookDeliveryLogs, WebhookDeliveryLogsCreate, WebhookDeliveryLogsUpdate
4+
__all__ = ["JSONDict"]
5+
JSONDict = Dict[str, Any]

lomi/models/accounts.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

lomi/models/beneficiary_payouts.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)