@@ -6,6 +6,10 @@ The Lithic Python library provides convenient access to the Lithic REST API from
66application. It includes type definitions for all request params and response fields,
77and 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
1822from 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
2933print (card.token)
@@ -38,20 +42,19 @@ Simply import `AsyncLithic` instead of `Lithic` and use `await` with each API ca
3842
3943``` python
4044from 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
4851async 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+
5558asyncio.run(main())
5659```
5760
@@ -69,32 +72,37 @@ List methods in the Lithic API are paginated.
6972
7073This 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
7476from typing import List
77+ import lithic
7578
76- client = lithic. Lithic()
79+ lithic = Lithic()
7780
7881all_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
8489Or, asynchronously:
8590
8691``` python
87- import lithic
92+ import asyncio
8893from 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
100108Alternatively, 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
132140All 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
139147try :
140- client.cards.create()
141-
148+ lithic.cards.create({
149+ " type" : " an_incorrect_type"
150+ })
142151except lithic.APIConnectionError as e:
143152 print (' The server could not be reached' )
144153 print (e.__cause__) # an underlying Exception, likely raised within httpx.
145-
146154except lithic.RateLimitError as e:
147155 print (' A 429 status code was received; we should back off a bit.' )
148-
149156except 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:
177184from 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
189201which 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
206223On timeout, an ` APITimeoutError ` is thrown.
@@ -213,12 +230,13 @@ You can configure the following keyword arguments when instantiating the client:
213230
214231``` python
215232import 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
0 commit comments