You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-71Lines changed: 32 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ By default `tangle api` uses `--schema-source auto`, which means official static
33
33
34
34
`tangle sdk` commands are hand-written workflows. They can be:
35
35
36
-
-**local-only**: no generated/native API bindings required, e.g. pipeline validation/layout and component generation;
36
+
-**local-only**: no generated API bindings required, e.g. pipeline validation/layout and component generation;
37
37
-**API-backed**: use the generated client but add domain behavior, e.g. pipeline-run submit payload construction, hydration, artifact lookup, publishing/version checks, or config batching.
38
38
39
39
Current SDK groups include:
@@ -86,22 +86,22 @@ Use `--log-type none` for quiet machine-readable runs, and `--log-type file` to
86
86
The repository contains two Python import packages with different responsibilities:
87
87
88
88
-`tangle_cli` is hand-written. It contains CLI wiring, SDK/business helpers, local pipeline/component workflows, dynamic API discovery, codegen, shared runtime classes, logging, and extension classes.
89
-
-`tangle_api` is generated/native. It contains checked-in generated Pydantic models, generated endpoint operation methods, and the official OpenAPI snapshot.
89
+
-`tangle_api` is generated/static. It contains checked-in generated Pydantic models, generated endpoint operation methods, and the official OpenAPI snapshot.
90
90
91
-
The default `tangle-cli` package keeps the top-level import and local-only SDK commands native-free. Install the native extra when you want static API-backed commands and the handwritten `TangleApiClient` wrapper to use the checked-in generated bindings:
91
+
The default public `tangle-cli` package depends on the matching `tangle-api` package, so normal installs include the checked-in generated bindings used by static API-backed commands and the handwritten `TangleApiClient` wrapper:
92
92
93
93
```bash
94
-
pip install 'tangle-cli[native]'
94
+
pip install tangle-cli
95
95
```
96
96
97
-
In this workspace, `uv` installs the workspace `tangle-api` package for development and tests:
97
+
The `native` extra remains as a compatibility no-op alias for older install instructions. In this workspace, `uv` installs the workspace `tangle-api` package for development and tests:
98
98
99
99
```bash
100
100
uv run tangle api --help
101
101
uv run tangle sdk pipelines validate pipeline.yaml
102
102
```
103
103
104
-
If you are embedding `tangle_cli` in a downstream project, you can provide your own local `tangle_api.generated`package produced from your backend schema instead of using this repo's official generated package.
104
+
Custom API/codegen users can still run codegen from the fully capable install; generating bindings does not require removing the official `tangle-api` package. For project-local generated APIs, generate into a local source tree such as `src/tangle_api/generated`(and `src/tangle_api/schema/openapi.json` when you want `tangle api --schema-source official`) and run from that project so local `src/tangle_api` shadows site-packages. For packaged custom APIs, publish/provide a distribution named `tangle-api` with a version compatible with this `tangle-cli` release (for example `0.0.1a3+yourorg` for a `tangle-cli` dependency on `tangle-api==0.0.1a3`) via a private index, `--find-links`, or uv sources. As an expert escape hatch, `--no-deps` installs only `tangle-cli` and skips all dependencies, so that environment must manually provide every required runtime dependency plus its generated/custom `tangle_api`; this is acceptable for controlled codegen/custom scenarios but not normal UX.
105
105
106
106
## Quick command examples
107
107
@@ -204,9 +204,9 @@ uv run tangle api reset-cache --base-url https://api.example
204
204
205
205
Schema source modes are:
206
206
207
-
-`--schema-source auto` (default): official static operations plus cached-only backend extensions when a cache exists. Requires the native `tangle-api` package for official operations.
208
-
-`--schema-source official`: only the checked-in official static schema. Requires the native `tangle-api` package.
209
-
-`--schema-source cache`: only the schema previously written by `tangle api refresh` for the selected base URL. Does not require the native package.
207
+
-`--schema-source auto` (default): official static operations plus cached-only backend extensions when a cache exists. Normal `tangle-cli` installs include the `tangle-api` package needed for official operations; custom API projects can shadow or replace that package as described in the codegen section.
208
+
-`--schema-source official`: only the checked-in official static schema from `tangle-api` (or a compatible custom `tangle-api` package on your environment's import path).
209
+
-`--schema-source cache`: only the schema previously written by `tangle api refresh` for the selected base URL. This is the custom/source-checkout fallback when a consumer environment does not provide an importable `tangle_api.schema` package.
210
210
211
211
For resource help, put `--schema-source` on the resource group:
`TangleApiClient`is handwritten in `tangle_cli.client` and inherits generated endpoint methods from `tangle_api.generated.operations.GeneratedTangleApiOperations`. The generated endpoint methods call the handwritten transport/request logic. Handwritten semantic helpers such as `find_existing_components(...)` return domain models and normalize common compatibility cases.
308
308
309
-
The top-level `import tangle_cli` is lightweight and does not import native static bindings. Install the native extra or otherwise provide a local `tangle_api.generated` package before importing `tangle_cli.client`.
309
+
The top-level `import tangle_cli` is lightweight and does not import static bindings eagerly. Normal installs include `tangle-api`; source checkouts or downstream embeddings may instead provide a local `tangle_api.generated` package before importing `tangle_cli.client`.
310
310
311
311
## Codegen/autogen from OpenAPI
312
312
@@ -337,6 +337,17 @@ uv run python -m tangle_cli.openapi.codegen \
337
337
--out src/tangle_api/generated
338
338
```
339
339
340
+
For a project-local custom API package, write both the schema snapshot and generated modules under that project's source tree, then run tools/tests from the project environment so `src/tangle_api` is earlier on `sys.path` than the official site-packages package:
341
+
342
+
```bash
343
+
uv run python -m tangle_cli.openapi.codegen \
344
+
--openapi-url https://api.example/openapi.json \
345
+
--openapi src/tangle_api/schema/openapi.json \
346
+
--out src/tangle_api/generated
347
+
```
348
+
349
+
That project-local `tangle_api` package can be an editable/package source tree. If you ship the custom API bindings as a wheel or source distribution, use the distribution name `tangle-api` and a compatible version for the `tangle-cli` release you are using. A PEP 440 local version such as `0.0.1a3+yourorg` can satisfy a public `==0.0.1a3` dependency while distinguishing your private build. Provide that package through your private index, `--find-links`, or uv source configuration so the resolver chooses it instead of the public official package.
- `--out`: directory that receives `__init__.py`, `models.py`, and `operations.py`. Defaults to `packages/tangle-api/src/tangle_api/generated`.
361
+
- `--out`: directory that receives `__init__.py`, `runtime.py`, `models.py`, and `operations.py`. Defaults to `packages/tangle-api/src/tangle_api/generated`.
351
362
- `--operations-class-name`: generated operations mixin class name. Defaults to `GeneratedTangleApiOperations`.
352
-
- `--model-extension-module`: importable module with `MODEL_EXTENSIONS`; repeat to compose modules.
353
363
- `--model-alias`: expose a stable public model name from one or more source schema names, e.g. `ComponentSpec=ComponentSpecOutput,ComponentSpecInput`.
354
364
- `--request-body-schema` / `--request-body-schema-file`: override a specific operation's JSON request-body schema without mutating the fetched OpenAPI document.
355
365
356
366
At runtime, more `tangle api ...` commands become available in two ways:
357
367
358
-
1. Static codegen: regenerate and install/provide a `tangle_api.generated` package for the schema.
368
+
1. Static codegen: regenerate and install/provide a local or packaged `tangle_api` package containing `tangle_api.generated` and, for official-schema CLI discovery, `tangle_api.schema`.
359
369
2. Dynamic cache: run `tangle api refresh --base-url ...` and use `--schema-source auto` or `--schema-source cache` to expose cached-only operations through the dynamic CLI.
360
370
361
-
## Generated model extension pattern
371
+
The supported workaround hierarchy for custom API consumers is: prefer a project-local `src/tangle_api` package that shadows site-packages for that project; if distributing bindings, prefer a compatible private `tangle-api` distribution; reserve `--no-deps` installs or manual uninstalls of the official package for controlled expert environments where you manually provide all dependencies and the generated/custom `tangle_api` package.
362
372
363
-
Generated models use a generated implementation base plus a stable public subclass. For example, codegen emits this shape for a model with a handwritten extension:
373
+
## Runtime generated model extension pattern
374
+
375
+
`tangle_api.generated.models` is a leaf package and codegen emits plain generated Pydantic models directly:
364
376
365
377
```python
366
-
class _ComponentSpecGenerated(TangleGeneratedModel):
378
+
class ComponentSpec(TangleGeneratedModel):
367
379
name: Any = None
368
380
# generated OpenAPI fields...
369
-
370
-
class ComponentSpec(ComponentSpecExtensions, _ComponentSpecGenerated):
371
-
pass
372
-
```
373
-
374
-
The public class is a subclass rather than an alias because the public class name is the stable contract while the generated base can be regenerated. Subclassing lets the public class keep the OpenAPI/Pydantic fields from `_ComponentSpecGenerated` and add or override behavior through normal Python MRO.
375
-
376
-
Extension bases are placed to the **left** of the generated base:
377
-
378
-
```python
379
-
class ComponentSpec(ComponentSpecExtensions, _ComponentSpecGenerated):
380
-
pass
381
-
```
382
-
383
-
That means extension methods/properties override generated-base behavior when names overlap, while generated fields and `TangleGeneratedModel` runtime helpers such as `to_dict()` remain available.
384
-
385
-
The built-in default extension module is:
386
-
387
-
```text
388
-
tangle_cli.generated_model_extensions
389
381
```
390
382
391
-
It defines:
383
+
Generated models do not import `tangle_cli` and codegen does not bake downstream extension modules into `tangle_api`. Downstream packages compose their own extended model namespace at runtime. In `tangle_cli.models`, the default CLI mixins are declared in `tangle_cli.generated_model_extensions`:
392
384
393
385
```python
394
386
MODEL_EXTENSIONS = {
@@ -398,42 +390,11 @@ MODEL_EXTENSIONS = {
398
390
}
399
391
```
400
392
401
-
During codegen, `tangle_api.generated.models` imports those extension classes from `tangle_cli.generated_model_extensions`. This preserves the package boundary: `tangle_api`remains generated bindings, while `tangle_cli` owns handwritten runtime and extension behavior.
402
-
403
-
Downstream projects can layer their own extensions:
404
-
405
-
```python
406
-
# my_project/tangle_model_extensions.py
407
-
class MyComponentSpecExtensions:
408
-
@property
409
-
def owning_team(self) -> str | None:
410
-
return (self.metadata or {}).get("annotations", {}).get("team")
The default module is applied first. Repeated `--model-extension-module` values are applied in order, and later/downstream modules become leftmost in the generated public class MRO, so they override earlier/default extensions. If two modules export the same extension class name, codegen imports them with deterministic aliases.
425
-
426
-
Pass an empty string to disable built-in default extensions:
427
-
428
-
```bash
429
-
uv run python -m tangle_cli.openapi.codegen \
430
-
--from-snapshot \
431
-
--model-extension-module ""
432
-
```
393
+
`tangle_cli.models.compose_models(...)`reads those mappings and creates subclasses in the `tangle_cli.models` namespace, e.g. `ComponentSpec(ComponentSpecExtensions, tangle_api.generated.models.ComponentSpec)`, without mutating `tangle_api.generated.models`. The generated operations layer also calls `_response_model(model_name, default)` so `TangleApiClient` can deserialize responses into the CLI-composed classes while the base `GeneratedTangleApiOperations` remains downstream-agnostic.
433
394
434
-
The same empty-string sentinel can disable built-in `--model-alias` defaults. Built-in aliases keep stable public model names such as `ComponentSpec` even when a backend schema uses names like `ComponentSpecOutput` or `ComponentSpecInput`.
395
+
Downstream projects can use the same pattern in their own namespace: import base classes from `tangle_api.generated.models`, define method/property-only mixins plus a `MODEL_EXTENSIONS` mapping, and compose subclasses locally. Avoid global monkey-patching of `tangle_api.generated.models`.
435
396
436
-
Extension classes should be importable from their modules and should not import generated model classes. They should be mixins over generated data, not replacements for generated schemas.
397
+
Built-in `--model-alias` defaults still keep stable public model names such as `ComponentSpec` even when a backend schema uses names like `ComponentSpecOutput` or `ComponentSpecInput`.
Checked-in generated Tangle API models, operation proxies, and schema snapshot used by `tangle-cli[native]`.
3
+
Checked-in generated Tangle API models, operation proxies, and schema snapshot used by the default `tangle-cli` install.
4
+
5
+
This package is intentionally a leaf package: it depends on Pydantic, but not on `tangle-cli`. Custom API consumers can provide their own compatible distribution named `tangle-api` or a project-local `src/tangle_api` package that shadows the official package in that project environment.
0 commit comments