leal-sdk 0.0.11__tar.gz
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.
- leal_sdk-0.0.11/LICENSE +21 -0
- leal_sdk-0.0.11/PKG-INFO +243 -0
- leal_sdk-0.0.11/README.md +207 -0
- leal_sdk-0.0.11/pyproject.toml +105 -0
- leal_sdk-0.0.11/src/leal/__init__.py +216 -0
- leal_sdk-0.0.11/src/leal/_default_clients.py +30 -0
- leal_sdk-0.0.11/src/leal/cards/__init__.py +55 -0
- leal_sdk-0.0.11/src/leal/cards/client.py +412 -0
- leal_sdk-0.0.11/src/leal/cards/raw_client.py +784 -0
- leal_sdk-0.0.11/src/leal/cards/types/__init__.py +53 -0
- leal_sdk-0.0.11/src/leal/cards/types/create_cards_request_card.py +77 -0
- leal_sdk-0.0.11/src/leal/cards/types/create_cards_response.py +107 -0
- leal_sdk-0.0.11/src/leal/cards/types/get_cards_response.py +107 -0
- leal_sdk-0.0.11/src/leal/cards/types/list_cards_response_item.py +107 -0
- leal_sdk-0.0.11/src/leal/cards/types/update_cards_request_card.py +77 -0
- leal_sdk-0.0.11/src/leal/cards/types/update_cards_response.py +107 -0
- leal_sdk-0.0.11/src/leal/client.py +366 -0
- leal_sdk-0.0.11/src/leal/core/__init__.py +127 -0
- leal_sdk-0.0.11/src/leal/core/api_error.py +23 -0
- leal_sdk-0.0.11/src/leal/core/client_wrapper.py +147 -0
- leal_sdk-0.0.11/src/leal/core/datetime_utils.py +70 -0
- leal_sdk-0.0.11/src/leal/core/file.py +67 -0
- leal_sdk-0.0.11/src/leal/core/force_multipart.py +18 -0
- leal_sdk-0.0.11/src/leal/core/http_client.py +940 -0
- leal_sdk-0.0.11/src/leal/core/http_response.py +63 -0
- leal_sdk-0.0.11/src/leal/core/http_sse/__init__.py +42 -0
- leal_sdk-0.0.11/src/leal/core/http_sse/_api.py +455 -0
- leal_sdk-0.0.11/src/leal/core/http_sse/_decoders.py +74 -0
- leal_sdk-0.0.11/src/leal/core/http_sse/_exceptions.py +7 -0
- leal_sdk-0.0.11/src/leal/core/http_sse/_models.py +17 -0
- leal_sdk-0.0.11/src/leal/core/jsonable_encoder.py +133 -0
- leal_sdk-0.0.11/src/leal/core/logging.py +107 -0
- leal_sdk-0.0.11/src/leal/core/parse_error.py +36 -0
- leal_sdk-0.0.11/src/leal/core/pydantic_utilities.py +508 -0
- leal_sdk-0.0.11/src/leal/core/query_encoder.py +58 -0
- leal_sdk-0.0.11/src/leal/core/remove_none_from_dict.py +11 -0
- leal_sdk-0.0.11/src/leal/core/request_options.py +40 -0
- leal_sdk-0.0.11/src/leal/core/serialization.py +347 -0
- leal_sdk-0.0.11/src/leal/customer_cards/__init__.py +52 -0
- leal_sdk-0.0.11/src/leal/customer_cards/client.py +482 -0
- leal_sdk-0.0.11/src/leal/customer_cards/raw_client.py +821 -0
- leal_sdk-0.0.11/src/leal/customer_cards/types/__init__.py +50 -0
- leal_sdk-0.0.11/src/leal/customer_cards/types/get_customer_cards_response.py +108 -0
- leal_sdk-0.0.11/src/leal/customer_cards/types/list_customer_cards_response_item.py +93 -0
- leal_sdk-0.0.11/src/leal/customer_cards/types/redeem_customer_cards_response.py +24 -0
- leal_sdk-0.0.11/src/leal/customer_cards/types/redeem_customer_cards_response_redemption.py +47 -0
- leal_sdk-0.0.11/src/leal/customer_cards/types/stamp_customer_cards_response.py +108 -0
- leal_sdk-0.0.11/src/leal/customers/__init__.py +58 -0
- leal_sdk-0.0.11/src/leal/customers/client.py +524 -0
- leal_sdk-0.0.11/src/leal/customers/raw_client.py +880 -0
- leal_sdk-0.0.11/src/leal/customers/types/__init__.py +56 -0
- leal_sdk-0.0.11/src/leal/customers/types/create_customers_request_customer.py +52 -0
- leal_sdk-0.0.11/src/leal/customers/types/create_customers_response.py +82 -0
- leal_sdk-0.0.11/src/leal/customers/types/get_customers_response.py +82 -0
- leal_sdk-0.0.11/src/leal/customers/types/list_customers_response.py +25 -0
- leal_sdk-0.0.11/src/leal/customers/types/list_customers_response_pagination.py +37 -0
- leal_sdk-0.0.11/src/leal/customers/types/update_customers_request_customer.py +52 -0
- leal_sdk-0.0.11/src/leal/customers/types/update_customers_response.py +82 -0
- leal_sdk-0.0.11/src/leal/environment.py +7 -0
- leal_sdk-0.0.11/src/leal/errors/__init__.py +42 -0
- leal_sdk-0.0.11/src/leal/errors/not_found_error.py +11 -0
- leal_sdk-0.0.11/src/leal/errors/too_many_requests_error.py +11 -0
- leal_sdk-0.0.11/src/leal/errors/unauthorized_error.py +11 -0
- leal_sdk-0.0.11/src/leal/errors/unprocessable_entity_error.py +11 -0
- leal_sdk-0.0.11/src/leal/locations/__init__.py +55 -0
- leal_sdk-0.0.11/src/leal/locations/client.py +480 -0
- leal_sdk-0.0.11/src/leal/locations/raw_client.py +908 -0
- leal_sdk-0.0.11/src/leal/locations/types/__init__.py +53 -0
- leal_sdk-0.0.11/src/leal/locations/types/create_locations_request_location.py +27 -0
- leal_sdk-0.0.11/src/leal/locations/types/create_locations_response.py +57 -0
- leal_sdk-0.0.11/src/leal/locations/types/get_locations_response.py +57 -0
- leal_sdk-0.0.11/src/leal/locations/types/list_locations_response_item.py +57 -0
- leal_sdk-0.0.11/src/leal/locations/types/update_locations_request_location.py +27 -0
- leal_sdk-0.0.11/src/leal/locations/types/update_locations_response.py +57 -0
- leal_sdk-0.0.11/src/leal/posters/__init__.py +55 -0
- leal_sdk-0.0.11/src/leal/posters/client.py +504 -0
- leal_sdk-0.0.11/src/leal/posters/raw_client.py +962 -0
- leal_sdk-0.0.11/src/leal/posters/types/__init__.py +53 -0
- leal_sdk-0.0.11/src/leal/posters/types/create_posters_request_poster.py +52 -0
- leal_sdk-0.0.11/src/leal/posters/types/create_posters_response.py +87 -0
- leal_sdk-0.0.11/src/leal/posters/types/get_posters_response.py +87 -0
- leal_sdk-0.0.11/src/leal/posters/types/list_posters_response_item.py +87 -0
- leal_sdk-0.0.11/src/leal/posters/types/update_posters_request_poster.py +47 -0
- leal_sdk-0.0.11/src/leal/posters/types/update_posters_response.py +87 -0
- leal_sdk-0.0.11/src/leal/py.typed +0 -0
- leal_sdk-0.0.11/src/leal/rewards/__init__.py +55 -0
- leal_sdk-0.0.11/src/leal/rewards/client.py +506 -0
- leal_sdk-0.0.11/src/leal/rewards/raw_client.py +960 -0
- leal_sdk-0.0.11/src/leal/rewards/types/__init__.py +53 -0
- leal_sdk-0.0.11/src/leal/rewards/types/create_rewards_request_reward.py +47 -0
- leal_sdk-0.0.11/src/leal/rewards/types/create_rewards_response.py +67 -0
- leal_sdk-0.0.11/src/leal/rewards/types/get_rewards_response.py +67 -0
- leal_sdk-0.0.11/src/leal/rewards/types/list_rewards_response_item.py +67 -0
- leal_sdk-0.0.11/src/leal/rewards/types/update_rewards_request_reward.py +42 -0
- leal_sdk-0.0.11/src/leal/rewards/types/update_rewards_response.py +67 -0
- leal_sdk-0.0.11/src/leal/status/__init__.py +34 -0
- leal_sdk-0.0.11/src/leal/status/client.py +108 -0
- leal_sdk-0.0.11/src/leal/status/raw_client.py +133 -0
- leal_sdk-0.0.11/src/leal/status/types/__init__.py +38 -0
- leal_sdk-0.0.11/src/leal/status/types/check_status_response.py +49 -0
- leal_sdk-0.0.11/src/leal/status/types/check_status_response_rate_limit.py +32 -0
- leal_sdk-0.0.11/src/leal/stores/__init__.py +39 -0
- leal_sdk-0.0.11/src/leal/stores/client.py +260 -0
- leal_sdk-0.0.11/src/leal/stores/raw_client.py +508 -0
- leal_sdk-0.0.11/src/leal/stores/types/__init__.py +42 -0
- leal_sdk-0.0.11/src/leal/stores/types/get_stores_response.py +72 -0
- leal_sdk-0.0.11/src/leal/stores/types/list_stores_response_item.py +72 -0
- leal_sdk-0.0.11/src/leal/stores/types/update_stores_request_account.py +27 -0
- leal_sdk-0.0.11/src/leal/stores/types/update_stores_response.py +72 -0
- leal_sdk-0.0.11/src/leal/types/__init__.py +35 -0
- leal_sdk-0.0.11/src/leal/types/error.py +32 -0
- leal_sdk-0.0.11/src/leal/types/error_errors.py +5 -0
- leal_sdk-0.0.11/src/leal/version.py +3 -0
leal_sdk-0.0.11/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Leal.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
leal_sdk-0.0.11/PKG-INFO
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: leal-sdk
|
|
3
|
+
Version: 0.0.11
|
|
4
|
+
Summary:
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: leal,loyalty,stamp cards,apple wallet,google wallet
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Operating System :: POSIX
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Provides-Extra: aiohttp
|
|
26
|
+
Requires-Dist: aiohttp (>=3.14.1,<4) ; (python_version >= "3.10") and (extra == "aiohttp")
|
|
27
|
+
Requires-Dist: httpx (>=0.21.2)
|
|
28
|
+
Requires-Dist: httpx-aiohttp (>=0.1.8,<0.2.0) ; (python_version >= "3.10") and (extra == "aiohttp")
|
|
29
|
+
Requires-Dist: pydantic (>=1.9.2)
|
|
30
|
+
Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
|
|
31
|
+
Requires-Dist: typing_extensions (>=4.0.0)
|
|
32
|
+
Project-URL: Documentation, https://www.getleal.com/developers/python
|
|
33
|
+
Project-URL: Repository, https://github.com/lealhq/leal-python-sdk
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# Leal Python Library
|
|
37
|
+
|
|
38
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Flealhq%2Fleal-python-sdk)
|
|
39
|
+
[](https://pypi.python.org/pypi/leal-sdk)
|
|
40
|
+
|
|
41
|
+
Digital loyalty stamp cards in Apple Wallet and Google Wallet, for local
|
|
42
|
+
businesses. This library covers the whole [Leal](https://www.getleal.com)
|
|
43
|
+
API, so you can enrol customers, add stamps, redeem rewards and read a
|
|
44
|
+
card's wallet links from your own application.
|
|
45
|
+
|
|
46
|
+
- Guides and a page for every language: [www.getleal.com/developers](https://www.getleal.com/developers)
|
|
47
|
+
- Create an API token: [app.getleal.com/api_tokens](https://app.getleal.com/api_tokens)
|
|
48
|
+
- The OpenAPI description these libraries are built from: [www.getleal.com/openapi.json](https://www.getleal.com/openapi.json)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Table of Contents
|
|
52
|
+
|
|
53
|
+
- [Documentation](#documentation)
|
|
54
|
+
- [Installation](#installation)
|
|
55
|
+
- [Reference](#reference)
|
|
56
|
+
- [Usage](#usage)
|
|
57
|
+
- [Environments](#environments)
|
|
58
|
+
- [Async Client](#async-client)
|
|
59
|
+
- [Exception Handling](#exception-handling)
|
|
60
|
+
- [Advanced](#advanced)
|
|
61
|
+
- [Access Raw Response Data](#access-raw-response-data)
|
|
62
|
+
- [Retries](#retries)
|
|
63
|
+
- [Timeouts](#timeouts)
|
|
64
|
+
- [Custom Client](#custom-client)
|
|
65
|
+
- [Contributing](#contributing)
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
API reference documentation is available [here](https://app.getleal.com/docs/api.html).
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
pip install leal-sdk
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Reference
|
|
78
|
+
|
|
79
|
+
A full reference for this library is available [here](https://github.com/lealhq/leal-python-sdk/blob/HEAD/./reference.md).
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
Instantiate and use the client with the following:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from leal import Leal
|
|
87
|
+
|
|
88
|
+
client = Leal(
|
|
89
|
+
token="<token>",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
client.customer_cards.stamp(
|
|
93
|
+
account_id=1,
|
|
94
|
+
customer_id=1,
|
|
95
|
+
id=1,
|
|
96
|
+
stamps=1,
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Environments
|
|
101
|
+
|
|
102
|
+
This SDK allows you to configure different environments for API requests.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from leal import Leal
|
|
106
|
+
from leal.environment import LealEnvironment
|
|
107
|
+
|
|
108
|
+
client = Leal(
|
|
109
|
+
environment=LealEnvironment.PRODUCTION,
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Async Client
|
|
114
|
+
|
|
115
|
+
The SDK also exports an `async` client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use `httpx.AsyncClient()` instead of `httpx.Client()` (e.g. for the `httpx_client` parameter of this client).
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import asyncio
|
|
119
|
+
|
|
120
|
+
from leal import AsyncLeal
|
|
121
|
+
|
|
122
|
+
client = AsyncLeal(
|
|
123
|
+
token="<token>",
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
async def main() -> None:
|
|
128
|
+
await client.customer_cards.stamp(
|
|
129
|
+
account_id=1,
|
|
130
|
+
customer_id=1,
|
|
131
|
+
id=1,
|
|
132
|
+
stamps=1,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
asyncio.run(main())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Exception Handling
|
|
140
|
+
|
|
141
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
|
142
|
+
will be thrown.
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from leal.core.api_error import ApiError
|
|
146
|
+
|
|
147
|
+
try:
|
|
148
|
+
client.customer_cards.stamp(...)
|
|
149
|
+
except ApiError as e:
|
|
150
|
+
print(e.status_code)
|
|
151
|
+
print(e.body)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Advanced
|
|
155
|
+
|
|
156
|
+
### Access Raw Response Data
|
|
157
|
+
|
|
158
|
+
The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
|
|
159
|
+
The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from leal import Leal
|
|
163
|
+
|
|
164
|
+
client = Leal(...)
|
|
165
|
+
response = client.customer_cards.with_raw_response.stamp(...)
|
|
166
|
+
print(response.headers) # access the response headers
|
|
167
|
+
print(response.status_code) # access the response status code
|
|
168
|
+
print(response.data) # access the underlying object
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Retries
|
|
172
|
+
|
|
173
|
+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
174
|
+
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
|
|
175
|
+
retry limit (default: 2).
|
|
176
|
+
|
|
177
|
+
Which status codes are retried depends on the `retryStatusCodes` generator configuration:
|
|
178
|
+
|
|
179
|
+
**`legacy`** (current default): retries on
|
|
180
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
181
|
+
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
|
|
182
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
183
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)
|
|
184
|
+
|
|
185
|
+
**`recommended`**: retries on
|
|
186
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
187
|
+
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
|
|
188
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
189
|
+
- [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
|
|
190
|
+
- [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
|
|
191
|
+
- [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)
|
|
192
|
+
|
|
193
|
+
Use the `max_retries` request option to configure this behavior.
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
client.customer_cards.stamp(..., request_options={
|
|
197
|
+
"max_retries": 1
|
|
198
|
+
})
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Timeouts
|
|
202
|
+
|
|
203
|
+
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from leal import Leal
|
|
207
|
+
|
|
208
|
+
client = Leal(..., timeout=20.0)
|
|
209
|
+
|
|
210
|
+
# Override timeout for a specific method
|
|
211
|
+
client.customer_cards.stamp(..., request_options={
|
|
212
|
+
"timeout": 1
|
|
213
|
+
})
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Custom Client
|
|
217
|
+
|
|
218
|
+
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
|
|
219
|
+
and transports.
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
import httpx
|
|
223
|
+
from leal import Leal
|
|
224
|
+
|
|
225
|
+
client = Leal(
|
|
226
|
+
...,
|
|
227
|
+
httpx_client=httpx.Client(
|
|
228
|
+
proxy="http://my.test.proxy.example.com",
|
|
229
|
+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
|
230
|
+
),
|
|
231
|
+
)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Contributing
|
|
235
|
+
|
|
236
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
237
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
238
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
239
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
240
|
+
an issue first to discuss with us!
|
|
241
|
+
|
|
242
|
+
On the other hand, contributions to the README are always very welcome!
|
|
243
|
+
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Leal Python Library
|
|
2
|
+
|
|
3
|
+
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Flealhq%2Fleal-python-sdk)
|
|
4
|
+
[](https://pypi.python.org/pypi/leal-sdk)
|
|
5
|
+
|
|
6
|
+
Digital loyalty stamp cards in Apple Wallet and Google Wallet, for local
|
|
7
|
+
businesses. This library covers the whole [Leal](https://www.getleal.com)
|
|
8
|
+
API, so you can enrol customers, add stamps, redeem rewards and read a
|
|
9
|
+
card's wallet links from your own application.
|
|
10
|
+
|
|
11
|
+
- Guides and a page for every language: [www.getleal.com/developers](https://www.getleal.com/developers)
|
|
12
|
+
- Create an API token: [app.getleal.com/api_tokens](https://app.getleal.com/api_tokens)
|
|
13
|
+
- The OpenAPI description these libraries are built from: [www.getleal.com/openapi.json](https://www.getleal.com/openapi.json)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
- [Documentation](#documentation)
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Reference](#reference)
|
|
21
|
+
- [Usage](#usage)
|
|
22
|
+
- [Environments](#environments)
|
|
23
|
+
- [Async Client](#async-client)
|
|
24
|
+
- [Exception Handling](#exception-handling)
|
|
25
|
+
- [Advanced](#advanced)
|
|
26
|
+
- [Access Raw Response Data](#access-raw-response-data)
|
|
27
|
+
- [Retries](#retries)
|
|
28
|
+
- [Timeouts](#timeouts)
|
|
29
|
+
- [Custom Client](#custom-client)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
|
|
32
|
+
## Documentation
|
|
33
|
+
|
|
34
|
+
API reference documentation is available [here](https://app.getleal.com/docs/api.html).
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pip install leal-sdk
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Reference
|
|
43
|
+
|
|
44
|
+
A full reference for this library is available [here](https://github.com/lealhq/leal-python-sdk/blob/HEAD/./reference.md).
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
Instantiate and use the client with the following:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from leal import Leal
|
|
52
|
+
|
|
53
|
+
client = Leal(
|
|
54
|
+
token="<token>",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
client.customer_cards.stamp(
|
|
58
|
+
account_id=1,
|
|
59
|
+
customer_id=1,
|
|
60
|
+
id=1,
|
|
61
|
+
stamps=1,
|
|
62
|
+
)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Environments
|
|
66
|
+
|
|
67
|
+
This SDK allows you to configure different environments for API requests.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from leal import Leal
|
|
71
|
+
from leal.environment import LealEnvironment
|
|
72
|
+
|
|
73
|
+
client = Leal(
|
|
74
|
+
environment=LealEnvironment.PRODUCTION,
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Async Client
|
|
79
|
+
|
|
80
|
+
The SDK also exports an `async` client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use `httpx.AsyncClient()` instead of `httpx.Client()` (e.g. for the `httpx_client` parameter of this client).
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import asyncio
|
|
84
|
+
|
|
85
|
+
from leal import AsyncLeal
|
|
86
|
+
|
|
87
|
+
client = AsyncLeal(
|
|
88
|
+
token="<token>",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async def main() -> None:
|
|
93
|
+
await client.customer_cards.stamp(
|
|
94
|
+
account_id=1,
|
|
95
|
+
customer_id=1,
|
|
96
|
+
id=1,
|
|
97
|
+
stamps=1,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
asyncio.run(main())
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Exception Handling
|
|
105
|
+
|
|
106
|
+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
|
|
107
|
+
will be thrown.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from leal.core.api_error import ApiError
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
client.customer_cards.stamp(...)
|
|
114
|
+
except ApiError as e:
|
|
115
|
+
print(e.status_code)
|
|
116
|
+
print(e.body)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Advanced
|
|
120
|
+
|
|
121
|
+
### Access Raw Response Data
|
|
122
|
+
|
|
123
|
+
The SDK provides access to raw response data, including headers, through the `.with_raw_response` property.
|
|
124
|
+
The `.with_raw_response` property returns a "raw" client that can be used to access the `.headers` and `.data` attributes.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from leal import Leal
|
|
128
|
+
|
|
129
|
+
client = Leal(...)
|
|
130
|
+
response = client.customer_cards.with_raw_response.stamp(...)
|
|
131
|
+
print(response.headers) # access the response headers
|
|
132
|
+
print(response.status_code) # access the response status code
|
|
133
|
+
print(response.data) # access the underlying object
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Retries
|
|
137
|
+
|
|
138
|
+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
|
|
139
|
+
as the request is deemed retryable and the number of retry attempts has not grown larger than the configured
|
|
140
|
+
retry limit (default: 2).
|
|
141
|
+
|
|
142
|
+
Which status codes are retried depends on the `retryStatusCodes` generator configuration:
|
|
143
|
+
|
|
144
|
+
**`legacy`** (current default): retries on
|
|
145
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
146
|
+
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
|
|
147
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
148
|
+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (All server errors, including 500)
|
|
149
|
+
|
|
150
|
+
**`recommended`**: retries on
|
|
151
|
+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
|
|
152
|
+
- [409](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409) (Conflict)
|
|
153
|
+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
|
|
154
|
+
- [502](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502) (Bad Gateway)
|
|
155
|
+
- [503](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/503) (Service Unavailable)
|
|
156
|
+
- [504](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/504) (Gateway Timeout)
|
|
157
|
+
|
|
158
|
+
Use the `max_retries` request option to configure this behavior.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
client.customer_cards.stamp(..., request_options={
|
|
162
|
+
"max_retries": 1
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Timeouts
|
|
167
|
+
|
|
168
|
+
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from leal import Leal
|
|
172
|
+
|
|
173
|
+
client = Leal(..., timeout=20.0)
|
|
174
|
+
|
|
175
|
+
# Override timeout for a specific method
|
|
176
|
+
client.customer_cards.stamp(..., request_options={
|
|
177
|
+
"timeout": 1
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Custom Client
|
|
182
|
+
|
|
183
|
+
You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
|
|
184
|
+
and transports.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
import httpx
|
|
188
|
+
from leal import Leal
|
|
189
|
+
|
|
190
|
+
client = Leal(
|
|
191
|
+
...,
|
|
192
|
+
httpx_client=httpx.Client(
|
|
193
|
+
proxy="http://my.test.proxy.example.com",
|
|
194
|
+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
|
|
195
|
+
),
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Contributing
|
|
200
|
+
|
|
201
|
+
While we value open-source contributions to this SDK, this library is generated programmatically.
|
|
202
|
+
Additions made directly to this library would have to be moved over to our generation code,
|
|
203
|
+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
|
|
204
|
+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
|
|
205
|
+
an issue first to discuss with us!
|
|
206
|
+
|
|
207
|
+
On the other hand, contributions to the README are always very welcome!
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "leal-sdk"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
|
|
5
|
+
[tool.poetry]
|
|
6
|
+
name = "leal-sdk"
|
|
7
|
+
version = "0.0.11"
|
|
8
|
+
description = ""
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = []
|
|
11
|
+
keywords = [
|
|
12
|
+
"leal",
|
|
13
|
+
"loyalty",
|
|
14
|
+
"stamp cards",
|
|
15
|
+
"apple wallet",
|
|
16
|
+
"google wallet"
|
|
17
|
+
]
|
|
18
|
+
license = "MIT"
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
"Programming Language :: Python :: 3.15",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Operating System :: POSIX",
|
|
31
|
+
"Operating System :: MacOS",
|
|
32
|
+
"Operating System :: POSIX :: Linux",
|
|
33
|
+
"Operating System :: Microsoft :: Windows",
|
|
34
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
35
|
+
"Typing :: Typed",
|
|
36
|
+
"License :: OSI Approved :: MIT License"
|
|
37
|
+
]
|
|
38
|
+
packages = [
|
|
39
|
+
{ include = "leal", from = "src"}
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.poetry.urls]
|
|
43
|
+
Documentation = 'https://www.getleal.com/developers/python'
|
|
44
|
+
Repository = 'https://github.com/lealhq/leal-python-sdk'
|
|
45
|
+
|
|
46
|
+
[tool.poetry.dependencies]
|
|
47
|
+
python = "^3.10"
|
|
48
|
+
aiohttp = { version = ">=3.14.1,<4", optional = true, python = ">=3.10"}
|
|
49
|
+
httpx = ">=0.21.2"
|
|
50
|
+
httpx-aiohttp = { version = "^0.1.8", optional = true, python = ">=3.10"}
|
|
51
|
+
pydantic = ">= 1.9.2"
|
|
52
|
+
pydantic-core = ">=2.18.2,<3.0.0"
|
|
53
|
+
typing_extensions = ">= 4.0.0"
|
|
54
|
+
|
|
55
|
+
[tool.poetry.group.dev.dependencies]
|
|
56
|
+
mypy = "==1.13.0"
|
|
57
|
+
pytest = "^9.0.3"
|
|
58
|
+
pytest-asyncio = "^1.0.0"
|
|
59
|
+
pytest-xdist = "^3.6.1"
|
|
60
|
+
python-dateutil = "^2.9.0"
|
|
61
|
+
types-python-dateutil = "^2.9.0.20240316"
|
|
62
|
+
urllib3 = ">=2.6.3,<3.0.0"
|
|
63
|
+
ruff = "==0.11.5"
|
|
64
|
+
|
|
65
|
+
[tool.pytest.ini_options]
|
|
66
|
+
testpaths = [ "tests" ]
|
|
67
|
+
asyncio_mode = "auto"
|
|
68
|
+
norecursedirs = [ "src" ]
|
|
69
|
+
markers = [
|
|
70
|
+
"aiohttp: tests that require httpx_aiohttp to be installed",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[tool.mypy]
|
|
74
|
+
plugins = ["pydantic.mypy"]
|
|
75
|
+
|
|
76
|
+
[tool.ruff]
|
|
77
|
+
line-length = 120
|
|
78
|
+
|
|
79
|
+
[tool.ruff.lint]
|
|
80
|
+
select = [
|
|
81
|
+
"E", # pycodestyle errors
|
|
82
|
+
"F", # pyflakes
|
|
83
|
+
"I", # isort
|
|
84
|
+
]
|
|
85
|
+
ignore = [
|
|
86
|
+
"E402", # Module level import not at top of file
|
|
87
|
+
"E501", # Line too long
|
|
88
|
+
"E711", # Comparison to `None` should be `cond is not None`
|
|
89
|
+
"E712", # Avoid equality comparisons to `True`; use `if ...:` checks
|
|
90
|
+
"E721", # Use `is` and `is not` for type comparisons, or `isinstance()` for insinstance checks
|
|
91
|
+
"E722", # Do not use bare `except`
|
|
92
|
+
"E731", # Do not assign a `lambda` expression, use a `def`
|
|
93
|
+
"F821", # Undefined name
|
|
94
|
+
"F841" # Local variable ... is assigned to but never used
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
[tool.ruff.lint.isort]
|
|
98
|
+
section-order = ["future", "standard-library", "third-party", "first-party"]
|
|
99
|
+
|
|
100
|
+
[build-system]
|
|
101
|
+
requires = ["poetry-core"]
|
|
102
|
+
build-backend = "poetry.core.masonry.api"
|
|
103
|
+
|
|
104
|
+
[tool.poetry.extras]
|
|
105
|
+
aiohttp=["aiohttp", "httpx-aiohttp"]
|