A lightweight, Pythonic library for interacting with the NADAG innmelding API — quickly sync ground investigation data, all from Python.
- https://test.ngu.no/api/openapi-ui/ + Explore: /api/nadag/innmelding/openapi/v1
- https://ngu.github.io/mono/
pip install nadag-innmelding-python-clientfrom nadag_innmelding_python_client import AuthenticatedClient
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
secret_token = nadag_authenticate() # This you need to implement this yourself
client = AuthenticatedClient(
base_url="https://test.ngu.no/api/",
token=secret_token,
)
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 ")A scheduled / on-demand GitHub Actions workflow (auto-update.yaml) keeps the client current:
- Downloads the upstream OpenAPI specification from:
https://test.ngu.no/api/nadag/innmelding/openapi/v1(stored atopenapi_specification/nadag-innmelding.yaml). - Extracts the
info.versionvalue. - If the version differs from the committed spec, it regenerates the client using
openapi-python-clientwithtemplates/+config.yaml. - Updates the package version in
nadag-innmelding-python-client/pyproject.tomlto match the spec version. - Creates a pull request (branch name:
chore/openapi-spec-v<spec-version>) instead of committing directly.
After the pull request is merged:
- Manually create a git tag
v<spec-version>(or create a GitHub Release with that tag). - The existing
release.yamlworkflow (triggered on release creation) publishes the new version to PyPI using thePYPI_TOKENsecret.
Rationale for PR-based flow:
- Enables code review of generated changes.
- Lets you amend / adjust the version or templates before publishing.
To replicate the regeneration locally:
pip install openapi-python-client
python scripts/update_from_spec.pyThis will download the latest spec, regenerate the client, and bump the package version. You can then open a PR or tag manually.
Clone the repository.
Please open an issue before submitting a pull request. We welcome contributions and suggestions!