|
5 | 5 | First, create a client: |
6 | 6 |
|
7 | 7 | ```python |
8 | | -from {{ package_name }} import Client |
9 | | - |
10 | | -client = Client(base_url="https://api.example.com") |
11 | | -``` |
12 | | - |
13 | | -If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: |
14 | | - |
15 | | -```python |
16 | | -from {{ package_name }} import AuthenticatedClient |
17 | | - |
18 | | -client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") |
| 8 | +from {{ package_name }} import setup |
| 9 | + |
| 10 | +# Don't store this in plaintext in your code! |
| 11 | +client = setup( |
| 12 | + username="my_username", |
| 13 | + password="my_password", |
| 14 | + host="https://app.codegra.de", |
| 15 | +) |
19 | 16 | ``` |
20 | 17 |
|
21 | 18 | Now call your endpoint and use your models: |
22 | 19 |
|
23 | 20 | ```python |
24 | | -from {{ package_name }}.models import MyDataModel |
25 | | -from {{ package_name }}.api.my_tag import get_my_data_model |
26 | | - |
27 | | -my_data: MyDataModel = get_my_data_model(client=client) |
28 | | -``` |
29 | | - |
30 | | -Or do the same thing with an async version: |
31 | | - |
32 | | -```python |
33 | | -from {{ package_name }}.models import MyDataModel |
34 | | -from {{ package_name }}.async_api.my_tag import get_my_data_model |
35 | | - |
36 | | -my_data: MyDataModel = await get_my_data_model(client=client) |
| 21 | +from {{ package_name }}.models import PatchCourseData |
| 22 | + |
| 23 | +courses = client.course.get_all() |
| 24 | +for course in courses: |
| 25 | + client.course.patch( |
| 26 | + PatchCourseData(name=course.name + ' (NEW)'), |
| 27 | + course_id=course.id, |
| 28 | + ) |
37 | 29 | ``` |
38 | 30 |
|
39 | | -Things to know: |
40 | | -1. Every path/method combo becomes a Python function with type annotations. |
41 | | -1. All path/query params, and bodies become method arguments. |
42 | | -1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) |
43 | | -1. Any endpoint which did not have a tag will be in `{{ package_name }}.api.default` |
44 | | -1. If the API returns a response code that was not declared in the OpenAPI document, a |
45 | | - `{{ package_name }}.api.errors.ApiResponseError` wil be raised |
46 | | - with the `response` attribute set to the `httpx.Response` that was received. |
47 | | - |
48 | | - |
49 | | -## Building / publishing this Client |
50 | | -This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: |
51 | | -1. Update the metadata in pyproject.toml (e.g. authors, version) |
52 | | -1. If you're using a private repository, configure it with Poetry |
53 | | - 1. `poetry config repositories.<your-repository-name> <url-to-your-repository>` |
54 | | - 1. `poetry config http-basic.<your-repository-name> <username> <password>` |
55 | | -1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build` |
56 | | - |
57 | | -If you want to install this client into another project without publishing it (e.g. for development) then: |
58 | | -1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project |
59 | | -1. If that project is not using Poetry: |
60 | | - 1. Build a wheel with `poetry build -f wheel` |
61 | | - 1. Install that wheel from the other project `pip install <path-to-wheel>` |
| 31 | +## Installing |
| 32 | +This project uses [Poetry](https://python-poetry.org/) to manage dependencies |
| 33 | +and packaging. Currently you will need to install it using poetry, but in the |
| 34 | +future we will start releasing this package on pypi. |
0 commit comments