Skip to content

Commit 8600519

Browse files
RobertCraigierattrayalex
authored andcommitted
Bump
1 parent cd6c889 commit 8600519

84 files changed

Lines changed: 1842 additions & 1016 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The Lithic Python library provides convenient access to the Lithic REST API from
66
application. It includes type definitions for all request params and response fields,
77
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
88

9+
## Documentation
10+
11+
The API documentation can be found [here](https://docs.lithic.com).
12+
913
## Installation
1014

1115
```sh
@@ -17,13 +21,13 @@ pip install lithic
1721
```python
1822
from lithic import Lithic
1923

20-
client = Lithic(
21-
api_key="my api key", # defaults to os.environ.get("LITHIC_API_KEY")
22-
environment="sandbox" # defaults to "production"
24+
lithic = Lithic(
25+
api_key='my api key', # defaults to os.environ.get("LITHIC_API_KEY")
26+
environment='sandbox', # defaults to 'production'.
2327
)
2428

25-
card = client.cards.create({
26-
"type": "SINGLE_USE"
29+
card = lithic.cards.create({
30+
"type": "SINGLE_USE",
2731
})
2832

2933
print(card.token)
@@ -38,20 +42,19 @@ Simply import `AsyncLithic` instead of `Lithic` and use `await` with each API ca
3842

3943
```python
4044
from lithic import AsyncLithic
41-
import asyncio # or the async environment of your choice
4245

43-
client = AsyncLithic(
44-
api_key="my api key", # defaults to os.environ.get("LITHIC_API_KEY")
45-
environment="sandbox" # defaults to "production"
46+
lithic = AsyncLithic(
47+
api_key='my api key', # defaults to os.environ.get("LITHIC_API_KEY")
48+
environment='sandbox', # defaults to 'production'.
4649
)
4750

4851
async def main():
49-
card = await client.cards.create({
52+
card = await lithic.cards.create({
5053
"type": "SINGLE_USE"
5154
})
52-
5355
print(card.token)
5456

57+
5558
asyncio.run(main())
5659
```
5760

@@ -69,32 +72,37 @@ List methods in the Lithic API are paginated.
6972

7073
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
7174

72-
```python
73-
import lithic
75+
```py
7476
from typing import List
77+
import lithic
7578

76-
client = lithic.Lithic()
79+
lithic = Lithic()
7780

7881
all_cards = []
79-
# Iterate through items across all pages, issuing requests as needed.
80-
for card in client.cards.list():
82+
# Automatically fetches more pages as needed.
83+
for card in lithic.cards.list():
84+
# Do something with card here
8185
all_cards.append(card)
86+
return all_cards
8287
```
8388

8489
Or, asynchronously:
8590

8691
```python
87-
import lithic
92+
import asyncio
8893
from typing import List
94+
import lithic
8995

90-
client = lithic.AsyncLithic()
96+
lithic = AsyncLithic()
9197

92-
async def get_all_cards() -> List[lithic.types.Card]:
93-
cards = []
98+
async def main() -> None:
99+
all_cards = []
94100
# Iterate through items across all pages, issuing requests as needed.
95-
async for card in client.cards.list():
96-
cards.append(card)
97-
return cards
101+
async for card in lithic.cards.list():
102+
all_cards.append(card)
103+
return all_cards
104+
105+
asyncio.run(main())
98106
```
99107

100108
Alternatively, you can use the `.has_next_page()`, `.next_page_params()`,
@@ -132,20 +140,19 @@ response), a subclass of `lithic.APIStatusError` will be raised, containing `sta
132140
All errors inherit from `lithic.APIError`.
133141

134142
```python
135-
import lithic
143+
from lithic import Lithic
136144

137-
client = lithic.Lithic()
145+
lithic = Lithic()
138146

139147
try:
140-
client.cards.create()
141-
148+
lithic.cards.create({
149+
"type": "an_incorrect_type"
150+
})
142151
except lithic.APIConnectionError as e:
143152
print('The server could not be reached')
144153
print(e.__cause__) # an underlying Exception, likely raised within httpx.
145-
146154
except lithic.RateLimitError as e:
147155
print('A 429 status code was received; we should back off a bit.')
148-
149156
except lithic.APIStatusError as e:
150157
print('Another non-200-range status code was received')
151158
print(e.status_code)
@@ -177,10 +184,15 @@ You can use the `max_retries` option to configure or disable this:
177184
from lithic import Lithic
178185

179186
# Configure the default for all requests:
180-
client = Lithic(max_retries=0)
187+
lithic = Lithic(
188+
# default is 2
189+
max_retries=0,
190+
)
181191

182-
# Override per-request:
183-
client.cards.list({"page_size": 10}, max_retries=5)
192+
# Or, configure per-request:
193+
lithic.cards.list({
194+
"page_size": 10
195+
}, max_retries=5);
184196
```
185197

186198
### Timeouts
@@ -189,18 +201,23 @@ Requests time out after 60 seconds by default. You can configure this with a `ti
189201
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration):
190202

191203
```python
204+
from lithic import Lithic
205+
192206
# Configure the default for all requests:
193-
client = Lithic(
194-
timeout=20.0 # default is 60s.
207+
lithic = Lithic(
208+
# default is 60s
209+
timeout=20.0,
195210
)
196211

197212
# More granular control:
198-
client = Lithic(
199-
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0)
213+
lithic = Lithic(
214+
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
200215
)
201216

202217
# Override per-request:
203-
client.cards.list({"page_size": 10}, timeout=5.0)
218+
lithic.cards.list({
219+
"page_size": 10
220+
}, timeout=5 * 1000)
204221
```
205222

206223
On timeout, an `APITimeoutError` is thrown.
@@ -213,12 +230,13 @@ You can configure the following keyword arguments when instantiating the client:
213230

214231
```python
215232
import httpx
216-
import lithic
233+
from lithic import Lithic
217234

218-
client = lithic.Lithic(
219-
base_url="http://my.test.server.example.com:8083", # Use a custom base URL
220-
proxies="http://my.test.proxy.example.com",
221-
transport=httpx.HTTPTransport(local_address="0.0.0.0")
235+
lithic = Lithic(
236+
# Use a custom base URL
237+
base_url="http://my.test.server.example.com:8083",
238+
proxies="http://my.test.proxy.example.com",
239+
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
222240
)
223241
```
224242

lithic/__init__.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# File generated from our OpenAPI spec by Stainless.
22

33
from . import types
4+
from ._types import NoneType, Transport, ProxiesTypes
45
from ._client import (
56
ENVIRONMENTS,
67
Client,
@@ -13,7 +14,7 @@
1314
RequestOptions,
1415
)
1516
from ._version import __title__, __version__
16-
from .exceptions import (
17+
from ._exceptions import (
1718
APIError,
1819
ConflictError,
1920
NotFoundError,
@@ -33,26 +34,40 @@
3334
"types",
3435
"__version__",
3536
"__title__",
37+
"NoneType",
38+
"Transport",
39+
"ProxiesTypes",
3640
"APIError",
3741
"APIConnectionError",
38-
"APITimeoutError",
3942
"APIResponseValidationError",
40-
"BadRequestError",
43+
"APIStatusError",
44+
"APITimeoutError",
4145
"AuthenticationError",
42-
"PermissionDeniedError",
43-
"NotFoundError",
46+
"BadRequestError",
4447
"ConflictError",
45-
"UnprocessableEntityError",
46-
"RateLimitError",
4748
"InternalServerError",
48-
"APIStatusError",
49+
"NotFoundError",
50+
"PermissionDeniedError",
51+
"RateLimitError",
52+
"UnprocessableEntityError",
4953
"Timeout",
50-
"Transport",
51-
"ProxiesTypes",
5254
"RequestOptions",
5355
"Client",
5456
"AsyncClient",
5557
"Lithic",
5658
"AsyncLithic",
5759
"ENVIRONMENTS",
5860
]
61+
62+
# Update the __module__ attribute for exported symbols so that
63+
# error messages point to this module instead of the module
64+
# it was originally defined in, e.g.
65+
# lithic._base_exceptions.NotFoundError -> lithic.NotFoundError
66+
__locals = locals()
67+
for __name in __all__:
68+
if not __name.startswith("__"):
69+
try:
70+
setattr(__locals[__name], "__module__", "lithic")
71+
except (TypeError, AttributeError):
72+
# Some of our exported symbols are builtins which we can't set attributes for.
73+
pass

0 commit comments

Comments
 (0)