|
2 | 2 |
|
3 | 3 | [](https://github.com/python-lapidary/lapidary/actions/workflows/test_publish.yaml) |
4 | 4 |
|
5 | | -Python DSL for Web API clients. |
| 5 | +Python Helper for Web API clients. |
6 | 6 |
|
7 | 7 | ## Why |
8 | 8 |
|
9 | | -Web API clients follow a relatively small set of patterns and implementing them is rather repetitive task. Encapsulating these patterns in form of a DSL library frees its users from coding the same patterns over and over again. |
| 9 | +Web API clients follow a relatively small set of patterns and implementing them is rather repetitive task. |
| 10 | +Prepare request, make the call, handle response status, deserialize the body |
| 11 | +Typical examples show how to use `request.get()` or similar method, but this is an anti-pattern. These calls should be encapsulated as module functions or methods. |
10 | 12 |
|
11 | 13 | ## How |
12 | 14 |
|
13 | | -Lapidary is an internal (in-python) DSL made of decorators and annotations, that can be used to describe Web APIs similarly to OpenAPI. |
14 | | -([lapidary-render](https://github.com/python-lapidary/lapidary-render/) can convert a large subset of OpenAPI 3.0 to Lapidary). |
15 | | - |
16 | | -At runtime, the library interprets user-provided function declarations (without bodies), and makes them behave as declared. If a function accepts parameter of type `X` and returns `Y`, Lapidary will try to convert `X` to HTTP request and the response to `Y`. |
17 | | - |
18 | | -### Example: |
19 | | - |
20 | | -```python |
21 | | -class CatClient(ClientBase): |
22 | | - """This class is a working API client""" |
23 | | - |
24 | | - def __init__(self): |
25 | | - super().__init__( |
26 | | - base_url='https://example.com/api', |
27 | | - ) |
28 | | - |
29 | | - @get('/cat') |
30 | | - async def list_cats(self: Self) -> Annotated[ |
31 | | - tuple[list[Cat], CatListMeta], |
32 | | - Responses({ |
33 | | - '2XX': Response( |
34 | | - Body({ |
35 | | - 'application/json': list[Cat], |
36 | | - }), |
37 | | - CatListMeta |
38 | | - ), |
39 | | - }) |
40 | | - ]: |
41 | | - pass |
42 | | - |
43 | | -client = CatClient() |
44 | | -cats_body, cats_meta = await client.list_cats() |
45 | | -``` |
| 15 | +Lapidary is a library that provides decorators and annotations for describing Web APIs in a way similar to OpenAPI. |
| 16 | +In fact [lapidary render](https://github.com/python-lapidary/lapidary-render/) can convert much of OpenAPI 3.0 to Lapidary code. |
| 17 | + |
| 18 | +At runtime, the library interprets user-provided function declarations and makes them behave as specified. |
| 19 | +If a function accepts parameter of type `X` and returns `Y`, Lapidary will try to convert `X` to HTTP request and the response back to `Y`. |
| 20 | + |
| 21 | +Check the [example](https://python-lapidary.github.io/lapidary/#usage) |
0 commit comments