lightweb-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.
Files changed (43) hide show
  1. lightweb_adapter_sdk-0.1.0/.github/workflows/ci.yml +46 -0
  2. lightweb_adapter_sdk-0.1.0/.github/workflows/release.yml +117 -0
  3. lightweb_adapter_sdk-0.1.0/.gitignore +82 -0
  4. lightweb_adapter_sdk-0.1.0/CHANGELOG.md +36 -0
  5. lightweb_adapter_sdk-0.1.0/LICENSE +197 -0
  6. lightweb_adapter_sdk-0.1.0/PKG-INFO +138 -0
  7. lightweb_adapter_sdk-0.1.0/README.md +106 -0
  8. lightweb_adapter_sdk-0.1.0/docs/conformance.md +188 -0
  9. lightweb_adapter_sdk-0.1.0/docs/contract.md +382 -0
  10. lightweb_adapter_sdk-0.1.0/docs/event-consumer.md +199 -0
  11. lightweb_adapter_sdk-0.1.0/docs/examples/round-0-prompt.md +463 -0
  12. lightweb_adapter_sdk-0.1.0/docs/round-prompt-template.md +245 -0
  13. lightweb_adapter_sdk-0.1.0/docs/supervisor-side-edits.md +57 -0
  14. lightweb_adapter_sdk-0.1.0/docs/testkit.md +208 -0
  15. lightweb_adapter_sdk-0.1.0/docs/wrap-procedures.md +97 -0
  16. lightweb_adapter_sdk-0.1.0/pyproject.toml +91 -0
  17. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/__init__.py +0 -0
  18. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/adapter/__init__.py +133 -0
  19. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/__init__.py +94 -0
  20. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/fault_control.py +54 -0
  21. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_apply.py +140 -0
  22. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_capabilities.py +40 -0
  23. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_disable.py +115 -0
  24. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_event_consumer.py +135 -0
  25. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_health.py +52 -0
  26. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_identity_mapping.py +75 -0
  27. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_list_accounts.py +114 -0
  28. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/conformance/test_reconcile.py +148 -0
  29. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/event_consumer/__init__.py +19 -0
  30. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/event_consumer/dedup.py +77 -0
  31. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/event_consumer/jetstream.py +262 -0
  32. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/event_consumer/parser.py +94 -0
  33. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/event_consumer/protocol.py +48 -0
  34. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/py.typed +0 -0
  35. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/reference/__init__.py +330 -0
  36. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/reference/event_consumer.py +50 -0
  37. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/reference/fake_server.py +147 -0
  38. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/reference/fault_control.py +36 -0
  39. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/testkit/__init__.py +35 -0
  40. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/testkit/fake_entitlements.py +115 -0
  41. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/testkit/fake_event_source.py +132 -0
  42. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/testkit/structural.py +64 -0
  43. lightweb_adapter_sdk-0.1.0/src/lightweb_adapter_sdk/types/__init__.py +416 -0
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ check:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.12", "3.13"]
15
+
16
+ steps:
17
+ - name: Checkout
18
+ uses: actions/checkout@v4
19
+ with:
20
+ fetch-depth: 0
21
+
22
+ - name: Set up uv
23
+ uses: astral-sh/setup-uv@v5
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+
27
+ - name: Install dependencies
28
+ run: make install
29
+
30
+ - name: Type check
31
+ run: make typecheck
32
+
33
+ - name: Lint
34
+ run: make lint
35
+
36
+ - name: Format check
37
+ run: make format-check
38
+
39
+ - name: Unit tests
40
+ run: make test-unit
41
+
42
+ - name: Conformance tests
43
+ run: make test-conformance
44
+
45
+ - name: Conformance independence check
46
+ run: make test-conformance-independence
@@ -0,0 +1,117 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*.*.*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
20
+
21
+ - name: Set up uv
22
+ uses: astral-sh/setup-uv@v5
23
+ with:
24
+ python-version: "3.12"
25
+
26
+ - name: Install build dependencies
27
+ run: uv pip install -e ".[dev]"
28
+
29
+ - name: Build wheel and sdist
30
+ run: make build
31
+
32
+ - name: Verify version matches tag
33
+ shell: python
34
+ run: |
35
+ import re
36
+ import sys
37
+ from pathlib import Path
38
+
39
+ tag = "${{ github.ref_name }}"
40
+ tag_version = tag.lstrip("v")
41
+
42
+ dist = Path("dist")
43
+ wheel_files = list(dist.glob("lightweb_adapter_sdk-*.whl"))
44
+ sdist_files = list(dist.glob("lightweb_adapter_sdk-*.tar.gz"))
45
+
46
+ if not wheel_files or not sdist_files:
47
+ print("ERROR: No wheel or sdist found in dist/")
48
+ sys.exit(1)
49
+
50
+ wheel_name = wheel_files[0].stem
51
+ sdist_name = sdist_files[0].stem
52
+
53
+ wheel_version = re.match(r"lightweb_adapter_sdk-(.+)", wheel_name).group(1)
54
+ sdist_version = re.match(r"lightweb_adapter_sdk-(.+)", sdist_name).group(1)
55
+
56
+ if wheel_version != sdist_version:
57
+ print(f"ERROR: Wheel version ({wheel_version}) != sdist version ({sdist_version})")
58
+ sys.exit(1)
59
+
60
+ if wheel_version != tag_version:
61
+ print(f"ERROR: Built version ({wheel_version}) != tag ({tag_version})")
62
+ sys.exit(1)
63
+
64
+ - name: Run CI checks
65
+ run: |
66
+ uv pip install -e ".[dev]"
67
+ make typecheck
68
+ make lint
69
+ make format-check
70
+ make test
71
+ make test-conformance
72
+ make test-conformance-independence
73
+
74
+ - name: Upload artifacts
75
+ uses: actions/upload-artifact@v4
76
+ with:
77
+ name: dist
78
+ path: dist/
79
+ retention-days: 5
80
+
81
+ publish-testpypi:
82
+ needs: [build]
83
+ runs-on: ubuntu-latest
84
+ if: contains(github.ref_name, 'rc')
85
+ environment: testpypi
86
+ permissions:
87
+ id-token: write
88
+
89
+ steps:
90
+ - name: Download artifacts
91
+ uses: actions/download-artifact@v4
92
+ with:
93
+ name: dist
94
+ path: dist/
95
+
96
+ - name: Publish to Test PyPI
97
+ uses: pypa/gh-action-pypi-publish@release/v1
98
+ with:
99
+ repository-url: https://test.pypi.org/legacy/
100
+
101
+ publish-pypi:
102
+ needs: [build]
103
+ runs-on: ubuntu-latest
104
+ if: ${{ !contains(github.ref_name, 'rc') }}
105
+ environment: pypi
106
+ permissions:
107
+ id-token: write
108
+
109
+ steps:
110
+ - name: Download artifacts
111
+ uses: actions/download-artifact@v4
112
+ with:
113
+ name: dist
114
+ path: dist/
115
+
116
+ - name: Publish to PyPI
117
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,82 @@
1
+ # Session state (per workflow described in CLAUDE.md)
2
+ .claude/
3
+ decisions-log/
4
+
5
+ # OpenCode session state
6
+ .opencode/
7
+
8
+ # Local round-prompt staging
9
+ prompts/
10
+
11
+ # Python build artifacts
12
+ __pycache__/
13
+ *.py[cod]
14
+ *$py.class
15
+ *.so
16
+ .Python
17
+ build/
18
+ develop-eggs/
19
+ dist/
20
+ downloads/
21
+ eggs/
22
+ .eggs/
23
+ lib/
24
+ lib64/
25
+ parts/
26
+ sdist/
27
+ var/
28
+ wheels/
29
+ share/python-wheels/
30
+ *.egg-info/
31
+ .installed.cfg
32
+ *.egg
33
+ MANIFEST
34
+
35
+ # Virtual environments
36
+ .venv/
37
+ venv/
38
+ env/
39
+ ENV/
40
+ env.bak/
41
+ venv.bak/
42
+
43
+ # uv
44
+ .uv/
45
+ uv.lock
46
+
47
+ # Type checkers
48
+ .mypy_cache/
49
+ .dmypy.json
50
+ dmypy.json
51
+ .pyre/
52
+ .pytype/
53
+
54
+ # Test artifacts
55
+ .pytest_cache/
56
+ .hypothesis/
57
+ .coverage
58
+ .coverage.*
59
+ htmlcov/
60
+ .tox/
61
+ .nox/
62
+ coverage.xml
63
+ *.cover
64
+ *.py,cover
65
+ .cache
66
+
67
+ # ruff
68
+ .ruff_cache/
69
+
70
+ # Editors and OS
71
+ .idea/
72
+ .vscode/
73
+ *.swp
74
+ *.swo
75
+ *~
76
+ .DS_Store
77
+ Thumbs.db
78
+
79
+ # Local environment overrides
80
+ .env
81
+ .env.local
82
+ *.local
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to the Lightweb adapter SDK are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See [`CONVENTIONS.md`](CONVENTIONS.md) §1 for the SDK's specific versioning discipline, including what counts as a breaking change.
6
+
7
+ Breaking changes are flagged with `**BREAKING:**` at the start of the entry, even within their category.
8
+
9
+ The SDK is in 0.x until its contract has been validated by at least one production adapter. Per [`CONVENTIONS.md`](CONVENTIONS.md) §1.3, breaking changes may land in minor (0.X → 0.(X+1)) releases while in 0.x; pin against a specific minor version.
10
+
11
+ ## [Unreleased]
12
+
13
+ ## [0.1.0] - 2026-05-19
14
+
15
+ ### Changed
16
+
17
+ - Conformance suite is now fully adapter-agnostic: conformance tests no longer import from `lightweb_adapter_sdk.reference`. State inspection uses `list_accounts()` instead of `get_account()`. Fault injection uses the `FaultControl` Protocol instead of `FakeExampleAppServer.set_unreachable()`.
18
+ - `ExampleAppUnreachable` now inherits from `AdapterUnreachable` to maintain compatibility with conformance assertions on the base type.
19
+
20
+ ### Changed (BREAKING)
21
+
22
+ - `EventEnvelope.event_type` semantics: now follows the pattern `entitlements.<entity>.<verb>` (matching what the platform emits), not `entitlements.<app>.<verb>`. The class shape is unchanged; the docstring and parsing logic differ.
23
+ - `EventEnvelope.member_id` source: now extracted from the platform envelope's `data.member_id` field, not from `subject.id`. The class shape is unchanged.
24
+
25
+ ### Removed (BREAKING)
26
+
27
+ - `app_from_event_type(event_type: str) -> str` — helper's premise was incorrect (assumed app name in middle segment of event_type; in reality, middle segment is the entity type). No replacement; adapters know their own app and do not extract it from events.
28
+
29
+ ### Added
30
+
31
+ - `AdapterUnreachable` exception in `lightweb_adapter_sdk.types` — a base exception type for target-app unreachability. Adapter authors should raise this or a subclass when their adapter detects the target app is unreachable.
32
+ - `FaultControl` Protocol in `lightweb_adapter_sdk.conformance.fault_control` — defines the interface for fault injection in conformance tests (`inject_unreachable`, `inject_rate_limit`, `inject_auth_failure`, `reset`).
33
+ - `ReferenceFaultControl` in `lightweb_adapter_sdk.reference.fault_control` — reference implementation of `FaultControl` for the example adapter.
34
+ - `is_entitlement_change_event(env: EventEnvelope) -> bool` — returns `True` for the curated set of event types that trigger member-state-changing entitlement re-derivation. Adapter consumers use this to filter events that warrant a re-apply, ignoring informational events like `app_account.created` and `feature_key.registry_reloaded`.
35
+ - PEP 561 `py.typed` marker. Downstream consumers' type checkers will now pick up SDK type annotations.
36
+ - `nats-py >= 2.6` declared as runtime dependency for `JetStreamEventConsumer`. (The dependency was used at runtime by `JetStreamEventConsumer` since Round 4 began but was not declared in `pyproject.toml`; declaration was missed during the contract-reshape work. No API change.)
@@ -0,0 +1,197 @@
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 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 to
50
+ that Work or Derivative Works thereof, that is intentionally submitted
51
+ to Licensor for inclusion in the Work by the copyright owner or by an
52
+ individual or Legal Entity authorized to submit on behalf of the
53
+ copyright owner. For the purposes of this definition, "submitted" means
54
+ any form of electronic, verbal, or written communication sent to the
55
+ 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 Work
71
+ and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of this
74
+ License, each Contributor hereby grants to You a perpetual, worldwide,
75
+ non-exclusive, no-charge, royalty-free, irrevocable (except as stated
76
+ in this section) patent license to make, have made, use, offer to sell,
77
+ sell, import, and otherwise transfer the Work, where such license
78
+ applies only to those patent claims licensable by such Contributor that
79
+ are necessarily infringed by their Contribution(s) alone or by
80
+ combination of their Contribution(s) with the Work to which such
81
+ Contribution(s) was submitted. If You institute patent litigation
82
+ against any entity (including a cross-claim or counterclaim in a
83
+ lawsuit) alleging that the Work or a Contribution incorporated within
84
+ the Work constitutes direct or contributory patent infringement, then
85
+ any patent licenses granted to You under this License for that Work
86
+ shall terminate as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the Work
89
+ or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You meet the
91
+ following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or Derivative
94
+ Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works that
100
+ You distribute, all copyright, patent, trademark, and attribution
101
+ notices from the Source form of the Work, excluding those notices
102
+ that do not pertain to any part of the Derivative Works; and
103
+
104
+ (d) If the Work includes a "NOTICE" text file as part of its
105
+ distribution, then any Derivative Works that You distribute must
106
+ include a readable copy of the attribution notices contained within
107
+ such NOTICE file, excluding those notices that do not pertain to any
108
+ part of the Derivative Works, in at least one of the following
109
+ places: within a NOTICE text file distributed as part of the
110
+ Derivative Works; within the Source form or documentation, if
111
+ provided along with the Derivative Works; or, within a display
112
+ generated by the Derivative Works, if and wherever such third-party
113
+ notices normally appear. The contents of the NOTICE file are for
114
+ informational purposes only and do not modify the License. You may
115
+ add Your own attribution notices within Derivative Works that You
116
+ distribute, alongside or as an addendum to the NOTICE text from the
117
+ Work, provided that such additional attribution notices cannot be
118
+ construed as modifying the License.
119
+
120
+ You may add Your own copyright statement to Your modifications and may
121
+ provide additional or different license terms and conditions for use,
122
+ reproduction, or distribution of Your modifications, or for any such
123
+ Derivative Works as a whole, provided Your use, reproduction, and
124
+ distribution of the Work otherwise complies with the conditions stated
125
+ in this License.
126
+
127
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
128
+ any Contribution intentionally submitted for inclusion in the Work by
129
+ You to the Licensor shall be under the terms and conditions of this
130
+ License, without any additional terms or conditions. Notwithstanding the
131
+ above, nothing herein shall supersede or modify the terms of any
132
+ separate license agreement you may have executed with the Licensor
133
+ regarding such Contributions.
134
+
135
+ 6. Trademarks. This License does not grant permission to use the trade
136
+ names, trademarks, service marks, or product names of the Licensor,
137
+ except as required for reasonable and customary use in describing the
138
+ origin of the Work and reproducing the content of the NOTICE file.
139
+
140
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
141
+ to in writing, Licensor provides the Work (and each Contributor
142
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR
143
+ CONDITIONS OF ANY KIND, either express or implied, including, without
144
+ limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
145
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
146
+ responsible for determining the appropriateness of using or
147
+ redistributing the Work and assume any risks associated with Your
148
+ exercise of permissions under this License.
149
+
150
+ 8. Limitation of Liability. In no event and under no legal theory,
151
+ whether in tort (including negligence), contract, or otherwise, unless
152
+ required by applicable law (such as deliberate and grossly negligent
153
+ acts) or agreed to in writing, shall any Contributor be liable to You
154
+ for damages, including any direct, indirect, special, incidental, or
155
+ consequential damages of any character arising as a result of this
156
+ License or out of the use or inability to use the Work (including but
157
+ not limited to damages for loss of goodwill, work stoppage, computer
158
+ failure or malfunction, or any and all other commercial damages or
159
+ losses), even if such Contributor has been advised of the possibility
160
+ of such damages.
161
+
162
+ 9. Accepting Warranty or Additional Liability. While redistributing the
163
+ Work or Derivative Works thereof, You may choose to offer, and charge a
164
+ fee for, acceptance of support, warranty, indemnity, or other liability
165
+ obligations and/or rights consistent with this License. However, in
166
+ accepting such obligations, You may act only on Your own behalf and on
167
+ Your sole responsibility, not on behalf of any other Contributor, and
168
+ only if You agree to indemnify, defend, and hold each Contributor
169
+ harmless for any liability incurred by, or claims asserted against, such
170
+ Contributor by reason of your accepting any such warranty or additional
171
+ liability.
172
+
173
+ END OF TERMS AND CONDITIONS
174
+
175
+ APPENDIX: How to apply the Apache License to your work.
176
+
177
+ To apply the Apache License to your work, attach the following
178
+ boilerplate notice, with the fields enclosed by brackets "[]"
179
+ replaced with your own identifying information. (Don't include the
180
+ brackets!) The text should be enclosed in the appropriate comment
181
+ syntax for the file format. We also recommend that a file or class name
182
+ and description of purpose be included on the same "printed page" as the
183
+ copyright notice for easier identification within third-party archives.
184
+
185
+ Copyright 2025 Lightweb
186
+
187
+ Licensed under the Apache License, Version 2.0 (the "License");
188
+ you may not use this file except in compliance with the License.
189
+ You may obtain a copy of the License at
190
+
191
+ http://www.apache.org/licenses/LICENSE-2.0
192
+
193
+ Unless required by applicable law or agreed to in writing, software
194
+ distributed under the License is distributed on an "AS IS" BASIS,
195
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
196
+ See the License for the specific language governing permissions and
197
+ limitations under the License.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: lightweb-adapter-sdk
3
+ Version: 0.1.0
4
+ Summary: Published Python SDK for the Lightweb adapter contract
5
+ Project-URL: Homepage, https://github.com/lightweb/adapter-sdk
6
+ Project-URL: Repository, https://github.com/lightweb/adapter-sdk
7
+ Project-URL: Issues, https://github.com/lightweb/adapter-sdk/issues
8
+ Project-URL: Changelog, https://github.com/lightweb/adapter-sdk/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/lightweb/adapter-sdk/docs
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: adapter,contract,entitlements,lightweb,provisioning
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: nats-py>=2.6
24
+ Requires-Dist: pydantic>=2.0
25
+ Requires-Dist: pytest-asyncio>=0.23
26
+ Requires-Dist: pytest>=8.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: hypothesis; extra == 'dev'
29
+ Requires-Dist: mypy; extra == 'dev'
30
+ Requires-Dist: ruff; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Lightweb adapter SDK
34
+
35
+ The published Python SDK for the Lightweb adapter contract.
36
+
37
+ > **Status: pre-1.0, under active development.** The SDK is not yet released to PyPI. The first 0.1.0 release will follow once initial implementation rounds are complete. See [`CHANGELOG.md`](CHANGELOG.md) for release history.
38
+
39
+ ## What this is
40
+
41
+ [Lightweb](https://github.com/lightweb/platform) is a community-owned, deployable platform template for hosting self-hosted alternatives to common web services — files, chat, code, meetings. The platform separates *what a member is entitled to* (the entitlements service, source of truth) from *how those entitlements are provisioned into specific apps* (one adapter per app: NextCloud, Matrix, Gitea, Jitsi, and others).
42
+
43
+ This SDK publishes the contract those adapters implement. It's six methods, a handful of shared types, an event envelope, and a conformance suite that every adapter is expected to pass.
44
+
45
+ If you want to build an adapter for a new app, this is the library you depend on. If you want to understand how the platform's adapter layer works without writing one, [`docs/contract.md`](docs/contract.md) is the canonical specification.
46
+
47
+ ## The contract, briefly
48
+
49
+ Every adapter implements six methods:
50
+
51
+ - `capabilities()` — declares which feature keys this adapter handles and what enforcement it offers.
52
+ - `apply(member, entitlements)` — idempotent; makes the target app's state match the desired entitlements.
53
+ - `disable(member)` — soft-disable; blocks access while preserving data.
54
+ - `reconcile(member, entitlements)` — read-only; returns a drift report comparing app state to desired state.
55
+ - `health()` — the adapter and its target app are reachable.
56
+ - `list_accounts(cursor)` — optional; pages through every account in the app for whole-system reconciliation.
57
+
58
+ There is no `delete`. Deletion is destructive, asymmetric, and out of the contract by design; it's handled separately as a gated, human-approved workflow in the platform's reconciler.
59
+
60
+ The full specification is in [`docs/contract.md`](docs/contract.md).
61
+
62
+ ## Quick start
63
+
64
+ Install:
65
+
66
+ ```bash
67
+ pip install lightweb-adapter-sdk
68
+ ```
69
+
70
+ A minimal adapter:
71
+
72
+ ```python
73
+ from lightweb_adapter_sdk.adapter import Adapter
74
+ from lightweb_adapter_sdk.types import (
75
+ Member, Entitlement, AppAccount, DriftReport,
76
+ Capabilities, HealthStatus, AccountListPage,
77
+ )
78
+
79
+
80
+ class MyAdapter:
81
+ """Adapter for MyApp."""
82
+
83
+ def capabilities(self) -> Capabilities:
84
+ ...
85
+
86
+ def apply(self, member: Member, entitlements: list[Entitlement]) -> AppAccount:
87
+ ...
88
+
89
+ def disable(self, member: Member) -> None:
90
+ ...
91
+
92
+ def reconcile(self, member: Member) -> DriftReport:
93
+ ...
94
+
95
+ def health(self) -> HealthStatus:
96
+ ...
97
+
98
+ def list_accounts(self, cursor: str | None = None) -> AccountListPage:
99
+ ...
100
+
101
+
102
+ # Verify the adapter satisfies the contract structurally:
103
+ adapter: Adapter = MyAdapter()
104
+ ```
105
+
106
+ The `Adapter` is a `typing.Protocol`; your class doesn't have to inherit from it. If it has the right method signatures, it satisfies the contract.
107
+
108
+ The conformance suite verifies your adapter meets the contract's *behavioral* requirements (not just its structural ones). See [`docs/conformance.md`](docs/conformance.md) for how to run it against your adapter.
109
+
110
+ ## Documentation
111
+
112
+ - [`docs/contract.md`](docs/contract.md) — the canonical contract specification. The authority on what an adapter must do.
113
+ - [`docs/conformance.md`](docs/conformance.md) — how to wire the conformance suite into your adapter's CI.
114
+ - [`docs/event-consumer.md`](docs/event-consumer.md) — JetStream event consumer conventions.
115
+ - [`docs/testkit.md`](docs/testkit.md) — the testkit for adapter authors.
116
+ - [`ARCHITECTURE.md`](ARCHITECTURE.md) — repository orientation; what's where and why.
117
+
118
+ For the broader architectural context — *why* the adapter contract exists in this shape — see the Lightweb HLD in the platform monorepo at `lightweb/platform`'s `docs/hld.md`, especially §4.
119
+
120
+ ## Status
121
+
122
+ The SDK is pre-1.0. The current implementation is structured as a sequence of rounds, with Round 5 targeting the first 0.1.0 release. 1.0 follows once the contract has been validated by at least one production adapter.
123
+
124
+ ## Relationship to the Lightweb platform
125
+
126
+ The platform monorepo (`lightweb/platform`) is AGPLv3 and contains the bespoke spine services and first-party adapters that ship with Lightweb. The platform's first-party adapters consume this SDK the same way third-party adapters do — as a pinned PyPI dependency, not as a source-level inclusion.
127
+
128
+ This SDK is Apache 2.0. The license boundary is structural: the SDK is the *contract* third parties implement against, and a permissive license is appropriate for a contract definition.
129
+
130
+ The SDK has no code-level dependency on the platform monorepo. It does mirror some platform-side artifacts (event envelope schemas, the entitlements service's API shape), but those are vendored as generated bindings, not pulled dynamically.
131
+
132
+ ## License
133
+
134
+ Apache License 2.0. See [`LICENSE`](LICENSE) for the full text.
135
+
136
+ ## Code of conduct
137
+
138
+ Project participants are expected to follow the [Contributor Covenant](https://www.contributor-covenant.org/).