rahcp 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 (69) hide show
  1. rahcp-0.1.0/LICENSE +73 -0
  2. rahcp-0.1.0/PKG-INFO +40 -0
  3. rahcp-0.1.0/README.md +65 -0
  4. rahcp-0.1.0/pyproject.toml +104 -0
  5. rahcp-0.1.0/setup.cfg +4 -0
  6. rahcp-0.1.0/src/rahcp/__init__.py +7 -0
  7. rahcp-0.1.0/src/rahcp/cli/__init__.py +3 -0
  8. rahcp-0.1.0/src/rahcp/cli/_client.py +32 -0
  9. rahcp-0.1.0/src/rahcp/cli/_output.py +36 -0
  10. rahcp-0.1.0/src/rahcp/cli/_run.py +27 -0
  11. rahcp-0.1.0/src/rahcp/cli/auth.py +40 -0
  12. rahcp-0.1.0/src/rahcp/cli/config.py +130 -0
  13. rahcp-0.1.0/src/rahcp/cli/iiif.py +632 -0
  14. rahcp-0.1.0/src/rahcp/cli/main.py +143 -0
  15. rahcp-0.1.0/src/rahcp/cli/namespace.py +154 -0
  16. rahcp-0.1.0/src/rahcp/cli/s3.py +623 -0
  17. rahcp-0.1.0/src/rahcp/cli/transkribus.py +555 -0
  18. rahcp-0.1.0/src/rahcp.egg-info/PKG-INFO +40 -0
  19. rahcp-0.1.0/src/rahcp.egg-info/SOURCES.txt +67 -0
  20. rahcp-0.1.0/src/rahcp.egg-info/dependency_links.txt +1 -0
  21. rahcp-0.1.0/src/rahcp.egg-info/entry_points.txt +2 -0
  22. rahcp-0.1.0/src/rahcp.egg-info/requires.txt +34 -0
  23. rahcp-0.1.0/src/rahcp.egg-info/top_level.txt +7 -0
  24. rahcp-0.1.0/src/rahcp_client/__init__.py +47 -0
  25. rahcp-0.1.0/src/rahcp_client/_transfer.py +70 -0
  26. rahcp-0.1.0/src/rahcp_client/bulk/__init__.py +34 -0
  27. rahcp-0.1.0/src/rahcp_client/bulk/config.py +150 -0
  28. rahcp-0.1.0/src/rahcp_client/bulk/download.py +157 -0
  29. rahcp-0.1.0/src/rahcp_client/bulk/helpers.py +549 -0
  30. rahcp-0.1.0/src/rahcp_client/bulk/protocol.py +61 -0
  31. rahcp-0.1.0/src/rahcp_client/bulk/stream.py +183 -0
  32. rahcp-0.1.0/src/rahcp_client/bulk/upload.py +212 -0
  33. rahcp-0.1.0/src/rahcp_client/client.py +303 -0
  34. rahcp-0.1.0/src/rahcp_client/config.py +27 -0
  35. rahcp-0.1.0/src/rahcp_client/errors.py +57 -0
  36. rahcp-0.1.0/src/rahcp_client/mapi.py +92 -0
  37. rahcp-0.1.0/src/rahcp_client/s3.py +427 -0
  38. rahcp-0.1.0/src/rahcp_client/tracing.py +120 -0
  39. rahcp-0.1.0/src/rahcp_etl/__init__.py +16 -0
  40. rahcp-0.1.0/src/rahcp_etl/checkpointing.py +65 -0
  41. rahcp-0.1.0/src/rahcp_etl/consumer.py +98 -0
  42. rahcp-0.1.0/src/rahcp_etl/dlq.py +146 -0
  43. rahcp-0.1.0/src/rahcp_etl/pipeline.py +146 -0
  44. rahcp-0.1.0/src/rahcp_iiif/__init__.py +17 -0
  45. rahcp-0.1.0/src/rahcp_iiif/config.py +9 -0
  46. rahcp-0.1.0/src/rahcp_iiif/downloader.py +270 -0
  47. rahcp-0.1.0/src/rahcp_iiif/manifest.py +125 -0
  48. rahcp-0.1.0/src/rahcp_iiif/verify.py +146 -0
  49. rahcp-0.1.0/src/rahcp_tracker/__init__.py +26 -0
  50. rahcp-0.1.0/src/rahcp_tracker/_base.py +211 -0
  51. rahcp-0.1.0/src/rahcp_tracker/factory.py +46 -0
  52. rahcp-0.1.0/src/rahcp_tracker/models.py +31 -0
  53. rahcp-0.1.0/src/rahcp_tracker/postgres.py +43 -0
  54. rahcp-0.1.0/src/rahcp_tracker/protocol.py +49 -0
  55. rahcp-0.1.0/src/rahcp_tracker/sqlite.py +62 -0
  56. rahcp-0.1.0/src/rahcp_transkribus/__init__.py +46 -0
  57. rahcp-0.1.0/src/rahcp_transkribus/alto.py +71 -0
  58. rahcp-0.1.0/src/rahcp_transkribus/client.py +252 -0
  59. rahcp-0.1.0/src/rahcp_transkribus/config.py +22 -0
  60. rahcp-0.1.0/src/rahcp_transkribus/errors.py +11 -0
  61. rahcp-0.1.0/src/rahcp_transkribus/exporter.py +424 -0
  62. rahcp-0.1.0/src/rahcp_transkribus/models.py +95 -0
  63. rahcp-0.1.0/src/rahcp_transkribus/versions.py +75 -0
  64. rahcp-0.1.0/src/rahcp_validate/__init__.py +39 -0
  65. rahcp-0.1.0/src/rahcp_validate/images.py +132 -0
  66. rahcp-0.1.0/src/rahcp_validate/rules.py +92 -0
  67. rahcp-0.1.0/tests/test_iiif_to_s3_e2e.py +250 -0
  68. rahcp-0.1.0/tests/test_transkribus_change_detection_e2e.py +365 -0
  69. rahcp-0.1.0/tests/test_transkribus_to_s3_e2e.py +330 -0
rahcp-0.1.0/LICENSE ADDED
@@ -0,0 +1,73 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30
+
31
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
32
+
33
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
34
+
35
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
36
+
37
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
38
+
39
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+
41
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
42
+
43
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS
56
+
57
+ APPENDIX: How to apply the Apache License to your work.
58
+
59
+ To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
+
61
+ Copyright [yyyy] [name of copyright owner]
62
+
63
+ Licensed under the Apache License, Version 2.0 (the "License");
64
+ you may not use this file except in compliance with the License.
65
+ You may obtain a copy of the License at
66
+
67
+ http://www.apache.org/licenses/LICENSE-2.0
68
+
69
+ Unless required by applicable law or agreed to in writing, software
70
+ distributed under the License is distributed on an "AS IS" BASIS,
71
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
+ See the License for the specific language governing permissions and
73
+ limitations under the License.
rahcp-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: rahcp
3
+ Version: 0.1.0
4
+ Summary: Python SDK & CLI for HCP Unified API
5
+ Author: Riksarkivet
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/AI-Riksarkivet/ra-hcp
8
+ Project-URL: Repository, https://github.com/AI-Riksarkivet/ra-hcp
9
+ Project-URL: Issues, https://github.com/AI-Riksarkivet/ra-hcp/issues
10
+ Requires-Python: >=3.13
11
+ License-File: LICENSE
12
+ Requires-Dist: httpx>=0.28
13
+ Requires-Dist: pydantic>=2.0
14
+ Requires-Dist: pydantic-settings>=2.13
15
+ Requires-Dist: tenacity>=9.0
16
+ Requires-Dist: sqlmodel>=0.0.22
17
+ Requires-Dist: typer>=0.15
18
+ Requires-Dist: rich>=13.0
19
+ Requires-Dist: pyyaml>=6.0
20
+ Provides-Extra: validate
21
+ Requires-Dist: pillow>=11.0; extra == "validate"
22
+ Provides-Extra: etl
23
+ Requires-Dist: nats-py>=2.9; extra == "etl"
24
+ Provides-Extra: postgres
25
+ Requires-Dist: psycopg[binary]>=3.2; extra == "postgres"
26
+ Provides-Extra: alto
27
+ Requires-Dist: ocrd-page-to-alto>=2.1.0; extra == "alto"
28
+ Provides-Extra: otel
29
+ Requires-Dist: opentelemetry-api>=1.29; extra == "otel"
30
+ Requires-Dist: opentelemetry-sdk>=1.29; extra == "otel"
31
+ Requires-Dist: opentelemetry-exporter-otlp>=1.29; extra == "otel"
32
+ Provides-Extra: all
33
+ Requires-Dist: pillow>=11.0; extra == "all"
34
+ Requires-Dist: nats-py>=2.9; extra == "all"
35
+ Requires-Dist: psycopg[binary]>=3.2; extra == "all"
36
+ Requires-Dist: ocrd-page-to-alto>=2.1.0; extra == "all"
37
+ Requires-Dist: opentelemetry-api>=1.29; extra == "all"
38
+ Requires-Dist: opentelemetry-sdk>=1.29; extra == "all"
39
+ Requires-Dist: opentelemetry-exporter-otlp>=1.29; extra == "all"
40
+ Dynamic: license-file
rahcp-0.1.0/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # ra-hcp
2
+
3
+ [![Tests](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/ci.yml/badge.svg)](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/ci.yml)
4
+ [![Docs](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/docs.yml/badge.svg)](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/docs.yml)
5
+ [![Storybook](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/storybook.yml/badge.svg)](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/storybook.yml)
6
+ [![CodeQL](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/codeql.yml/badge.svg)](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/codeql.yml)
7
+ [![Scorecard](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/scorecard.yml/badge.svg)](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/scorecard.yml)
8
+ [![TruffleHog](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/trufflehog.yml/badge.svg)](https://github.com/AI-Riksarkivet/ra-hcp/actions/workflows/trufflehog.yml)
9
+
10
+ Web application for managing Hitachi Content Platform (HCP) — S3-compatible object storage and Management API operations.
11
+
12
+ | Layer | Technology |
13
+ |-------|------------|
14
+ | Frontend | SvelteKit 2, Svelte 5, Tailwind CSS 4, Bun |
15
+ | Backend | FastAPI, boto3, Python, uv |
16
+ | Caching | Redis |
17
+ | Docs | Zensical |
18
+ | CI/CD | Dagger, Docker, Helm |
19
+
20
+ ## Quick Start
21
+
22
+ ```bash
23
+ make setup # Install Bun + uv and all dependencies
24
+ make run-api-mock # Start mock backend (no HCP credentials needed)
25
+ make frontend-dev # Start frontend dev server
26
+ ```
27
+
28
+ For production mode with real HCP credentials: `make run-api`
29
+
30
+ ## Development
31
+
32
+ Install the git hooks once after cloning, so formatting, linting, type checks, and
33
+ commit-message rules run automatically before each commit:
34
+
35
+ ```bash
36
+ prek install # pre-commit: ruff format/lint, backend ty check
37
+ prek install --hook-type commit-msg # commit-msg: Conventional Commits + author-trailer guard
38
+ ```
39
+
40
+ Hooks live in [`prek.toml`](prek.toml), pinned to the same tool versions CI uses, so
41
+ local checks and CI agree. Run them by hand anytime with `prek run --all-files`, or via
42
+ the Makefile: `make fmt` (format), `make lint`, `make quality` (format + lint + type-check).
43
+ [prek](https://github.com/j178/prek) is a fast pre-commit runner — install it with
44
+ `uv tool install prek`.
45
+
46
+ ## Documentation
47
+
48
+ - [Docs site](https://ai-riksarkivet.github.io/hcp/) — architecture, API guide, configuration
49
+ - [Storybook](https://ai-riksarkivet.github.io/hcp/storybook/) — component library
50
+
51
+ ## Requirements
52
+
53
+ - [Bun](https://bun.sh) — frontend runtime
54
+ - [uv](https://docs.astral.sh/uv/) — Python package manager
55
+ - [prek](https://github.com/j178/prek) — pre-commit hook runner (`uv tool install prek`)
56
+ - Docker — for Redis caching (optional)
57
+
58
+
59
+ ## Gallery
60
+
61
+ <img width="2523" height="1298" alt="image" src="https://github.com/user-attachments/assets/e3e27ebf-5901-4c41-8d68-0d12a13f2d97" />
62
+
63
+ <img width="2534" height="1317" alt="image" src="https://github.com/user-attachments/assets/43ec04b3-2fcc-4b49-b2b1-26ea70d3fd17" />
64
+
65
+ <img width="2530" height="1253" alt="image" src="https://github.com/user-attachments/assets/9098e9f9-2778-42ba-9c13-24f6259c0a69" />
@@ -0,0 +1,104 @@
1
+ [project]
2
+ name = "rahcp"
3
+ version = "0.1.0"
4
+ description = "Python SDK & CLI for HCP Unified API"
5
+ requires-python = ">=3.13"
6
+ license = "Apache-2.0"
7
+ authors = [{ name = "Riksarkivet" }]
8
+ # Single published distribution. The CLI lives natively at src/rahcp/cli; the
9
+ # sibling modules stay as packages/ workspace members for development but are
10
+ # copied into src/ and bundled into this one wheel at build time. So the deps
11
+ # below are the real third-party deps; heavy/optional ones are extras.
12
+ dependencies = [
13
+ "httpx>=0.28",
14
+ "pydantic>=2.0",
15
+ "pydantic-settings>=2.13",
16
+ "tenacity>=9.0",
17
+ "sqlmodel>=0.0.22",
18
+ "typer>=0.15",
19
+ "rich>=13.0",
20
+ "pyyaml>=6.0",
21
+ ]
22
+
23
+ [project.optional-dependencies]
24
+ validate = ["pillow>=11.0"] # rahcp_validate + --validate flag
25
+ etl = ["nats-py>=2.9"] # rahcp_etl (JetStream orchestration)
26
+ postgres = ["psycopg[binary]>=3.2"] # rahcp_tracker Postgres backend
27
+ alto = ["ocrd-page-to-alto>=2.1.0"] # rahcp transkribus --fmt alto
28
+ otel = [
29
+ "opentelemetry-api>=1.29",
30
+ "opentelemetry-sdk>=1.29",
31
+ "opentelemetry-exporter-otlp>=1.29",
32
+ ]
33
+ all = [
34
+ "pillow>=11.0",
35
+ "nats-py>=2.9",
36
+ "psycopg[binary]>=3.2",
37
+ "ocrd-page-to-alto>=2.1.0",
38
+ "opentelemetry-api>=1.29",
39
+ "opentelemetry-sdk>=1.29",
40
+ "opentelemetry-exporter-otlp>=1.29",
41
+ ]
42
+
43
+ [project.scripts]
44
+ rahcp = "rahcp.cli.main:app"
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/AI-Riksarkivet/ra-hcp"
48
+ Repository = "https://github.com/AI-Riksarkivet/ra-hcp"
49
+ Issues = "https://github.com/AI-Riksarkivet/ra-hcp/issues"
50
+
51
+ # The wheel ships everything under src/. In the repo src/ holds only the rahcp
52
+ # package (umbrella + rahcp.cli); the build step (make build-sdk / .dagger
53
+ # BuildSdk) copies the sibling modules from packages/*/src into src/ first, so
54
+ # the one wheel is self-contained. sources=["src"] strips the src/ prefix, making
55
+ # each dir a top-level import package; it is adaptive, so in dev (no copy) only
56
+ # rahcp ships and the siblings resolve from the workspace instead.
57
+ [tool.hatch.build.targets.wheel]
58
+ sources = ["src"]
59
+ include = ["src"]
60
+
61
+ [tool.hatch.build.targets.sdist]
62
+ include = ["src", "tests"]
63
+
64
+ [tool.uv]
65
+ package = true # rahcp is a real package (installed editable in dev, wheel on publish)
66
+
67
+ [tool.uv.workspace]
68
+ members = ["packages/*"]
69
+ exclude = ["backend"]
70
+
71
+ [tool.uv.sources]
72
+ rahcp-client = { workspace = true }
73
+ rahcp-tracker = { workspace = true }
74
+ rahcp-iiif = { workspace = true }
75
+ rahcp-transkribus = { workspace = true }
76
+ rahcp-validate = { workspace = true }
77
+ rahcp-etl = { workspace = true }
78
+
79
+ [dependency-groups]
80
+ dev = [
81
+ "pytest>=8.0",
82
+ "pytest-asyncio>=0.25",
83
+ "respx>=0.22",
84
+ "moto[s3,server]>=5.0",
85
+ "boto3>=1.35",
86
+ "pillow>=11.0",
87
+ "nats-py>=2.9",
88
+ "psycopg[binary]>=3.2",
89
+ "pytest-postgresql>=6.1",
90
+ # sibling workspace modules — editable in dev so the bundled code + moved
91
+ # tests import; never part of the published wheel's metadata (bundled instead).
92
+ "rahcp-client",
93
+ "rahcp-tracker",
94
+ "rahcp-iiif",
95
+ "rahcp-transkribus",
96
+ "rahcp-validate",
97
+ "rahcp-etl",
98
+ ]
99
+
100
+ [tool.pytest.ini_options]
101
+ asyncio_mode = "auto"
102
+ testpaths = ["tests"]
103
+ # Project convention: importlib import-mode (sibling test suites share basenames).
104
+ addopts = "--import-mode=importlib"
rahcp-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,7 @@
1
+ """rahcp — Python SDK for HCP Unified API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from rahcp_client import HCPClient, HCPSettings
6
+
7
+ __all__ = ["HCPClient", "HCPSettings"]
@@ -0,0 +1,3 @@
1
+ """rahcp-cli — CLI for HCP Unified API."""
2
+
3
+ from __future__ import annotations
@@ -0,0 +1,32 @@
1
+ """Shared client factory — auto-authenticates from config/flags/env."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ import typer
8
+
9
+ if TYPE_CHECKING:
10
+ from rahcp_client import HCPClient
11
+
12
+
13
+ def make_client(ctx: typer.Context) -> HCPClient:
14
+ """Create an HCPClient from resolved settings.
15
+
16
+ Priority: CLI flags > env vars > config file > defaults.
17
+
18
+ If username/password are available, the client auto-logs in on __aenter__.
19
+ Tenant is passed during login so the backend routes to the correct HCP tenant.
20
+ """
21
+ from rahcp_client import HCPClient
22
+
23
+ return HCPClient(
24
+ endpoint=ctx.obj["endpoint"],
25
+ username=ctx.obj.get("username", ""),
26
+ password=ctx.obj.get("password", ""),
27
+ tenant=ctx.obj.get("tenant"),
28
+ verify_ssl=ctx.obj.get("verify_ssl", True),
29
+ timeout=ctx.obj.get("timeout", 30.0),
30
+ multipart_threshold=ctx.obj.get("multipart_threshold", 100 * 1024 * 1024),
31
+ multipart_chunk=ctx.obj.get("multipart_chunk", 64 * 1024 * 1024),
32
+ )
@@ -0,0 +1,36 @@
1
+ """Rich table/JSON formatting helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+ from rich.console import Console
9
+ from rich.table import Table
10
+
11
+ console = Console()
12
+
13
+
14
+ def print_json(data: Any) -> None:
15
+ """Print data as formatted JSON."""
16
+ console.print_json(json.dumps(data, indent=2, default=str))
17
+
18
+
19
+ def print_table(
20
+ rows: list[dict[str, Any]],
21
+ columns: list[str] | None = None,
22
+ *,
23
+ title: str | None = None,
24
+ ) -> None:
25
+ """Print a list of dicts as a Rich table."""
26
+ if not rows:
27
+ console.print("[dim]No results.[/dim]")
28
+ return
29
+
30
+ cols = columns or list(rows[0].keys())
31
+ table = Table(title=title)
32
+ for col in cols:
33
+ table.add_column(col)
34
+ for row in rows:
35
+ table.add_row(*[str(row.get(c, "")) for c in cols])
36
+ console.print(table)
@@ -0,0 +1,27 @@
1
+ """Shared async runner with error handling."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import sys
7
+ from collections.abc import Coroutine
8
+ from typing import Any
9
+
10
+ from rahcp.cli._output import console
11
+
12
+
13
+ def run(coro: Coroutine[Any, Any, None]) -> None:
14
+ """Run an async coroutine with clean error output."""
15
+ try:
16
+ asyncio.run(coro)
17
+ except KeyboardInterrupt:
18
+ sys.exit(130)
19
+ except Exception as exc:
20
+ from rahcp_client.errors import HCPError
21
+
22
+ if isinstance(exc, HCPError):
23
+ label = type(exc).__name__
24
+ console.print(f"[red]{label}:[/red] {exc.message}")
25
+ else:
26
+ console.print(f"[red]Error:[/red] {exc}")
27
+ sys.exit(1)
@@ -0,0 +1,40 @@
1
+ """Auth commands — whoami."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import json
7
+
8
+ import typer
9
+
10
+ from rahcp.cli._client import make_client
11
+ from rahcp.cli._output import console, print_json
12
+ from rahcp.cli._run import run
13
+
14
+ app = typer.Typer(help="Authentication", no_args_is_help=True)
15
+
16
+
17
+ @app.command()
18
+ def whoami(ctx: typer.Context) -> None:
19
+ """Show current user info by decoding the JWT token."""
20
+
21
+ async def _whoami() -> None:
22
+ async with make_client(ctx) as client:
23
+ token = client.token
24
+ if not token:
25
+ console.print("[red]Not authenticated. Check your config.[/red]")
26
+ raise typer.Exit(1)
27
+ try:
28
+ payload_b64 = token.split(".")[1]
29
+ payload_b64 += "=" * (4 - len(payload_b64) % 4)
30
+ payload = json.loads(base64.urlsafe_b64decode(payload_b64))
31
+ except (IndexError, json.JSONDecodeError, Exception) as exc:
32
+ console.print(f"[red]Invalid token format:[/red] {exc}")
33
+ raise typer.Exit(1) from exc
34
+ if ctx.obj["json"]:
35
+ print_json(payload)
36
+ else:
37
+ console.print(f"User: [bold]{payload.get('sub', '?')}[/bold]")
38
+ console.print(f"Tenant: {payload.get('tenant', '(system)')}")
39
+
40
+ run(_whoami())
@@ -0,0 +1,130 @@
1
+ """YAML config file with named profiles.
2
+
3
+ Config file: ~/.rahcp/config.yaml (or --config / RAHCP_CONFIG)
4
+
5
+ Example::
6
+
7
+ default: dev
8
+
9
+ profiles:
10
+ dev:
11
+ endpoint: http://localhost:8000/api/v1
12
+ username: admin
13
+ password: secret
14
+ tenant: dev-ai
15
+ verify_ssl: false
16
+ prod:
17
+ endpoint: http://localhost:8000/api/v1
18
+ username: prod-user
19
+ password: secret
20
+ tenant: prod-archive
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import logging
26
+ from pathlib import Path
27
+
28
+ import yaml
29
+ from pydantic import BaseModel, Field
30
+
31
+ log = logging.getLogger(__name__)
32
+
33
+ CONFIG_DIR = Path.home() / ".rahcp"
34
+ CONFIG_PATH = CONFIG_DIR / "config.yaml"
35
+
36
+
37
+ class Profile(BaseModel):
38
+ """A named connection profile."""
39
+
40
+ # Connection
41
+ endpoint: str = "http://localhost:8000/api/v1"
42
+ username: str = ""
43
+ password: str = ""
44
+ tenant: str = ""
45
+ verify_ssl: bool = True
46
+ timeout: float = 30.0
47
+
48
+ # Multipart upload
49
+ multipart_threshold: int = 100 * 1024 * 1024
50
+ multipart_chunk: int = 64 * 1024 * 1024
51
+ multipart_concurrency: int = 6
52
+
53
+ # Bulk transfer defaults
54
+ bulk_workers: int = 10
55
+ bulk_progress_interval: float = 5.0
56
+ bulk_queue_depth: int = 8
57
+ bulk_tracker_flush_every: int = 500
58
+ bulk_tracker_dir: str = ""
59
+ bulk_tracker_prefix: str = ""
60
+ bulk_presign_batch_size: int = 200
61
+ bulk_chunk_size: int = 4 * 1024 * 1024 # 4 MB
62
+ bulk_stream_threshold: int = 100 * 1024 * 1024 # 100 MB
63
+
64
+ # IIIF
65
+ iiif_url: str = "https://iiifintern-ai.ra.se"
66
+ iiif_timeout: float = 60.0
67
+ iiif_query_params: str = "full/max/0/default.jpg"
68
+ iiif_workers: int = 4
69
+ iiif_referer: str = ""
70
+
71
+ # Transkribus
72
+ transkribus_url: str = "https://transkribus.eu/TrpServer/rest"
73
+ transkribus_username: str = ""
74
+ transkribus_password: str = ""
75
+ transkribus_timeout: float = 60.0
76
+ transkribus_workers: int = 8
77
+
78
+ # Observability
79
+ log_level: str = "warning"
80
+ otel_endpoint: str = ""
81
+ otel_protocol: str = "http/protobuf"
82
+ otel_service_name: str = "rahcp-cli"
83
+
84
+
85
+ class CLIConfig(BaseModel):
86
+ """Config with named profiles."""
87
+
88
+ default: str = ""
89
+ profiles: dict[str, Profile] = Field(default_factory=dict)
90
+
91
+ def resolve(self, name: str | None = None) -> Profile:
92
+ """Resolve a profile by name, falling back to default."""
93
+ key = name or self.default
94
+ if key and key in self.profiles:
95
+ return self.profiles[key]
96
+ if len(self.profiles) == 1:
97
+ return next(iter(self.profiles.values()))
98
+ return Profile()
99
+
100
+
101
+ def load_config(path: str | None = None) -> CLIConfig:
102
+ """Load config from a YAML file.
103
+
104
+ Resolution: explicit path > RAHCP_CONFIG env > ~/.rahcp/config.yaml
105
+ """
106
+ config_path = Path(path) if path else CONFIG_PATH
107
+ if not config_path.exists():
108
+ return CLIConfig()
109
+ try:
110
+ raw = yaml.safe_load(config_path.read_text()) or {}
111
+ except Exception:
112
+ log.warning("Failed to parse config file: %s", config_path)
113
+ return CLIConfig()
114
+
115
+ # Multi-profile format
116
+ if "profiles" in raw:
117
+ return CLIConfig(
118
+ default=raw.get("default", ""),
119
+ profiles={
120
+ name: Profile(**vals)
121
+ for name, vals in raw["profiles"].items()
122
+ if isinstance(vals, dict)
123
+ },
124
+ )
125
+
126
+ # Flat format (backwards compat) — single "default" profile
127
+ return CLIConfig(
128
+ default="default",
129
+ profiles={"default": Profile(**raw)},
130
+ )