Metadata-Version: 2.4
Name: nadag-innmelding-python-client
Version: 2026.9.7
Summary: A client library for accessing Nadag innmelding API
Author: Jiyang Ye
Author-email: Jiyang Ye <jiyang.ye@ngi.no>
License-Expression: MIT
Requires-Dist: httpx>=0.20.0,<0.29.0
Requires-Dist: attrs>=22.2.0
Requires-Dist: python-dateutil>=2.8.0,<3
Maintainer: Jiyang Ye, Jostein Leira
Maintainer-email: Jiyang Ye <jiyang.ye@ngi.no>, Jostein Leira <jostein.leira@ngi.no>
Requires-Python: >=3.13, <4.0
Description-Content-Type: text/markdown

# nadag-innmelding-python-client
A client library for accessing Nadag innmelding API

## Usage
First, create a client:

```python
from nadag_innmelding_python_client import AuthenticatedClient

secret_token = nadag_authenticate()  # This you need to implement this yourself

client = AuthenticatedClient(
    base_url="https://test.ngu.no/api/",
    token=secret_token,
)
```

Now call your endpoint and use your models:

```python
from nadag_innmelding_python_client.api.default import get_nadag_innmelding_v_1_geoteknisk_unders as get_geoteknisk_unders
from nadag_innmelding_python_client.models import GeotekniskUnders
from nadag_innmelding_python_client.types import Response

with client as client:
    response: Response[GeotekniskUnders] = get_geoteknisk_unders.sync_detailed(
        client=client,
        ekstern_id=str(project_id),
        ekstern_navnerom="Your Namespace",
    )

    match response.status_code:
        case HTTPStatus.OK:
            geoteknisk_unders: GeotekniskUnders = response.parsed
        case HTTPStatus.NOT_FOUND:
            # Create a new project in NADAG
        case _:
            # Handle other status codes
            raise Exception(f"Got unexpected status code {response.status_code} for project ")

```

Things to know:
1. Every path/method combo becomes a Python module with four functions:
    1. `sync`: Blocking request that returns parsed data (if successful) or `None`
    1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
    1. `asyncio`: Like `sync` but async instead of blocking
    1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking

1. All path/query params, and bodies become method arguments.
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)
1. Any endpoint which did not have a tag will be in `nadag_innmelding_python_client.api.default`

## Advanced customizations

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):

```python
from nadag_innmelding_python_client import Client


def log_request(request):
    print(f"Request event hook: {request.method} {request.url} - Waiting for response")


def log_response(response):
    request = response.request
    print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")


client = Client(
    base_url="https://api.example.com",
    httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},
)

# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client()
```

You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url):

```python
import httpx
from nadag_innmelding_python_client import Client

client = Client(
    base_url="https://api.example.com",
)
# Note that base_url needs to be re-set, as would any shared cookies, headers, etc.
client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030"))
```

## Building / publishing this package
This project uses [uv](https://docs.astral.sh/uv/) to manage dependencies and packaging. Here are the basics:
1. Update the metadata in `pyproject.toml` (e.g. authors, version).
2. Run `uv sync` to create the environment and install dependencies.
3. Build the source and wheel distributions with `uv build`.
4. Publish them with `uv publish`.

If you want to install this client into another project without publishing it (e.g. for development) then:
1. In a uv project, run `uv add <path-to-this-client>`.
2. Otherwise, run `uv build --wheel` and install the resulting wheel with pip.
