alembic-adapter-sdk 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.
@@ -0,0 +1,69 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
11
+ cancel-in-progress: true
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ test:
18
+ name: test (py${{ matrix.python-version }})
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ fail-fast: false
22
+ matrix:
23
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
24
+ steps:
25
+ - uses: actions/checkout@v6
26
+ - uses: actions/setup-python@v6
27
+ with:
28
+ python-version: ${{ matrix.python-version }}
29
+ - name: install package with dev dependencies
30
+ run: pip install -e ".[dev]"
31
+ - name: run tests with coverage gate
32
+ run: |
33
+ coverage run -m unittest discover -s tests -v
34
+ coverage report
35
+
36
+ lint:
37
+ name: lint
38
+ runs-on: ubuntu-latest
39
+ steps:
40
+ - uses: actions/checkout@v6
41
+ - uses: actions/setup-python@v6
42
+ with:
43
+ python-version: "3.12"
44
+ - uses: astral-sh/ruff-action@v3
45
+ - run: ruff check
46
+ - run: ruff format --check
47
+
48
+ build:
49
+ name: build
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - uses: actions/checkout@v6
53
+ - uses: actions/setup-python@v6
54
+ with:
55
+ python-version: "3.12"
56
+ - run: python -m pip install --upgrade build
57
+ - run: python -m build
58
+
59
+ success:
60
+ name: success
61
+ needs: [test, lint, build]
62
+ runs-on: ubuntu-latest
63
+ if: always()
64
+ steps:
65
+ - name: check results
66
+ run: |
67
+ if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
68
+ exit 1
69
+ fi
@@ -0,0 +1,38 @@
1
+ name: publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ environment: pypi
12
+ permissions:
13
+ id-token: write
14
+ contents: write
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+ - uses: actions/setup-python@v6
18
+ with:
19
+ python-version: "3.12"
20
+ - name: build
21
+ run: |
22
+ pip install build
23
+ python -m build
24
+ - name: generate sbom
25
+ run: |
26
+ pip install cyclonedx-bom
27
+ python -m pip freeze --all | cyclonedx-py requirements - --pyproject pyproject.toml -o "/tmp/sbom-${{ github.ref_name }}.cdx.json"
28
+ - name: upload sbom
29
+ uses: actions/upload-artifact@v7
30
+ with:
31
+ name: sbom-${{ github.ref_name }}
32
+ path: /tmp/sbom-${{ github.ref_name }}.cdx.json
33
+ - name: attach sbom to release
34
+ uses: softprops/action-gh-release@v3
35
+ with:
36
+ files: /tmp/sbom-${{ github.ref_name }}.cdx.json
37
+ - name: publish to pypi
38
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+ .ruff_cache/
9
+ .mypy_cache/
10
+ .pytest_cache/
11
+ .coverage
12
+ .coverage.*
13
+ coverage.xml
14
+ htmlcov/
15
+ site/
16
+ .DS_Store
@@ -0,0 +1,201 @@
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,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 cyberwitchery labs
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: alembic-adapter-sdk
3
+ Version: 0.1.0
4
+ Summary: SDK for writing alembic external adapters in Python
5
+ Project-URL: Homepage, https://github.com/cyberwitchery/alembic-adapter-sdk-python
6
+ Project-URL: Repository, https://github.com/cyberwitchery/alembic-adapter-sdk-python
7
+ Project-URL: alembic (core), https://github.com/cyberwitchery/alembic
8
+ Author-email: cyberwitchery lab <contact@cyberwitchery.com>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: adapter,alembic,dcim,ipam,network-automation
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: System :: Networking
17
+ Requires-Python: >=3.10
18
+ Provides-Extra: dev
19
+ Requires-Dist: coverage[toml]; extra == 'dev'
20
+ Requires-Dist: ruff; extra == 'dev'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # alembic-adapter-sdk (python)
24
+
25
+ a small, dependency-free sdk for writing [alembic](https://github.com/cyberwitchery/alembic)
26
+ external adapters in python.
27
+
28
+ network engineering lives in python, so adapters should be writable there too.
29
+ alembic delegates backend i/o to *external adapters*: standalone programs the
30
+ alembic host spawns as subprocesses, exchanging one json request and one json
31
+ response over stdin/stdout. this sdk handles that protocol so you only write the
32
+ backend logic.
33
+
34
+ the import package is `alembic_adapter`. (the pypi distribution is
35
+ `alembic-adapter-sdk`; the bare name `alembic` belongs to sqlalchemy's migration
36
+ tool and is unrelated.)
37
+
38
+ ## install
39
+
40
+ ```bash
41
+ pip install alembic-adapter-sdk
42
+ ```
43
+
44
+ or, from a checkout:
45
+
46
+ ```bash
47
+ pip install -e .
48
+ ```
49
+
50
+ the sdk has no runtime dependencies; it speaks json with the stdlib.
51
+
52
+ ## writing an adapter
53
+
54
+ subclass `Adapter`, implement the methods your backend needs, and call `run`:
55
+
56
+ ```python
57
+ from alembic_adapter import Adapter, ApplyReport, AppliedOp, Create, run
58
+
59
+ class MyAdapter(Adapter):
60
+ def setup(self, config):
61
+ # `config` is the parsed `setup:` block from the backend config.
62
+ self.host = (config or {}).get("host", "http://localhost:8080")
63
+
64
+ def read(self, schema, types, state):
65
+ # observe backend state -> list[ExternalObject]; the engine diffs it
66
+ # against the desired inventory to build a plan. emit-only adapters
67
+ # return [] (the default).
68
+ return []
69
+
70
+ def write(self, schema, ops, state):
71
+ # apply create/update/delete ops, then report what was applied.
72
+ report = ApplyReport()
73
+ for op in ops:
74
+ if isinstance(op, Create):
75
+ ... # create op.desired on the backend
76
+ report.applied.append(AppliedOp(uid=op.uid, type_name=op.type_name))
77
+ return report
78
+
79
+ if __name__ == "__main__":
80
+ run(MyAdapter())
81
+ ```
82
+
83
+ `run` reads one request from stdin, dispatches it, and writes a
84
+ newline-terminated json response to stdout. any exception your adapter raises is
85
+ turned into a well-formed `{"ok": false, "error": ...}` response.
86
+
87
+ see [`examples/example_adapter.py`](examples/example_adapter.py) for a complete,
88
+ copyable starting point.
89
+
90
+ ## the protocol
91
+
92
+ every request carries `version` (currently `1`) and a `method`. the sdk parses
93
+ the payload into typed objects and serializes your results back:
94
+
95
+ | method | you receive | you return |
96
+ | --------------- | --------------------------------- | ------------------------- |
97
+ | `read` | `schema`, `types`, `state` | `list[ExternalObject]` |
98
+ | `write` | `schema`, `ops`, `state` | `ApplyReport` |
99
+ | `ensure_schema` | `schema` | `ProvisionReport` |
100
+
101
+ `setup` is the `setup:` block from the backend config (parsed json, usually a
102
+ dict); `Adapter.setup` is called once before each request.
103
+
104
+ the model mirrors alembic's ir:
105
+
106
+ - `Op` is `Create`, `Update`, or `Delete` (dispatch with `isinstance`). `Create`
107
+ and `Update` carry the full desired `Object`; `Update` also carries `changes`
108
+ and `backend_id`; `Delete` carries `key` and `backend_id`.
109
+ - `Object` has `uid`, `type_name`, `key`, and `attrs`.
110
+ - `State.backend_id(type_name, uid)` looks up the engine's existing backend id
111
+ for an object, so renames stay stable.
112
+ - `Schema` parses into `TypeSchema` / `FieldSchema` / `FieldType`, so
113
+ schema-driven adapters can, for example, find reference fields via
114
+ `field.type.kind == "ref"` and `field.type.target`.
115
+
116
+ for the full request/response shapes, see alembic's
117
+ [`docs/external-adapters.md`](https://github.com/cyberwitchery/alembic/blob/main/docs/external-adapters.md).
118
+
119
+ ## wiring into alembic
120
+
121
+ point a backend config at your program (see [`examples/backend.yaml`](examples/backend.yaml)):
122
+
123
+ ```yaml
124
+ backend: external
125
+ command: python3
126
+ args: ["examples/example_adapter.py"]
127
+ setup:
128
+ host: http://localhost:8080
129
+ ```
130
+
131
+ ```bash
132
+ alembic plan --backend external --backend-config examples/backend.yaml \
133
+ -f inventory.yaml -o plan.json
134
+ alembic apply --backend external --backend-config examples/backend.yaml \
135
+ -p plan.json
136
+ ```
137
+
138
+ you can also debug the protocol by hand by piping a request into your adapter:
139
+
140
+ ```bash
141
+ echo '{"version":1,"setup":{},"method":"read","schema":{"types":{}},"types":[],"state":{"mappings":{}}}' \
142
+ | python3 examples/example_adapter.py
143
+ ```
144
+
145
+ ## develop
146
+
147
+ ```bash
148
+ pip install -e ".[dev]"
149
+
150
+ # tests
151
+ PYTHONPATH=src python -m unittest discover -s tests
152
+
153
+ # tests with the coverage gate (fails under 100%, matching ci)
154
+ coverage run -m unittest discover -s tests
155
+ coverage report
156
+
157
+ ruff check
158
+ ruff format --check
159
+ ```
160
+
161
+ ## license
162
+
163
+ Apache-2.0
@@ -0,0 +1,141 @@
1
+ # alembic-adapter-sdk (python)
2
+
3
+ a small, dependency-free sdk for writing [alembic](https://github.com/cyberwitchery/alembic)
4
+ external adapters in python.
5
+
6
+ network engineering lives in python, so adapters should be writable there too.
7
+ alembic delegates backend i/o to *external adapters*: standalone programs the
8
+ alembic host spawns as subprocesses, exchanging one json request and one json
9
+ response over stdin/stdout. this sdk handles that protocol so you only write the
10
+ backend logic.
11
+
12
+ the import package is `alembic_adapter`. (the pypi distribution is
13
+ `alembic-adapter-sdk`; the bare name `alembic` belongs to sqlalchemy's migration
14
+ tool and is unrelated.)
15
+
16
+ ## install
17
+
18
+ ```bash
19
+ pip install alembic-adapter-sdk
20
+ ```
21
+
22
+ or, from a checkout:
23
+
24
+ ```bash
25
+ pip install -e .
26
+ ```
27
+
28
+ the sdk has no runtime dependencies; it speaks json with the stdlib.
29
+
30
+ ## writing an adapter
31
+
32
+ subclass `Adapter`, implement the methods your backend needs, and call `run`:
33
+
34
+ ```python
35
+ from alembic_adapter import Adapter, ApplyReport, AppliedOp, Create, run
36
+
37
+ class MyAdapter(Adapter):
38
+ def setup(self, config):
39
+ # `config` is the parsed `setup:` block from the backend config.
40
+ self.host = (config or {}).get("host", "http://localhost:8080")
41
+
42
+ def read(self, schema, types, state):
43
+ # observe backend state -> list[ExternalObject]; the engine diffs it
44
+ # against the desired inventory to build a plan. emit-only adapters
45
+ # return [] (the default).
46
+ return []
47
+
48
+ def write(self, schema, ops, state):
49
+ # apply create/update/delete ops, then report what was applied.
50
+ report = ApplyReport()
51
+ for op in ops:
52
+ if isinstance(op, Create):
53
+ ... # create op.desired on the backend
54
+ report.applied.append(AppliedOp(uid=op.uid, type_name=op.type_name))
55
+ return report
56
+
57
+ if __name__ == "__main__":
58
+ run(MyAdapter())
59
+ ```
60
+
61
+ `run` reads one request from stdin, dispatches it, and writes a
62
+ newline-terminated json response to stdout. any exception your adapter raises is
63
+ turned into a well-formed `{"ok": false, "error": ...}` response.
64
+
65
+ see [`examples/example_adapter.py`](examples/example_adapter.py) for a complete,
66
+ copyable starting point.
67
+
68
+ ## the protocol
69
+
70
+ every request carries `version` (currently `1`) and a `method`. the sdk parses
71
+ the payload into typed objects and serializes your results back:
72
+
73
+ | method | you receive | you return |
74
+ | --------------- | --------------------------------- | ------------------------- |
75
+ | `read` | `schema`, `types`, `state` | `list[ExternalObject]` |
76
+ | `write` | `schema`, `ops`, `state` | `ApplyReport` |
77
+ | `ensure_schema` | `schema` | `ProvisionReport` |
78
+
79
+ `setup` is the `setup:` block from the backend config (parsed json, usually a
80
+ dict); `Adapter.setup` is called once before each request.
81
+
82
+ the model mirrors alembic's ir:
83
+
84
+ - `Op` is `Create`, `Update`, or `Delete` (dispatch with `isinstance`). `Create`
85
+ and `Update` carry the full desired `Object`; `Update` also carries `changes`
86
+ and `backend_id`; `Delete` carries `key` and `backend_id`.
87
+ - `Object` has `uid`, `type_name`, `key`, and `attrs`.
88
+ - `State.backend_id(type_name, uid)` looks up the engine's existing backend id
89
+ for an object, so renames stay stable.
90
+ - `Schema` parses into `TypeSchema` / `FieldSchema` / `FieldType`, so
91
+ schema-driven adapters can, for example, find reference fields via
92
+ `field.type.kind == "ref"` and `field.type.target`.
93
+
94
+ for the full request/response shapes, see alembic's
95
+ [`docs/external-adapters.md`](https://github.com/cyberwitchery/alembic/blob/main/docs/external-adapters.md).
96
+
97
+ ## wiring into alembic
98
+
99
+ point a backend config at your program (see [`examples/backend.yaml`](examples/backend.yaml)):
100
+
101
+ ```yaml
102
+ backend: external
103
+ command: python3
104
+ args: ["examples/example_adapter.py"]
105
+ setup:
106
+ host: http://localhost:8080
107
+ ```
108
+
109
+ ```bash
110
+ alembic plan --backend external --backend-config examples/backend.yaml \
111
+ -f inventory.yaml -o plan.json
112
+ alembic apply --backend external --backend-config examples/backend.yaml \
113
+ -p plan.json
114
+ ```
115
+
116
+ you can also debug the protocol by hand by piping a request into your adapter:
117
+
118
+ ```bash
119
+ echo '{"version":1,"setup":{},"method":"read","schema":{"types":{}},"types":[],"state":{"mappings":{}}}' \
120
+ | python3 examples/example_adapter.py
121
+ ```
122
+
123
+ ## develop
124
+
125
+ ```bash
126
+ pip install -e ".[dev]"
127
+
128
+ # tests
129
+ PYTHONPATH=src python -m unittest discover -s tests
130
+
131
+ # tests with the coverage gate (fails under 100%, matching ci)
132
+ coverage run -m unittest discover -s tests
133
+ coverage report
134
+
135
+ ruff check
136
+ ruff format --check
137
+ ```
138
+
139
+ ## license
140
+
141
+ Apache-2.0
@@ -0,0 +1,23 @@
1
+ # wire this adapter into alembic as an external backend, e.g.:
2
+ #
3
+ # alembic plan --backend external --backend-config examples/backend.yaml \
4
+ # -f inventory.yaml -o plan.json
5
+ # alembic apply --backend external --backend-config examples/backend.yaml \
6
+ # -p plan.json
7
+ #
8
+ backend: external
9
+
10
+ # how alembic launches the adapter. once the package is installed you can also
11
+ # expose a console script and point `command` at that instead.
12
+ command: python3
13
+ args: ["examples/example_adapter.py"]
14
+
15
+ # optional process controls (defaults shown commented out):
16
+ # working_dir: .
17
+ # env:
18
+ # MY_BACKEND_TOKEN: $TOKEN
19
+ # timeout_seconds: 120
20
+
21
+ # the `setup:` block is handed verbatim to Adapter.setup (as parsed JSON).
22
+ setup:
23
+ host: http://localhost:8080