Skip to content

Commit a949288

Browse files
authored
docs: update MAINTAINERS_GUIDE and README.md (#17)
1 parent ac3f241 commit a949288

File tree

5 files changed

+142
-45
lines changed

5 files changed

+142
-45
lines changed

MAINTAINERS_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Or just follow these steps:
1212
1. Copy and rename the source openapi file the `openapi_specification/nadag-innmelding.yaml`
1313
2. Run the following command to generate the client code:
1414
```bash
15-
uvx openapi-python-client generate --path openapi_specification/nadag-innmelding.yaml --overwrite --custom-template-path=templates --config config.yaml
15+
uvx openapi-python-client generate --path openapi_specification/nadag-innmelding.yaml --overwrite --custom-template-path=templates --config config.yaml --meta=uv
1616
```
1717
3. Check in the changes to the repository (files updated, added, or removed).
1818
4. In the GitHub project, create a new release and the package should be published to PyPi.

nadag-innmelding-python-client/README.md

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,40 @@ A client library for accessing Nadag innmelding API
55
First, create a client:
66

77
```python
8-
from nadag_innmelding_python_client import Client
9-
10-
client = Client(base_url="https://api.example.com")
11-
```
8+
from nadag_innmelding_python_client import AuthenticatedClient
129

13-
If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
10+
secret_token = nadag_authenticate() # This you need to implement this yourself
1411

15-
```python
16-
from nadag_innmelding_python_client import AuthenticatedClient
12+
client = AuthenticatedClient(
13+
base_url="https://test.ngu.no/api/",
14+
token=secret_token,
15+
)
1716

18-
client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
1917
```
2018

2119
Now call your endpoint and use your models:
2220

2321
```python
24-
from nadag_innmelding_python_client.models import MyDataModel
25-
from nadag_innmelding_python_client.api.my_tag import get_my_data_model
22+
from nadag_innmelding_python_client.api.default import get_nadag_innmelding_v_1_geoteknisk_unders as get_geoteknisk_unders
23+
from nadag_innmelding_python_client.models import GeotekniskUnders
2624
from nadag_innmelding_python_client.types import Response
2725

2826
with client as client:
29-
my_data: MyDataModel = get_my_data_model.sync(client=client)
30-
# or if you need more info (e.g. status_code)
31-
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
32-
```
33-
34-
Or do the same thing with an async version:
35-
36-
```python
37-
from nadag_innmelding_python_client.models import MyDataModel
38-
from nadag_innmelding_python_client.api.my_tag import get_my_data_model
39-
from nadag_innmelding_python_client.types import Response
27+
response: Response[GeotekniskUnders] = get_geoteknisk_unders.sync_detailed(
28+
client=client,
29+
ekstern_id=str(project_id),
30+
ekstern_navnerom="Your Namespace",
31+
)
32+
33+
match response.status_code:
34+
case HTTPStatus.OK:
35+
geoteknisk_unders: GeotekniskUnders = response.parsed
36+
case HTTPStatus.NOT_FOUND:
37+
# Create a new project in NADAG
38+
case _:
39+
# Handle other status codes
40+
raise Exception(f"Got unexpected status code {response.status_code} for project ")
4041

41-
async with client as client:
42-
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
43-
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
44-
```
45-
46-
By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.
47-
48-
```python
49-
client = AuthenticatedClient(
50-
base_url="https://internal_api.example.com",
51-
token="SuperSecretToken",
52-
verify_ssl="/path/to/certificate_bundle.pem",
53-
)
54-
```
55-
56-
You can also disable certificate validation altogether, but beware that **this is a security risk**.
57-
58-
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
6442
```
6543

6644
Things to know:

nadag-innmelding-python-client/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "nadag-innmelding-python-client"
33
version = "2025.10.14"
44
description = "A client library for accessing Nadag innmelding API"
5+
license = {text = "MIT"}
56
authors = ["Jiyang Ye <[email protected]>"]
67
maintainers = ["Jiyang Ye <[email protected]>", "Jostein Leira <[email protected]>"]
78
readme = "README.md"

templates/README.md.jinja

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# {{ project_name }}
2+
{{ package_description }}
3+
4+
## Usage
5+
First, create a client:
6+
7+
```python
8+
from nadag_innmelding_python_client import AuthenticatedClient
9+
10+
secret_token = nadag_authenticate() # This you need to implement this yourself
11+
12+
client = AuthenticatedClient(
13+
base_url="https://test.ngu.no/api/",
14+
token=secret_token,
15+
)
16+
17+
```
18+
19+
Now call your endpoint and use your models:
20+
21+
```python
22+
from nadag_innmelding_python_client.api.default import get_nadag_innmelding_v_1_geoteknisk_unders as get_geoteknisk_unders
23+
from nadag_innmelding_python_client.models import GeotekniskUnders
24+
from nadag_innmelding_python_client.types import Response
25+
26+
with client as client:
27+
response: Response[GeotekniskUnders] = get_geoteknisk_unders.sync_detailed(
28+
client=client,
29+
ekstern_id=str(project_id),
30+
ekstern_navnerom="Your Namespace",
31+
)
32+
33+
match response.status_code:
34+
case HTTPStatus.OK:
35+
geoteknisk_unders: GeotekniskUnders = response.parsed
36+
case HTTPStatus.NOT_FOUND:
37+
# Create a new project in NADAG
38+
case _:
39+
# Handle other status codes
40+
raise Exception(f"Got unexpected status code {response.status_code} for project ")
41+
42+
```
43+
44+
Things to know:
45+
1. Every path/method combo becomes a Python module with four functions:
46+
1. `sync`: Blocking request that returns parsed data (if successful) or `None`
47+
1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
48+
1. `asyncio`: Like `sync` but async instead of blocking
49+
1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking
50+
51+
1. All path/query params, and bodies become method arguments.
52+
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)
53+
1. Any endpoint which did not have a tag will be in `{{ package_name }}.api.default`
54+
55+
## Advanced customizations
56+
57+
There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case):
58+
59+
```python
60+
from {{ package_name }} import Client
61+
62+
def log_request(request):
63+
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
64+
65+
def log_response(response):
66+
request = response.request
67+
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
68+
69+
client = Client(
70+
base_url="https://api.example.com",
71+
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
72+
)
73+
74+
# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
75+
```
76+
77+
You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):
78+
79+
```python
80+
import httpx
81+
from {{ package_name }} import Client
82+
83+
client = Client(
84+
base_url="https://api.example.com",
85+
)
86+
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
87+
client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
88+
```
89+
90+
{% if meta == "poetry" %}
91+
## Building / publishing this package
92+
This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
93+
1. Update the metadata in pyproject.toml (e.g. authors, version)
94+
1. If you're using a private repository, configure it with Poetry
95+
1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
96+
1. `poetry config http-basic.<your-repository-name> <username> <password>`
97+
1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
98+
99+
If you want to install this client into another project without publishing it (e.g. for development) then:
100+
1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
101+
1. If that project is not using Poetry:
102+
1. Build a wheel with `poetry build -f wheel`
103+
1. Install that wheel from the other project `pip install <path-to-wheel>`
104+
{% elif meta == 'uv' %}
105+
## Building / publishing this package
106+
This project uses [uv](https://github.com/astral-sh/uv) to manage dependencies and packaging. Here are the basics:
107+
1. Update the metadata in `pyproject.toml` (e.g. authors, version).
108+
2. If you're using a private repository: https://docs.astral.sh/uv/guides/integration/alternative-indexes/
109+
3. Build a distribution with `uv build`, builds `sdist` and `wheel` by default.
110+
1. Publish the client with `uv publish`, see documentation for publishing to private indexes.
111+
112+
If you want to install this client into another project without publishing it (e.g. for development) then:
113+
1. If that project **is using uv**, you can simply do `uv add <path-to-this-client>` from that project
114+
1. If that project is not using uv:
115+
1. Build a wheel with `uv build --wheel`.
116+
1. Install that wheel from the other project `pip install <path-to-wheel>`.
117+
{% endif %}

templates/pyproject.toml.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
name = "{{ project_name }}"
88
version = "{{ package_version }}"
99
description = "{{ package_description }}"
10+
license = {text = "MIT"}
1011
authors = ["Jiyang Ye <jiyang[email protected]>"]
1112
maintainers = ["Jiyang Ye <jiyang[email protected]>", "Jostein Leira <jostein[email protected]>"]
1213
readme = "README.md"

0 commit comments

Comments
 (0)