|
1 | 1 | # LocalStack Python SDK
|
2 | 2 |
|
3 |
| -This repository is a PoC for generating a Python SDK for the LocalStack public endpoint. |
4 |
| - |
5 |
| -### Generate the spec |
6 |
| - |
7 |
| -The first step is to generate the `openapi.yaml` spec. |
8 |
| -We have a script in `scripts/create_spec.py` |
9 |
| -- [ ] todo: fix the script; make sure it also fetches ext spec; |
10 |
| -`localstack-core` and `localstack-ext` are part of the dev dependencies for this very step. |
11 |
| - |
12 |
| -### Generate the code |
13 |
| -We use openapi-generator from `openapitools`. |
14 |
| -To run the generation, run `./bin/generate.sh`. |
15 |
| -The script uses the docker image of the CLI and use the `openapi.yaml` file as input. |
16 |
| -By default, the generator creates a bunch of files, but the most important things are: |
17 |
| -- `api` package: with the all APIs categorized by tags; |
18 |
| -- `models` package: with the methods derived from the components or the inline specs; |
19 |
| -- [ ] the code from the inline components is much uglier, but we can overwrite some naming with come config (or move to components). |
20 |
| - |
21 |
| -The python generator by default creates 3 functions for each path: |
22 |
| -- a normal function (the name is taken from the `operationId` in the specs) just with the validated response payload; |
23 |
| -- a function suffixed by `without_preloaded_content`: where the JSON responses are not validated; |
24 |
| -- a function suffixed by `with_http_info` which also returns the response header and status. |
25 |
| - |
26 |
| -The code in these `api` files (but also in any other generated artifacts), can be modified by providing custom mustache templates. |
27 |
| -[These](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/python) are the |
28 |
| -default for Python. |
29 |
| -Templates are not super immediate, but looking at them and at the generated code you can do it. |
30 |
| -For instance, I deleted the `without_preloaded_content` and `with_http_info` generated functions. |
31 |
| - |
32 |
| -### Supporting files |
33 |
| -The generated code uses some supporting files, i.e., some utilities that are responsible of making the actual HTTP calls, |
34 |
| -validating and parsing the responses. |
35 |
| -I just checked in this code and take it as granted, but I am pretty sure we can come up with some simpler code and avoid |
36 |
| -to generate this part (would move out from `generated`). |
37 |
| -- [ ] see if I can write my own api client and all the necessary supporting code. |
38 |
| - |
39 |
| -### TODO |
40 |
| -- [ ] understand if this can be viable at all; |
41 |
| -- [ ] devise a way to update the spec automatically and regenerate every time the code in `generated`; |
42 |
| -- much more...fill this list up |
| 3 | +This is the Python SDK for LocalStack. |
| 4 | +LocalStack offers a number of developer endpoints (see [docs](https://docs.localstack.cloud/references/internal-endpoints/)). |
| 5 | +This SDK provides a programmatic and easy way to interact with them. |
| 6 | + |
| 7 | +> [!WARNING] |
| 8 | +> This project is still in a preview phase, and will be subject to fast and breaking changes. |
| 9 | +
|
| 10 | +### Project Structure |
| 11 | + |
| 12 | +This project follows the following structure: |
| 13 | + |
| 14 | +- `packages/localstack-sdk-generated` is a python project generated from the OpenAPI specs with [openapi-generator](https://github.com/OpenAPITools/openapi-generator). |
| 15 | +- `localstack-sdk-python` is the main project that has `localstack-sdk-generated` has the main dependency. |
| 16 | + |
| 17 | +Developers are not supposed to modify at all `localstack-sdk-generated`. |
| 18 | +The code needs to be every time re-generated from specs using the `generate.sh` script in the `bin` folder. |
| 19 | + |
| 20 | +This project uses [uv](https://github.com/astral-sh/uv) as package/project manager. |
| 21 | + |
| 22 | +### Install & Run |
| 23 | + |
| 24 | +You can simply run `make install-dev` to install the two packages and the needed dependencies. |
| 25 | +`make test` runs the test suite. |
| 26 | +Note that LocalStack (pro) should be running in the background to execute the test. |
0 commit comments