A client library for accessing Nadag innmelding API
Project description
nadag-innmelding-python-client
A client library for accessing Nadag innmelding API
Usage
First, create a client:
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:
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:
-
Every path/method combo becomes a Python module with four functions:
sync: Blocking request that returns parsed data (if successful) orNonesync_detailed: Blocking request that always returns aRequest, optionally withparsedset if the request was successful.asyncio: Likesyncbut async instead of blockingasyncio_detailed: Likesync_detailedbut async instead of blocking
-
All path/query params, and bodies become method arguments.
-
If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
-
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):
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):
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 Poetry to manage dependencies and packaging. Here are the basics:
- Update the metadata in pyproject.toml (e.g. authors, version)
- If you're using a private repository, configure it with Poetry
poetry config repositories.<your-repository-name> <url-to-your-repository>poetry config http-basic.<your-repository-name> <username> <password>
- Publish the client with
poetry publish --build -r <your-repository-name>or, if for public PyPI, justpoetry publish --build
If you want to install this client into another project without publishing it (e.g. for development) then:
- If that project is using Poetry, you can simply do
poetry add <path-to-this-client>from that project - If that project is not using Poetry:
- Build a wheel with
poetry build -f wheel - Install that wheel from the other project
pip install <path-to-wheel>
- Build a wheel with
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nadag_innmelding_python_client-2025.11.3.tar.gz.
File metadata
- Download URL: nadag_innmelding_python_client-2025.11.3.tar.gz
- Upload date:
- Size: 109.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.9 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d61a8889d2a3178068202531d91d1a0e09571372f4146d54bac84b09c11e7c0
|
|
| MD5 |
679e7df3341c9814f3a9f5940103f83d
|
|
| BLAKE2b-256 |
072fd90e3e795e5ef5718edeb8afbf208eb68343eaa23160e4b2c75a530222b2
|
File details
Details for the file nadag_innmelding_python_client-2025.11.3-py3-none-any.whl.
File metadata
- Download URL: nadag_innmelding_python_client-2025.11.3-py3-none-any.whl
- Upload date:
- Size: 227.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.9 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fb1b0d541cdf76ca7fcfc2adcd4db90857fd2da2d7eeb88bb29d83292c743a7
|
|
| MD5 |
5b812961f5725fef6a8faede92f9af0f
|
|
| BLAKE2b-256 |
c40919f95037c67b6559a77e5066c95c143a7d14c7ff0d2d697e682289b67aac
|