mreg-api 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. mreg_api-0.1.0/.github/workflows/publish.yml +152 -0
  2. mreg_api-0.1.0/.github/workflows/test.yml +30 -0
  3. mreg_api-0.1.0/.gitignore +112 -0
  4. mreg_api-0.1.0/.markdownlint.json +9 -0
  5. mreg_api-0.1.0/.pre-commit-config.yaml +25 -0
  6. mreg_api-0.1.0/CHANGELOG.md +14 -0
  7. mreg_api-0.1.0/CLAUDE.md +145 -0
  8. mreg_api-0.1.0/LICENSE +674 -0
  9. mreg_api-0.1.0/NOTES.md +57 -0
  10. mreg_api-0.1.0/PKG-INFO +726 -0
  11. mreg_api-0.1.0/README.md +23 -0
  12. mreg_api-0.1.0/mreg_api/__about__.py +7 -0
  13. mreg_api-0.1.0/mreg_api/__init__.py +25 -0
  14. mreg_api-0.1.0/mreg_api/_version.py +34 -0
  15. mreg_api-0.1.0/mreg_api/cache.py +205 -0
  16. mreg_api-0.1.0/mreg_api/client.py +989 -0
  17. mreg_api-0.1.0/mreg_api/dirs.py +23 -0
  18. mreg_api-0.1.0/mreg_api/endpoints.py +152 -0
  19. mreg_api-0.1.0/mreg_api/exceptions.py +375 -0
  20. mreg_api-0.1.0/mreg_api/models/__init__.py +99 -0
  21. mreg_api-0.1.0/mreg_api/models/abstracts.py +536 -0
  22. mreg_api-0.1.0/mreg_api/models/fields.py +178 -0
  23. mreg_api-0.1.0/mreg_api/models/history.py +101 -0
  24. mreg_api-0.1.0/mreg_api/models/models.py +3849 -0
  25. mreg_api-0.1.0/mreg_api/py.typed +0 -0
  26. mreg_api-0.1.0/mreg_api/types.py +86 -0
  27. mreg_api-0.1.0/mreg_api/utilities/__init__.py +5 -0
  28. mreg_api-0.1.0/mreg_api/utilities/fs.py +84 -0
  29. mreg_api-0.1.0/mreg_api/utilities/shared.py +42 -0
  30. mreg_api-0.1.0/mreg_api.egg-info/PKG-INFO +726 -0
  31. mreg_api-0.1.0/mreg_api.egg-info/SOURCES.txt +44 -0
  32. mreg_api-0.1.0/mreg_api.egg-info/dependency_links.txt +1 -0
  33. mreg_api-0.1.0/mreg_api.egg-info/requires.txt +7 -0
  34. mreg_api-0.1.0/mreg_api.egg-info/top_level.txt +1 -0
  35. mreg_api-0.1.0/pyproject.toml +235 -0
  36. mreg_api-0.1.0/setup.cfg +4 -0
  37. mreg_api-0.1.0/tests/__init__.py +0 -0
  38. mreg_api-0.1.0/tests/conftest.py +39 -0
  39. mreg_api-0.1.0/tests/models/__init__.py +5 -0
  40. mreg_api-0.1.0/tests/models/test_fields.py +275 -0
  41. mreg_api-0.1.0/tests/models/test_models.py +285 -0
  42. mreg_api-0.1.0/tests/test_cache.py +106 -0
  43. mreg_api-0.1.0/tests/test_client.py +720 -0
  44. mreg_api-0.1.0/tests/test_exceptions.py +277 -0
  45. mreg_api-0.1.0/tests/test_types.py +173 -0
  46. mreg_api-0.1.0/uv.lock +654 -0
@@ -0,0 +1,152 @@
1
+ name: build mreg-api
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "[0-9]+.[0-9]+.[0-9]+*"
7
+
8
+ concurrency:
9
+ group: build-mreg-api-${{ github.head_ref }}
10
+
11
+ env:
12
+ UV_FROZEN: 1
13
+
14
+ jobs:
15
+ build_pypi:
16
+ name: Build wheels and source distribution
17
+ runs-on: ubuntu-latest
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0 # Fetch all history to verify tag is on main
23
+
24
+ - name: Exit if tag is not on main branch
25
+ run: |
26
+ if ! git branch -r --contains HEAD | grep -q 'origin/main'; then
27
+ echo "Error: Tagged commit is not on the main branch"
28
+ exit 1
29
+ fi
30
+
31
+ - name: Install uv
32
+ uses: astral-sh/setup-uv@v2
33
+
34
+ - name: Set up Python 3.12
35
+ run: uv python install 3.12
36
+
37
+ - name: Install build dependencies
38
+ run: uv sync
39
+
40
+ - name: Build source distribution
41
+ run: uv build
42
+
43
+ - uses: actions/upload-artifact@v4
44
+ with:
45
+ name: pypi_artifacts
46
+ path: dist/*
47
+ if-no-files-found: error
48
+
49
+ publish_github:
50
+ name: Publish GitHub release
51
+ needs:
52
+ - build_pypi
53
+ runs-on: ubuntu-latest
54
+
55
+ steps:
56
+ - name: Download wheel and source distributions
57
+ uses: actions/download-artifact@v4
58
+ with:
59
+ pattern: pypi_artifacts
60
+ path: dist
61
+ merge-multiple: true
62
+
63
+ - name: Generate SHA256 checksums
64
+ id: sha
65
+ run: |
66
+ cd dist
67
+ echo "checksums<<EOF" >> $GITHUB_OUTPUT
68
+ sha256sum * >> $GITHUB_OUTPUT
69
+ echo "EOF" >> $GITHUB_OUTPUT
70
+
71
+ - name: Create GitHub release
72
+ uses: softprops/action-gh-release@v2
73
+ with:
74
+ files: dist/*
75
+ body: |
76
+ Release ${{ github.ref_name }}
77
+
78
+ ## Installation Instructions
79
+
80
+ ### uv
81
+
82
+ ```bash
83
+ uv tool install mreg-api==${{ github.ref_name }}
84
+ ```
85
+
86
+ ### pipx
87
+
88
+ ```bash
89
+ pipx install mreg-api==${{ github.ref_name }}
90
+ ```
91
+
92
+ ### pip
93
+
94
+ ```bash
95
+ pip install mreg-api==${{ github.ref_name }}
96
+ ```
97
+
98
+ ## SHA256 Checksums
99
+ ```
100
+ ${{ steps.sha.outputs.checksums }}
101
+ ```
102
+ draft: false
103
+ prerelease: false
104
+
105
+ # GitHub releases can be republished, but PyPI uploads are permanent.
106
+ # Ensure all steps succeed before publishing to PyPI.
107
+ publish_pypi:
108
+ name: Publish PyPI release
109
+ needs:
110
+ - build_pypi # redundant but explicit
111
+ - publish_github
112
+ runs-on: ubuntu-latest
113
+ permissions:
114
+ id-token: write
115
+ steps:
116
+ - uses: actions/download-artifact@v4
117
+ with:
118
+ name: pypi_artifacts
119
+ path: dist
120
+
121
+ - name: Push build artifacts to PyPI
122
+ uses: pypa/gh-action-pypi-publish@release/v1
123
+
124
+ rollback_on_failure:
125
+ name: Rollback on publish failure
126
+ if: ${{ always() && (needs.publish_github.result == 'failure' || needs.publish_pypi.result == 'failure') }}
127
+ needs:
128
+ - publish_github
129
+ - publish_pypi
130
+ runs-on: ubuntu-latest
131
+ permissions:
132
+ contents: write
133
+ steps:
134
+ - name: Checkout repository
135
+ uses: actions/checkout@v4
136
+ with:
137
+ fetch-depth: 0
138
+ - name: Rollback GitHub release and tag
139
+ if: ${{ needs.publish_github.result == 'success' }}
140
+ env:
141
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142
+ run: |
143
+ echo "Deleting GitHub release..."
144
+ gh release delete ${{ github.ref_name }} --repo ${{ github.repository }} --yes || true
145
+
146
+ echo "Deleting git tag..."
147
+ git push --delete origin "refs/tags/${{ github.ref_name }}" || true
148
+ - name: Rollback notification
149
+ run: |
150
+ echo "::notice::Rolling back release ${{ github.ref_name }} due to publish failure"
151
+ echo "GitHub release status: ${{ needs.publish_github.result }}"
152
+ echo "PyPI publish status: ${{ needs.publish_pypi.result }}"
@@ -0,0 +1,30 @@
1
+ on:
2
+ push:
3
+ pull_request:
4
+
5
+ env:
6
+ UV_FROZEN: 1
7
+
8
+ name: Tests
9
+ jobs:
10
+ test:
11
+ name: Unit tests
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ python-version:
17
+ - "3.11"
18
+ - "3.12"
19
+ - "3.13"
20
+ - "3.14"
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+ - name: Install uv
24
+ uses: astral-sh/setup-uv@v2
25
+ - name: Set up Python ${{ matrix.python-version }}
26
+ run: uv python install ${{ matrix.python-version }}
27
+ - name: Install dependencies
28
+ run: uv sync
29
+ - name: Run unit tests
30
+ run: uv run pytest -vv
@@ -0,0 +1,112 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+ mreg_api/_version.py
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+ ci/new_testsuite_log.json
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Django stuff:
57
+ *.log
58
+ local_settings.py
59
+ db.sqlite3
60
+
61
+ # Flask stuff:
62
+ instance/
63
+ .webassets-cache
64
+
65
+ # Scrapy stuff:
66
+ .scrapy
67
+
68
+ # Sphinx documentation
69
+ docs/_build/
70
+
71
+ # PyBuilder
72
+ target/
73
+
74
+ # Jupyter Notebook
75
+ .ipynb_checkpoints
76
+
77
+ # pyenv
78
+ .python-version
79
+
80
+ # celery beat schedule file
81
+ celerybeat-schedule
82
+
83
+ # SageMath parsed files
84
+ *.sage.py
85
+
86
+ # Environments
87
+ .env
88
+ .venv
89
+ env/
90
+ venv/
91
+ ENV/
92
+ env.bak/
93
+ venv.bak/
94
+
95
+ # Spyder project settings
96
+ .spyderproject
97
+ .spyproject
98
+
99
+ # Rope project settings
100
+ .ropeproject
101
+
102
+ # mkdocs documentation
103
+ /site
104
+
105
+ # mypy
106
+ .mypy_cache/
107
+
108
+ # PyCharm
109
+ .idea/*
110
+ mreg/.idea
111
+
112
+ *.log
@@ -0,0 +1,9 @@
1
+ {
2
+ "default": true,
3
+ "no-duplicate-heading": {
4
+ "siblings_only": true
5
+ },
6
+ "line-length": false,
7
+ "no-bare-urls": false,
8
+ "no-inline-html": false
9
+ }
@@ -0,0 +1,25 @@
1
+ # This is the configuration file for prek (drop-in replacement for pre-commit).
2
+ # See:
3
+ # - https://pre-commit.com/
4
+ # - https://github.com/j178/prek?tab=readme-ov-file#prek
5
+ repos:
6
+ - repo: https://github.com/pre-commit/pre-commit-hooks
7
+ rev: v6.0.0
8
+ hooks:
9
+ - id: trailing-whitespace
10
+ - id: end-of-file-fixer
11
+ - id: check-yaml
12
+ - id: check-added-large-files
13
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
14
+ rev: v0.14.11
15
+ hooks:
16
+ # Run the linter.
17
+ - id: ruff-check
18
+ args: [--fix]
19
+ # Run the formatter.
20
+ - id: ruff-format
21
+ # - repo: https://github.com/DetachHead/basedpyright-prek-mirror
22
+ # rev: 1.37.1
23
+ # hooks:
24
+ # - id: basedpyright
25
+ # exclude: ^(tests|scripts|docs)/
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ <!-- ## Unreleased -->
9
+
10
+ ## [0.1.0](https://github.com/unioslo/mreg-api/releases/tag/0.1.0) - 2026-01-27
11
+
12
+ ### Added
13
+
14
+ - Initial release of MREG API client library.
@@ -0,0 +1,145 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ MREG API is a Python client library for interacting with the MREG network registry system. It provides Pydantic-based models for type-safe API interactions, caching, and configuration management.
8
+
9
+ **Current Status:** This project is being extracted from the mreg-cli codebase to create a standalone API client library. Many files have been copied with minor name changes (e.g., `cli` -> `api`), but the architecture will be significantly refactored to support API-only usage without CLI dependencies.
10
+
11
+ **Key Technologies:**
12
+
13
+ - Python 3.11+ (supports 3.11, 3.12, 3.13)
14
+ - Pydantic v2 for data validation and models
15
+ - requests for HTTP operations
16
+ - diskcache for persistent caching
17
+ - pytest for testing
18
+
19
+ ## Development Commands
20
+
21
+ ### Environment Setup
22
+
23
+ ```bash
24
+ # Install dependencies (uses uv for fast dependency resolution)
25
+ uv pip install -e ".[dev]"
26
+ ```
27
+
28
+ ### Code Quality
29
+
30
+ ```bash
31
+ # Lint with ruff (check only)
32
+ ruff check .
33
+
34
+ # Lint and auto-fix issues
35
+ ruff check --fix .
36
+
37
+ # Format code
38
+ ruff format .
39
+
40
+ # Combined lint + format (recommended before commits)
41
+ ruff check --fix . && ruff format .
42
+ ```
43
+
44
+ ### Testing
45
+
46
+ ```bash
47
+ # Run all tests
48
+ pytest
49
+
50
+ # Run tests with verbose output
51
+ pytest -v
52
+
53
+ # Run specific test file
54
+ pytest path/to/test_file.py
55
+
56
+ # Run tests matching pattern
57
+ pytest -k "pattern"
58
+ ```
59
+
60
+ ### Building
61
+
62
+ ```bash
63
+ # Build distribution packages
64
+ python -m build
65
+ ```
66
+
67
+ ## Code Style
68
+
69
+ ### Ruff Configuration
70
+
71
+ - Line length: 99 characters
72
+ - Target: Python 3.11+
73
+ - Import style: One import per line (`force-single-line = true`)
74
+ - Required import: `from __future__ import annotations` in all files
75
+
76
+ ### Enabled Lints
77
+
78
+ - flake8-builtins (A)
79
+ - flake8-unused-arguments (ARG)
80
+ - flake8-bugbear (B)
81
+ - pydocstyle (D) - requires docstrings
82
+ - Error checking (E, F)
83
+ - isort (I) for import sorting
84
+ - Pylint conventions and errors (PLC, PLE)
85
+
86
+ ### Docstring Style
87
+
88
+ - Multi-line docstrings: Summary on first line (D212)
89
+ - No blank line before class docstring (D211)
90
+ - Use triple double quotes (D300)
91
+
92
+ ## Important Notes
93
+
94
+ ### Work in Progress
95
+
96
+ This codebase is in active development as it's being extracted from mreg-cli. The current code structure is temporary and will undergo significant architectural changes. Do not assume the current patterns and module organization are final.
97
+
98
+ ### Missing/Incomplete Modules
99
+
100
+ Several modules are referenced but not yet implemented or need to be refactored:
101
+
102
+ - `mreg_api/dirs.py` - Directory/path constants
103
+ - `mreg_api/outputmanager.py` - Output formatting (may be removed or refactored)
104
+ - `mreg_api/choices.py` - Choice enums
105
+ - `mreg_api/__about__.py` - Package metadata
106
+
107
+ ### Testing
108
+
109
+ - Tests use pytest with `pytest-httpserver` for mocking HTTP
110
+ - Use `inline-snapshot` for snapshot testing
111
+ - Test files should be in a `tests/` directory (to be created)
112
+ - Test files excluded from strict docstring requirements
113
+
114
+ ### Dependencies
115
+
116
+ Core dependencies are minimal:
117
+
118
+ - requests (with SOCKS proxy support)
119
+ - pydantic v2.7.1+
120
+ - pydantic-extra-types
121
+ - platformdirs
122
+ - diskcache
123
+
124
+ Dev dependencies include ruff, pytest, and build tools.
125
+
126
+ ### Refactoring Roadmap
127
+
128
+ #### Goal
129
+
130
+ Transform this CLI codebase into a clean, standalone API client library for programmatic use.
131
+
132
+ #### Key Changes
133
+
134
+ - Remove CLI-specific logic and output methods from models
135
+ - Preserve current CRUD semantics (`fetch*`, `create`, `update`, `delete` methods)
136
+ - Create `mreg_api/client.py` with `MregClient` class for session management
137
+ - Handles authentication, base URL, session state
138
+ - Replace global session state with client instance (singleton pattern recommended)
139
+ - Migrate `get`/`post`/`patch`/`delete` from `utilities/api.py` to client methods
140
+ - Rename `MregCliConfig` to remove CLI references
141
+ - **Token file handling:** Do NOT change semantics - CLI users depend on this for auth persistence
142
+
143
+ #### Fragile Modules
144
+
145
+ - `mreg_api/api/history.py` - Complex filtering logic, brittle code