skipcheck-tm1 0.1.0.dev0__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 (150) hide show
  1. skipcheck_tm1-0.1.0.dev0/.gitignore +9 -0
  2. skipcheck_tm1-0.1.0.dev0/PKG-INFO +101 -0
  3. skipcheck_tm1-0.1.0.dev0/README.md +87 -0
  4. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/__init__.py +51 -0
  5. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/__main__.py +8 -0
  6. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/docs.py +41 -0
  7. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/emit_api.py +406 -0
  8. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/emit_model.py +306 -0
  9. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/emit_operations.py +77 -0
  10. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/names.py +88 -0
  11. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/spec.py +110 -0
  12. skipcheck_tm1-0.1.0.dev0/codegen/tm1_pygen/unasync.py +135 -0
  13. skipcheck_tm1-0.1.0.dev0/coverage/excluded.txt +2 -0
  14. skipcheck_tm1-0.1.0.dev0/coverage/live-excluded.txt +9 -0
  15. skipcheck_tm1-0.1.0.dev0/coverage/pending.txt +3 -0
  16. skipcheck_tm1-0.1.0.dev0/hatch_build.py +42 -0
  17. skipcheck_tm1-0.1.0.dev0/pyproject.toml +39 -0
  18. skipcheck_tm1-0.1.0.dev0/spec/tm1-api.json +12202 -0
  19. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/__init__.py +89 -0
  20. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/_calls.py +267 -0
  21. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/_compat.py +71 -0
  22. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/_protocol.py +285 -0
  23. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/_resource_base.py +63 -0
  24. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/_views.py +89 -0
  25. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/__init__.py +25 -0
  26. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/client.py +396 -0
  27. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/cognos.py +103 -0
  28. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/pool.py +294 -0
  29. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/resources.py +124 -0
  30. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/__init__.py +70 -0
  31. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/_base.py +33 -0
  32. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/annotation.py +185 -0
  33. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/attribute.py +142 -0
  34. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/content.py +174 -0
  35. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/cube.py +326 -0
  36. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/data.py +803 -0
  37. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/dimension.py +902 -0
  38. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/encryption.py +144 -0
  39. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/git.py +204 -0
  40. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/process.py +630 -0
  41. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/security.py +298 -0
  42. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/services/server.py +254 -0
  43. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/aio/session.py +838 -0
  44. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/auth.py +119 -0
  45. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/base.py +269 -0
  46. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/client.py +5 -0
  47. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/errors.py +405 -0
  48. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/identity.py +114 -0
  49. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/model.py +7 -0
  50. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/odata.py +837 -0
  51. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/operation.py +74 -0
  52. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/request.py +252 -0
  53. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/resources.py +17 -0
  54. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/services.py +4 -0
  55. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/session.py +6 -0
  56. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/timeouts.py +91 -0
  57. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/values.py +429 -0
  58. skipcheck_tm1-0.1.0.dev0/src/skipcheck_tm1/version.py +369 -0
  59. skipcheck_tm1-0.1.0.dev0/tests/__init__.py +0 -0
  60. skipcheck_tm1-0.1.0.dev0/tests/conformance/__init__.py +0 -0
  61. skipcheck_tm1-0.1.0.dev0/tests/conformance/codec.py +278 -0
  62. skipcheck_tm1-0.1.0.dev0/tests/conformance/scenarios.py +174 -0
  63. skipcheck_tm1-0.1.0.dev0/tests/conformance/test_calls.py +205 -0
  64. skipcheck_tm1-0.1.0.dev0/tests/conformance/test_dimension_scenarios.py +84 -0
  65. skipcheck_tm1-0.1.0.dev0/tests/conformance/test_encoding.py +62 -0
  66. skipcheck_tm1-0.1.0.dev0/tests/conformance/test_live_process_server.py +107 -0
  67. skipcheck_tm1-0.1.0.dev0/tests/conformance/test_live_runner.py +239 -0
  68. skipcheck_tm1-0.1.0.dev0/tests/conformance/test_live_traffic_compare.py +103 -0
  69. skipcheck_tm1-0.1.0.dev0/tests/conftest.py +142 -0
  70. skipcheck_tm1-0.1.0.dev0/tests/live/__init__.py +0 -0
  71. skipcheck_tm1-0.1.0.dev0/tests/live/conftest.py +189 -0
  72. skipcheck_tm1-0.1.0.dev0/tests/live/raw_tm1.py +155 -0
  73. skipcheck_tm1-0.1.0.dev0/tests/live/support.py +145 -0
  74. skipcheck_tm1-0.1.0.dev0/tests/live/test_annotation_service.py +58 -0
  75. skipcheck_tm1-0.1.0.dev0/tests/live/test_attribute_service.py +126 -0
  76. skipcheck_tm1-0.1.0.dev0/tests/live/test_cam_ldap_authentication.py +116 -0
  77. skipcheck_tm1-0.1.0.dev0/tests/live/test_cam_oidc_authentication.py +72 -0
  78. skipcheck_tm1-0.1.0.dev0/tests/live/test_cell_service.py +144 -0
  79. skipcheck_tm1-0.1.0.dev0/tests/live/test_cellset_service.py +129 -0
  80. skipcheck_tm1-0.1.0.dev0/tests/live/test_chore_service.py +136 -0
  81. skipcheck_tm1-0.1.0.dev0/tests/live/test_conformance_scenario.py +49 -0
  82. skipcheck_tm1-0.1.0.dev0/tests/live/test_content_service.py +112 -0
  83. skipcheck_tm1-0.1.0.dev0/tests/live/test_cube_attribute.py +80 -0
  84. skipcheck_tm1-0.1.0.dev0/tests/live/test_cube_rules.py +83 -0
  85. skipcheck_tm1-0.1.0.dev0/tests/live/test_cube_service.py +85 -0
  86. skipcheck_tm1-0.1.0.dev0/tests/live/test_dimension_service.py +86 -0
  87. skipcheck_tm1-0.1.0.dev0/tests/live/test_drillthrough.py +91 -0
  88. skipcheck_tm1-0.1.0.dev0/tests/live/test_edge_service.py +36 -0
  89. skipcheck_tm1-0.1.0.dev0/tests/live/test_element_service.py +86 -0
  90. skipcheck_tm1-0.1.0.dev0/tests/live/test_encryption_service.py +40 -0
  91. skipcheck_tm1-0.1.0.dev0/tests/live/test_generated_model.py +125 -0
  92. skipcheck_tm1-0.1.0.dev0/tests/live/test_git_service.py +192 -0
  93. skipcheck_tm1-0.1.0.dev0/tests/live/test_hierarchy_service.py +124 -0
  94. skipcheck_tm1-0.1.0.dev0/tests/live/test_level_and_member_service.py +31 -0
  95. skipcheck_tm1-0.1.0.dev0/tests/live/test_log_service.py +81 -0
  96. skipcheck_tm1-0.1.0.dev0/tests/live/test_mdx_and_model.py +30 -0
  97. skipcheck_tm1-0.1.0.dev0/tests/live/test_member_service.py +34 -0
  98. skipcheck_tm1-0.1.0.dev0/tests/live/test_member_set_service.py +24 -0
  99. skipcheck_tm1-0.1.0.dev0/tests/live/test_oidc_key_and_sql_data_source.py +29 -0
  100. skipcheck_tm1-0.1.0.dev0/tests/live/test_process_attribute.py +67 -0
  101. skipcheck_tm1-0.1.0.dev0/tests/live/test_process_debug.py +132 -0
  102. skipcheck_tm1-0.1.0.dev0/tests/live/test_process_service.py +111 -0
  103. skipcheck_tm1-0.1.0.dev0/tests/live/test_python_only.py +115 -0
  104. skipcheck_tm1-0.1.0.dev0/tests/live/test_sandbox_and_change_set.py +99 -0
  105. skipcheck_tm1-0.1.0.dev0/tests/live/test_server_service.py +45 -0
  106. skipcheck_tm1-0.1.0.dev0/tests/live/test_session_and_thread.py +79 -0
  107. skipcheck_tm1-0.1.0.dev0/tests/live/test_subset_service.py +105 -0
  108. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_batch.py +56 -0
  109. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_capabilities.py +66 -0
  110. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_client.py +26 -0
  111. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_impersonation_behavior.py +203 -0
  112. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_session.py +129 -0
  113. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_session_async.py +60 -0
  114. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_session_behavior.py +232 -0
  115. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_session_impersonation.py +73 -0
  116. skipcheck_tm1-0.1.0.dev0/tests/live/test_tm1_session_pool.py +88 -0
  117. skipcheck_tm1-0.1.0.dev0/tests/live/test_user_and_group.py +92 -0
  118. skipcheck_tm1-0.1.0.dev0/tests/live/test_view_service.py +113 -0
  119. skipcheck_tm1-0.1.0.dev0/tests/runtime/__init__.py +0 -0
  120. skipcheck_tm1-0.1.0.dev0/tests/runtime/conftest.py +149 -0
  121. skipcheck_tm1-0.1.0.dev0/tests/runtime/test_cognos.py +86 -0
  122. skipcheck_tm1-0.1.0.dev0/tests/runtime/test_java_parity_runtime.py +182 -0
  123. skipcheck_tm1-0.1.0.dev0/tests/runtime/test_pool.py +152 -0
  124. skipcheck_tm1-0.1.0.dev0/tests/runtime/test_session.py +612 -0
  125. skipcheck_tm1-0.1.0.dev0/tests/runtime/test_units.py +547 -0
  126. skipcheck_tm1-0.1.0.dev0/tests/services/__init__.py +0 -0
  127. skipcheck_tm1-0.1.0.dev0/tests/services/test_annotation.py +79 -0
  128. skipcheck_tm1-0.1.0.dev0/tests/services/test_attribute.py +100 -0
  129. skipcheck_tm1-0.1.0.dev0/tests/services/test_content.py +116 -0
  130. skipcheck_tm1-0.1.0.dev0/tests/services/test_cube.py +96 -0
  131. skipcheck_tm1-0.1.0.dev0/tests/services/test_data.py +465 -0
  132. skipcheck_tm1-0.1.0.dev0/tests/services/test_dimension.py +390 -0
  133. skipcheck_tm1-0.1.0.dev0/tests/services/test_encryption.py +76 -0
  134. skipcheck_tm1-0.1.0.dev0/tests/services/test_git.py +92 -0
  135. skipcheck_tm1-0.1.0.dev0/tests/services/test_process.py +362 -0
  136. skipcheck_tm1-0.1.0.dev0/tests/services/test_security.py +170 -0
  137. skipcheck_tm1-0.1.0.dev0/tests/services/test_server.py +137 -0
  138. skipcheck_tm1-0.1.0.dev0/tests/services/test_view.py +104 -0
  139. skipcheck_tm1-0.1.0.dev0/tests/test_architecture.py +216 -0
  140. skipcheck_tm1-0.1.0.dev0/tests/test_contract.py +324 -0
  141. skipcheck_tm1-0.1.0.dev0/tests/test_coverage_gate.py +86 -0
  142. skipcheck_tm1-0.1.0.dev0/tests/test_format.py +20 -0
  143. skipcheck_tm1-0.1.0.dev0/tests/test_generator.py +98 -0
  144. skipcheck_tm1-0.1.0.dev0/tests/test_java_examples_parity.py +120 -0
  145. skipcheck_tm1-0.1.0.dev0/tests/test_java_live_parity.py +221 -0
  146. skipcheck_tm1-0.1.0.dev0/tests/test_java_parity.py +167 -0
  147. skipcheck_tm1-0.1.0.dev0/tests/test_model.py +188 -0
  148. skipcheck_tm1-0.1.0.dev0/tests/test_session.py +171 -0
  149. skipcheck_tm1-0.1.0.dev0/tests/test_types.py +21 -0
  150. skipcheck_tm1-0.1.0.dev0/tests/test_views.py +228 -0
@@ -0,0 +1,9 @@
1
+ # Generated from ../spec/tm1-api.json at build time (hatch_build.py), never committed
2
+ src/skipcheck_tm1/_generated/
3
+ .venv/
4
+ __pycache__/
5
+ *.egg-info/
6
+ dist/
7
+ .pytest_cache/
8
+ build/
9
+ src/skipcheck_tm1/_sync/
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.5
2
+ Name: skipcheck-tm1
3
+ Version: 0.1.0.dev0
4
+ Summary: Python client for the IBM Planning Analytics (TM1) REST API, generated from its $metadata
5
+ License-Expression: AGPL-3.0-only
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: httpx>=0.27
8
+ Requires-Dist: pydantic>=2.7
9
+ Provides-Extra: test
10
+ Requires-Dist: pyright==1.1.414; extra == 'test'
11
+ Requires-Dist: pytest>=8; extra == 'test'
12
+ Requires-Dist: ruff==0.17.6; extra == 'test'
13
+ Description-Content-Type: text/markdown
14
+
15
+ # skipcheck-tm1 (Python)
16
+
17
+ A Python client for the **IBM Planning Analytics (TM1) REST API**, with the same API as the Java client (`tm1-client`): the same services, methods, parameters, queries, patches, session views and errors, named the Python way. Its model is generated from the same language-neutral spec ([`spec/tm1-api.json`](../spec)).
18
+
19
+ It comes in two flavors with one API: sync (`skipcheck_tm1`) and asyncio (`skipcheck_tm1.aio`). Requires Python 3.10+, [httpx](https://www.python-httpx.org/) and [pydantic](https://docs.pydantic.dev/) 2.
20
+
21
+ ```python
22
+ from skipcheck_tm1 import Filter, ODataPath, ODataQuery, Tm1Client
23
+ from skipcheck_tm1.model import Cube, CubePatch
24
+
25
+ with Tm1Client.builder().base_url("http://localhost:8010/api/v1/").basic_auth("admin", "apple").build() as tm1:
26
+ for cube in tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME).filter(Filter.starts_with(Cube.NAME, "Sales"))):
27
+ print(cube.name)
28
+
29
+ dimensions = ODataPath.of("Dimensions")
30
+ tm1.cubes.create(CubePatch.builder().name("Plan").bind_dimensions(dimensions.key("Region"), dimensions.key("Year")).build())
31
+
32
+ rules = "SKIPCHECK;\n['Margin'] = N: ['Revenue'] - ['Cost'];"
33
+ if not tm1.cubes.check_rules("Plan", rules):
34
+ tm1.cubes.update("Plan", CubePatch.builder().rules(rules).build())
35
+
36
+ # A long process, run asynchronously by TM1 and polled; interrupting the wait stops it on TM1
37
+ tm1.with_async(2).processes.execute_with_return("Rebuild Forecast")
38
+ ```
39
+
40
+ The same with asyncio:
41
+
42
+ ```python
43
+ from skipcheck_tm1.aio import AsyncTm1Client
44
+
45
+ async with AsyncTm1Client.builder().base_url("http://localhost:8010/api/v1/").basic_auth("admin", "apple").build() as tm1:
46
+ cubes = await tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME))
47
+ ```
48
+
49
+ ## From the Java client
50
+
51
+ | Java | Python |
52
+ |---|---|
53
+ | `tm1.cubes().modelCubes(query)` | `tm1.cubes.model_cubes(query)`; services are properties, methods snake case |
54
+ | `Mono<T>` | `T` (asyncio: a coroutine of `T`) |
55
+ | `Flux<T>` | `list[T]`; log tails and cellset streams are iterators |
56
+ | `ODataQuery query` parameter | `query: ODataQuery | None = None`, and keyword shortcuts (`select=…`, `top=…`) |
57
+ | Overloads (`update(name, patch)`, `update(name, patch, etag)`) | Optional parameters (`update(name, patch, etag=None)`) |
58
+ | `CubePatch.builder().name("x").build()` | the same, in snake case; a model instance (`Cube(name="x")`) works too |
59
+ | `Cube.NAME`, `Filter.and(…)` | `Cube.NAME`, `Filter.and_(…)` (`and`, `or`, `not` are keywords) |
60
+ | `Tm1Client.builder()…build()`, `withSandbox`, `withAsync`, `batch()` | `Tm1Client.builder()…build()`, `with_sandbox`, `with_async`, `batch()` |
61
+ | `Tm1SessionPool`, `Tm1Identity`, `Tm1Timeouts`, `Tm1ErrorClassifier` | the same names |
62
+ | `Tm1NotFoundException` | `Tm1NotFoundError` |
63
+ | Micrometer observations | the `skipcheck_tm1` logger |
64
+
65
+ `tm1.api` adds what Java doesn't have: a generated member for every endpoint (`tm1.api.cubes["Sales"].views.list()`). It honours `$metadata`'s containment: through a reference, such as `users["u"].groups["g"]`, it reads only, since on TM1 a delete through it deletes the group itself.
66
+
67
+ ## How it's made
68
+
69
+ | Part | Where | How |
70
+ |---|---|---|
71
+ | Model: an enum or pydantic model per CSDL type, patch builders, `Tm1Operations` | `skipcheck_tm1.model` | Generated from the spec at build time |
72
+ | Generated API (`tm1.api`) | `skipcheck_tm1._generated.api`, `aio_api` | Generated from the spec at build time |
73
+ | Services, session, pool, client | `skipcheck_tm1/aio/` | Hand-written, asyncio: the source of truth |
74
+ | The same, sync | `skipcheck_tm1/_sync/` | Generated from `aio/` by `tm1_pygen.unasync` at build time |
75
+ | Queries, requests, errors, versions, value types | `skipcheck_tm1/*.py` | Hand-written, shared by both flavors |
76
+
77
+ Nothing generated is committed: the build (`hatch_build.py`) runs [`codegen/tm1_pygen`](codegen/tm1_pygen), which needs only the standard library. To regenerate by hand:
78
+
79
+ ```sh
80
+ PYTHONPATH=codegen python -m tm1_pygen ../spec/tm1-api.json src/skipcheck_tm1
81
+ ```
82
+
83
+ ## Tests
84
+
85
+ ```sh
86
+ pip install -e '.[test]' -e './testcontainers[test]'
87
+ pytest
88
+ ```
89
+
90
+ - `test_format.py` runs Ruff ([`ruff.toml`](../ruff.toml)): layout, lint, and a docstring on every public module, class, method and function of the two packages, as the Java build requires Javadoc.
91
+ - `test_types.py` runs Pyright ([`pyrightconfig.json`](../pyrightconfig.json)) over both packages' sources, the generated modules included, as the Java build runs NullAway and Error Prone.
92
+ - `test_architecture.py` keeps the rules of Java's `ArchitectureTest`: the asyncio flavor never blocks or starts work nobody awaits, request URLs come from `ODataPath` and `ODataQuery`, logging goes through `logging` only, `odata.py` knows nothing of TM1, and services are stateless, async and declare their endpoints.
93
+ - `test_java_examples_parity.py` keeps the guide's examples ([`examples/`](examples), and tm1-testcontainers' [`examples/`](../tm1-testcontainers/examples)) the Java ones: a file for each Java examples class, with the same regions. They aren't run; `test_types.py` type-checks them and `test_format.py` lints them.
94
+ - `test_java_parity.py` and `runtime/test_java_parity_runtime.py` read the Java sources and require every public class and method, with the same `@Tm1Endpoint` IDs and parameters.
95
+ - `test_coverage_gate.py` holds each flavor to the spec's 242 endpoints, by the Java gate's rules.
96
+ - `test_contract.py` calls every endpoint through the generated API, in both flavors, against a fake TM1, and checks the request.
97
+ - `services/` and `runtime/` port the Java client's unit tests, in both flavors.
98
+ - `test_model.py` round-trips the payloads the Java client captured from a real TM1; `conformance/` shares OData encoding cases with Java and .NET.
99
+ - `live/` ports the Java live tests (`*Tm1Test` and `*BehaviorTest`), one file per Java class and each test under its Java name: `CubeServiceTm1Test` is `live/test_cube_service.py`, `Tm1SessionBehaviorTest` is `live/test_tm1_session_behavior.py`, and `reordersTheStorageOrder` is `test_reorders_the_storage_order`. `test_java_live_parity.py` reads the Java sources and fails unless each class and test is there, or [`coverage/live-excluded.txt`](coverage/live-excluded.txt) says why not; what only this client tests is in `live/test_python_only.py`. The CAM tests start Cognos (and Keycloak) themselves and skip without a Cognos source. Like the Java ones, they start TM1 in Docker themselves, with [`tm1-testcontainers`](testcontainers) (the Python port of Java's), from the same settings the Java tests read: `TM1_PRIVATE_IMAGE`, `TM1_HOME_DIR`, `TM1_INSTALL_VOLUME`, `TM1_BUNDLE_DIR` or `TM1_BUNDLE_URL`. `TM1_URL` (with `TM1_USER`, `TM1_PASSWORD`, `TM1_NAMESPACE`, `TM1_VERIFY=false`) uses a server that's already running instead. Without either they're skipped. [`scripts/live-tests.sh`](../scripts/live-tests.sh) runs the Java, Python and .NET live tests together.
100
+
101
+ The live tests pass against TM1 11.8.03500.6 (Planning Analytics 2.1.19), started in Docker by tm1-testcontainers from an installed `tm1_64` folder (`TM1_HOME_DIR`): 203 tests, with relational drillthrough skipped for want of an ODBC source. The five CAM tests need a Cognos source and pass on the Cognos test container (12.1.1). tm1-testcontainers' own tests pass for the TM1 server; the TM1 Web and Planning Analytics Workspace ones haven't run, for want of those products. They also pass against a server that is already running, named with `TM1_URL`.
@@ -0,0 +1,87 @@
1
+ # skipcheck-tm1 (Python)
2
+
3
+ A Python client for the **IBM Planning Analytics (TM1) REST API**, with the same API as the Java client (`tm1-client`): the same services, methods, parameters, queries, patches, session views and errors, named the Python way. Its model is generated from the same language-neutral spec ([`spec/tm1-api.json`](../spec)).
4
+
5
+ It comes in two flavors with one API: sync (`skipcheck_tm1`) and asyncio (`skipcheck_tm1.aio`). Requires Python 3.10+, [httpx](https://www.python-httpx.org/) and [pydantic](https://docs.pydantic.dev/) 2.
6
+
7
+ ```python
8
+ from skipcheck_tm1 import Filter, ODataPath, ODataQuery, Tm1Client
9
+ from skipcheck_tm1.model import Cube, CubePatch
10
+
11
+ with Tm1Client.builder().base_url("http://localhost:8010/api/v1/").basic_auth("admin", "apple").build() as tm1:
12
+ for cube in tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME).filter(Filter.starts_with(Cube.NAME, "Sales"))):
13
+ print(cube.name)
14
+
15
+ dimensions = ODataPath.of("Dimensions")
16
+ tm1.cubes.create(CubePatch.builder().name("Plan").bind_dimensions(dimensions.key("Region"), dimensions.key("Year")).build())
17
+
18
+ rules = "SKIPCHECK;\n['Margin'] = N: ['Revenue'] - ['Cost'];"
19
+ if not tm1.cubes.check_rules("Plan", rules):
20
+ tm1.cubes.update("Plan", CubePatch.builder().rules(rules).build())
21
+
22
+ # A long process, run asynchronously by TM1 and polled; interrupting the wait stops it on TM1
23
+ tm1.with_async(2).processes.execute_with_return("Rebuild Forecast")
24
+ ```
25
+
26
+ The same with asyncio:
27
+
28
+ ```python
29
+ from skipcheck_tm1.aio import AsyncTm1Client
30
+
31
+ async with AsyncTm1Client.builder().base_url("http://localhost:8010/api/v1/").basic_auth("admin", "apple").build() as tm1:
32
+ cubes = await tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME))
33
+ ```
34
+
35
+ ## From the Java client
36
+
37
+ | Java | Python |
38
+ |---|---|
39
+ | `tm1.cubes().modelCubes(query)` | `tm1.cubes.model_cubes(query)`; services are properties, methods snake case |
40
+ | `Mono<T>` | `T` (asyncio: a coroutine of `T`) |
41
+ | `Flux<T>` | `list[T]`; log tails and cellset streams are iterators |
42
+ | `ODataQuery query` parameter | `query: ODataQuery | None = None`, and keyword shortcuts (`select=…`, `top=…`) |
43
+ | Overloads (`update(name, patch)`, `update(name, patch, etag)`) | Optional parameters (`update(name, patch, etag=None)`) |
44
+ | `CubePatch.builder().name("x").build()` | the same, in snake case; a model instance (`Cube(name="x")`) works too |
45
+ | `Cube.NAME`, `Filter.and(…)` | `Cube.NAME`, `Filter.and_(…)` (`and`, `or`, `not` are keywords) |
46
+ | `Tm1Client.builder()…build()`, `withSandbox`, `withAsync`, `batch()` | `Tm1Client.builder()…build()`, `with_sandbox`, `with_async`, `batch()` |
47
+ | `Tm1SessionPool`, `Tm1Identity`, `Tm1Timeouts`, `Tm1ErrorClassifier` | the same names |
48
+ | `Tm1NotFoundException` | `Tm1NotFoundError` |
49
+ | Micrometer observations | the `skipcheck_tm1` logger |
50
+
51
+ `tm1.api` adds what Java doesn't have: a generated member for every endpoint (`tm1.api.cubes["Sales"].views.list()`). It honours `$metadata`'s containment: through a reference, such as `users["u"].groups["g"]`, it reads only, since on TM1 a delete through it deletes the group itself.
52
+
53
+ ## How it's made
54
+
55
+ | Part | Where | How |
56
+ |---|---|---|
57
+ | Model: an enum or pydantic model per CSDL type, patch builders, `Tm1Operations` | `skipcheck_tm1.model` | Generated from the spec at build time |
58
+ | Generated API (`tm1.api`) | `skipcheck_tm1._generated.api`, `aio_api` | Generated from the spec at build time |
59
+ | Services, session, pool, client | `skipcheck_tm1/aio/` | Hand-written, asyncio: the source of truth |
60
+ | The same, sync | `skipcheck_tm1/_sync/` | Generated from `aio/` by `tm1_pygen.unasync` at build time |
61
+ | Queries, requests, errors, versions, value types | `skipcheck_tm1/*.py` | Hand-written, shared by both flavors |
62
+
63
+ Nothing generated is committed: the build (`hatch_build.py`) runs [`codegen/tm1_pygen`](codegen/tm1_pygen), which needs only the standard library. To regenerate by hand:
64
+
65
+ ```sh
66
+ PYTHONPATH=codegen python -m tm1_pygen ../spec/tm1-api.json src/skipcheck_tm1
67
+ ```
68
+
69
+ ## Tests
70
+
71
+ ```sh
72
+ pip install -e '.[test]' -e './testcontainers[test]'
73
+ pytest
74
+ ```
75
+
76
+ - `test_format.py` runs Ruff ([`ruff.toml`](../ruff.toml)): layout, lint, and a docstring on every public module, class, method and function of the two packages, as the Java build requires Javadoc.
77
+ - `test_types.py` runs Pyright ([`pyrightconfig.json`](../pyrightconfig.json)) over both packages' sources, the generated modules included, as the Java build runs NullAway and Error Prone.
78
+ - `test_architecture.py` keeps the rules of Java's `ArchitectureTest`: the asyncio flavor never blocks or starts work nobody awaits, request URLs come from `ODataPath` and `ODataQuery`, logging goes through `logging` only, `odata.py` knows nothing of TM1, and services are stateless, async and declare their endpoints.
79
+ - `test_java_examples_parity.py` keeps the guide's examples ([`examples/`](examples), and tm1-testcontainers' [`examples/`](../tm1-testcontainers/examples)) the Java ones: a file for each Java examples class, with the same regions. They aren't run; `test_types.py` type-checks them and `test_format.py` lints them.
80
+ - `test_java_parity.py` and `runtime/test_java_parity_runtime.py` read the Java sources and require every public class and method, with the same `@Tm1Endpoint` IDs and parameters.
81
+ - `test_coverage_gate.py` holds each flavor to the spec's 242 endpoints, by the Java gate's rules.
82
+ - `test_contract.py` calls every endpoint through the generated API, in both flavors, against a fake TM1, and checks the request.
83
+ - `services/` and `runtime/` port the Java client's unit tests, in both flavors.
84
+ - `test_model.py` round-trips the payloads the Java client captured from a real TM1; `conformance/` shares OData encoding cases with Java and .NET.
85
+ - `live/` ports the Java live tests (`*Tm1Test` and `*BehaviorTest`), one file per Java class and each test under its Java name: `CubeServiceTm1Test` is `live/test_cube_service.py`, `Tm1SessionBehaviorTest` is `live/test_tm1_session_behavior.py`, and `reordersTheStorageOrder` is `test_reorders_the_storage_order`. `test_java_live_parity.py` reads the Java sources and fails unless each class and test is there, or [`coverage/live-excluded.txt`](coverage/live-excluded.txt) says why not; what only this client tests is in `live/test_python_only.py`. The CAM tests start Cognos (and Keycloak) themselves and skip without a Cognos source. Like the Java ones, they start TM1 in Docker themselves, with [`tm1-testcontainers`](testcontainers) (the Python port of Java's), from the same settings the Java tests read: `TM1_PRIVATE_IMAGE`, `TM1_HOME_DIR`, `TM1_INSTALL_VOLUME`, `TM1_BUNDLE_DIR` or `TM1_BUNDLE_URL`. `TM1_URL` (with `TM1_USER`, `TM1_PASSWORD`, `TM1_NAMESPACE`, `TM1_VERIFY=false`) uses a server that's already running instead. Without either they're skipped. [`scripts/live-tests.sh`](../scripts/live-tests.sh) runs the Java, Python and .NET live tests together.
86
+
87
+ The live tests pass against TM1 11.8.03500.6 (Planning Analytics 2.1.19), started in Docker by tm1-testcontainers from an installed `tm1_64` folder (`TM1_HOME_DIR`): 203 tests, with relational drillthrough skipped for want of an ODBC source. The five CAM tests need a Cognos source and pass on the Cognos test container (12.1.1). tm1-testcontainers' own tests pass for the TM1 server; the TM1 Web and Planning Analytics Workspace ones haven't run, for want of those products. They also pass against a server that is already running, named with `TM1_URL`.
@@ -0,0 +1,51 @@
1
+ """tm1_pygen: generates the Python client's model and API from the language-neutral API spec
2
+ (``spec/tm1-api.json``, exported from the ``$metadata`` snapshot by ``tm1-codegen``).
3
+
4
+ Run ``python -m tm1_pygen <spec.json> <package directory>``; the Python package's build runs
5
+ it (``hatch_build.py``). It needs nothing but the standard library.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+
12
+ from . import emit_api, emit_model, emit_operations, unasync
13
+ from .spec import Spec
14
+
15
+ __all__ = ["generate"]
16
+
17
+ _INIT = '''"""Generated from spec/tm1-api.json by tm1_pygen: don't edit, don't commit.
18
+
19
+ ``model``, ``api`` (sync), ``aio_api`` (asyncio) and ``index``; import the one you need.
20
+ """
21
+ '''
22
+
23
+
24
+ def generate(spec_path: str | Path, package_dir: str | Path) -> list[Path]:
25
+ """Writes ``_generated/`` under ``package_dir`` (the ``skipcheck_tm1`` directory) from the
26
+ spec, and ``_sync/`` from ``aio/`` (the sync flavor of the hand-written code), replacing both."""
27
+ spec = Spec.load(spec_path)
28
+ out = Path(package_dir) / "_generated"
29
+ out.mkdir(parents=True, exist_ok=True)
30
+ for old in out.glob("*.py"):
31
+ old.unlink()
32
+ api, index = emit_api.emit(spec, "sync")
33
+ aio_api, _ = emit_api.emit(spec, "async")
34
+ files = {
35
+ "__init__.py": _INIT,
36
+ "model.py": emit_model.emit(spec),
37
+ "api.py": api,
38
+ "aio_api.py": aio_api,
39
+ "index.py": index,
40
+ "operations.py": emit_operations.emit(spec),
41
+ "patches.py": emit_model.emit_patches(spec),
42
+ }
43
+ written = []
44
+ for name, text in files.items():
45
+ path = out / name
46
+ path.write_text(text, encoding="utf-8")
47
+ written.append(path)
48
+ aio = Path(package_dir) / "aio"
49
+ if aio.is_dir():
50
+ written += unasync.generate(aio, Path(package_dir) / "_sync")
51
+ return written
@@ -0,0 +1,8 @@
1
+ import sys
2
+
3
+ from . import generate
4
+
5
+ if len(sys.argv) != 3:
6
+ sys.exit("Usage: python -m tm1_pygen <spec.json> <skipcheck_tm1 package directory>")
7
+ for path in generate(sys.argv[1], sys.argv[2]):
8
+ print(f"wrote {path}")
@@ -0,0 +1,41 @@
1
+ """Docstrings from the spec's Markdown-ish text."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import textwrap
6
+ from typing import Any
7
+
8
+
9
+ def revisions(item: dict[str, Any]) -> str:
10
+ """``Since 11.8.20.`` and ``Deprecated in 11.8.3: …``, as a trailing paragraph, or nothing."""
11
+ parts = []
12
+ if item.get("since"):
13
+ parts.append(f"Since TM1 schema {item['since']}.")
14
+ deprecated = item.get("deprecated")
15
+ if deprecated:
16
+ text = f".. deprecated:: {deprecated['version']}"
17
+ if deprecated.get("reason"):
18
+ text += " " + " ".join(deprecated["reason"].split())
19
+ parts.append(text)
20
+ return ("\n\n" + "\n\n".join(parts)) if parts else ""
21
+
22
+
23
+ def md(text: str) -> str:
24
+ """The overlay's Markdown `code` as reST ``code``."""
25
+ parts = text.split("`")
26
+ return "".join(p if i % 2 == 0 else f"``{p}``" for i, p in enumerate(parts))
27
+
28
+
29
+ def docstring(text: str, indent: str) -> list[str]:
30
+ text = text.strip().replace("\\", "\\\\").replace('"""', '\\"\\"\\"')
31
+ paragraphs = [" ".join(p.split()) if not p.lstrip().startswith("..") else p.strip() for p in text.split("\n\n")]
32
+ lines: list[str] = []
33
+ for i, paragraph in enumerate(paragraphs):
34
+ if i:
35
+ lines.append("")
36
+ lines.extend(textwrap.wrap(paragraph, width=96 - len(indent), break_long_words=False, break_on_hyphens=False) or [""])
37
+ if text.endswith('"'):
38
+ lines[-1] += " "
39
+ if len(lines) == 1:
40
+ return [f'{indent}"""{lines[0]}"""']
41
+ return [f'{indent}"""{lines[0]}'] + [f"{indent}{line}" if line else "" for line in lines[1:]] + [f'{indent}"""']