cognee-connectors-core 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 (30) hide show
  1. cognee_connectors_core-0.1.0/.gitignore +111 -0
  2. cognee_connectors_core-0.1.0/LICENSE +201 -0
  3. cognee_connectors_core-0.1.0/PKG-INFO +233 -0
  4. cognee_connectors_core-0.1.0/README.md +200 -0
  5. cognee_connectors_core-0.1.0/cognee_connectors_core/__init__.py +101 -0
  6. cognee_connectors_core-0.1.0/cognee_connectors_core/base.py +768 -0
  7. cognee_connectors_core-0.1.0/cognee_connectors_core/descriptor.py +531 -0
  8. cognee_connectors_core-0.1.0/cognee_connectors_core/dlt_conventions.py +203 -0
  9. cognee_connectors_core-0.1.0/cognee_connectors_core/errors.py +49 -0
  10. cognee_connectors_core-0.1.0/cognee_connectors_core/http.py +130 -0
  11. cognee_connectors_core-0.1.0/cognee_connectors_core/oauth2.py +812 -0
  12. cognee_connectors_core-0.1.0/cognee_connectors_core/oauth_state.py +108 -0
  13. cognee_connectors_core-0.1.0/cognee_connectors_core/py.typed +0 -0
  14. cognee_connectors_core-0.1.0/cognee_connectors_core/registry.py +402 -0
  15. cognee_connectors_core-0.1.0/cognee_connectors_core/settings.py +62 -0
  16. cognee_connectors_core-0.1.0/cognee_connectors_core/signatures.py +339 -0
  17. cognee_connectors_core-0.1.0/cognee_connectors_core/testing.py +237 -0
  18. cognee_connectors_core-0.1.0/pyproject.toml +101 -0
  19. cognee_connectors_core-0.1.0/tests/conftest.py +20 -0
  20. cognee_connectors_core-0.1.0/tests/test_base.py +308 -0
  21. cognee_connectors_core-0.1.0/tests/test_descriptor.py +600 -0
  22. cognee_connectors_core-0.1.0/tests/test_dlt_conventions.py +243 -0
  23. cognee_connectors_core-0.1.0/tests/test_http.py +249 -0
  24. cognee_connectors_core-0.1.0/tests/test_oauth2.py +1291 -0
  25. cognee_connectors_core-0.1.0/tests/test_oauth_state.py +197 -0
  26. cognee_connectors_core-0.1.0/tests/test_package.py +62 -0
  27. cognee_connectors_core-0.1.0/tests/test_registry.py +448 -0
  28. cognee_connectors_core-0.1.0/tests/test_settings.py +86 -0
  29. cognee_connectors_core-0.1.0/tests/test_signatures.py +588 -0
  30. cognee_connectors_core-0.1.0/tests/test_testing.py +245 -0
@@ -0,0 +1,111 @@
1
+ # Environment files: .env.template is tracked, real credentials never are.
2
+ .env
3
+ .env.local
4
+ .local.env
5
+ .prod.env
6
+
7
+ # cognee data written by local runs and the tests
8
+ .data
9
+ .data_storage/
10
+ .cognee_system/
11
+ .cognee_cache/
12
+ .cognee/
13
+ *.lance/
14
+ logs/
15
+
16
+ # Test output files
17
+ test_outputs/
18
+ .artifacts/
19
+ .anon_id
20
+
21
+ # Byte-compiled / optimized / DLL files
22
+ __pycache__/
23
+ *.py[cod]
24
+ *$py.class
25
+
26
+ # C extensions
27
+ *.so
28
+
29
+ # Distribution / packaging
30
+ .Python
31
+ build/
32
+ develop-eggs/
33
+ dist/
34
+ downloads/
35
+ eggs/
36
+ .eggs/
37
+ lib/
38
+ lib64/
39
+ parts/
40
+ sdist/
41
+ var/
42
+ wheels/
43
+ share/python-wheels/
44
+ *.egg-info/
45
+ .installed.cfg
46
+ *.egg
47
+ MANIFEST
48
+
49
+ # PyInstaller
50
+ *.manifest
51
+ *.spec
52
+
53
+ # Installer logs
54
+ pip-log.txt
55
+ pip-delete-this-directory.txt
56
+
57
+ # Unit test / coverage reports
58
+ htmlcov/
59
+ .tox/
60
+ .nox/
61
+ .coverage
62
+ .coverage.*
63
+ .cache
64
+ nosetests.xml
65
+ coverage.xml
66
+ *.cover
67
+ *.py,cover
68
+ .hypothesis/
69
+ .pytest_cache/
70
+ cover/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # IPython
76
+ profile_default/
77
+ ipython_config.py
78
+
79
+ # Environments (uv). `.venv-clean` is the cognee-free venv of the clean-install check.
80
+ # `.python-version` is tracked on purpose: it pins the interpreter uv picks.
81
+ .venv
82
+ .venv-*
83
+ env/
84
+ venv/
85
+ ENV/
86
+ env.bak/
87
+ venv.bak/
88
+ mise.toml
89
+
90
+ # Ruff
91
+ .ruff_cache/
92
+
93
+ # mypy / ty
94
+ .mypy_cache/
95
+ .dmypy.json
96
+ dmypy.json
97
+
98
+ # PyCharm / VS Code
99
+ .idea/
100
+ .vscode/
101
+
102
+ # OS
103
+ .DS_Store
104
+
105
+ # enola code-graph snapshots (written into any repository enola scans)
106
+ .enola/
107
+
108
+ # PyPI configuration
109
+ .pypirc
110
+
111
+ node_modules/
@@ -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 2024 Topoteretes UG
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,233 @@
1
+ Metadata-Version: 2.5
2
+ Name: cognee-connectors-core
3
+ Version: 0.1.0
4
+ Summary: The contract every cognee connector implements: OAuth2 descriptors, webhook verification, DLT conventions and the registry hosts load connectors through.
5
+ Project-URL: Homepage, https://github.com/topoteretes/cognee/tree/main/cognee-connectors/core
6
+ Project-URL: Repository, https://github.com/topoteretes/cognee
7
+ Project-URL: Issues, https://github.com/topoteretes/cognee/issues
8
+ Project-URL: Documentation, https://docs.cognee.ai
9
+ Author: Cognee team
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ai-memory,cognee,connector,dlt,oauth2,webhooks
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: MacOS :: MacOS X
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Software Development :: Libraries
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Requires-Python: <3.15,>=3.10
28
+ Requires-Dist: aiohttp<4.0.0,>=3.13.5
29
+ Requires-Dist: pydantic-settings!=2.12.*,!=2.13.*,!=2.14.0,!=2.14.1,<3,>=2.7.0
30
+ Provides-Extra: dlt
31
+ Requires-Dist: dlt<1.31,>=1.9.0; extra == 'dlt'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # cognee-connectors-core
35
+
36
+ The contract every cognee connector implements, with no host in it. A connector
37
+ package (`cognee-connector-<provider>`) depends on this package and on its vendor
38
+ SDK; the hosts — cognee's own server and SDK, cloud-backend — depend on it to find
39
+ and drive the connectors. `cognee` itself is never a runtime dependency of this
40
+ package: everything here imports with cognee absent.
41
+
42
+ ```bash
43
+ pip install cognee-connectors-core # the contract
44
+ pip install "cognee-connectors-core[dlt]" # plus the dlt range connectors with a DLT source pin
45
+ ```
46
+
47
+ Python 3.10 – 3.14. Apache-2.0.
48
+
49
+ ## Modules
50
+
51
+ | Module | What it owns |
52
+ | --- | --- |
53
+ | `cognee_connectors_core.base` | `Connector` (the abstract contract), `ConnectorInstallation`, `SyncScope`, `ConnectorResource`, `WebhookDispatch`, `RefreshedTokens`, `WebhookVerifier`, the `Credential` protocol, `account_slug`, `dataset_name_for` |
54
+ | `cognee_connectors_core.descriptor` | `ConnectorDescriptor`, a Tier 1 connector expressed as data, plus `resolve_path` and `payload_paths` |
55
+ | `cognee_connectors_core.oauth2` | `DescriptorConnector`, which turns a descriptor into a working connector: authorize URL, code exchange, installation parsing, refresh, webhook verification and handling, and the `resolve_account` hook for Tier 2 |
56
+ | `cognee_connectors_core.signatures` | The webhook HMAC schemes (`SHA256_PREFIX`, `BARE_HEX`, `SLACK_V0`, `TIMESTAMPED`) and `HmacVerifier` |
57
+ | `cognee_connectors_core.oauth_state` | Provider-agnostic OAuth `state` minting and validation (`make_state`, `validate_state`) |
58
+ | `cognee_connectors_core.settings` | `ConnectorSettings`, the pydantic-settings base every provider settings class subclasses, and `require` |
59
+ | `cognee_connectors_core.dlt_conventions` | The attribute and column names cognee's ingestion reads off a DLT source (`cognee_document_source`, `cognee_pipeline_scope`, `cognee_node_set`, `cognee_structure`) and the helpers around them |
60
+ | `cognee_connectors_core.registry` | `use_connector`, `get_connector`, `find_connector`, `catalog()` and the entry-point loaders |
61
+ | `cognee_connectors_core.http` | The two-method `HttpClient` protocol and its aiohttp default |
62
+ | `cognee_connectors_core.errors` | `ConnectorError`, `WebhookVerificationError`, `RateLimitedError` |
63
+ | `cognee_connectors_core.testing` | `FakeHttpClient`, `FakeSettings`, `FakeCredential`, `sign_body`, `webhook_headers` |
64
+
65
+ The design, the three tiers and the rules every package follows are in
66
+ [`docs/ARCHITECTURE.md`](../docs/ARCHITECTURE.md) at the repo root.
67
+
68
+ ## How a host uses the loaders
69
+
70
+ Connector packages advertise themselves through three entry-point groups; a host
71
+ never imports a provider by name.
72
+
73
+ ```python
74
+ from cognee_connectors_core import registry
75
+
76
+ # Group "cognee.connectors": {provider: Connector}, each one registered.
77
+ connectors = registry.load_connectors()
78
+ # Group "cognee.sources": {name: source factory}; nothing is called.
79
+ sources = registry.load_sources()
80
+ # Group "cognee.integrations": calls each package's register(); the names that ran.
81
+ registered = registry.load_host_registrations()
82
+
83
+ # KeyError for an unknown provider, which a host answers with 404.
84
+ connector = registry.get_connector("notion")
85
+ # provider, display_name, auth, tier, has_webhooks, supports_resource_selection, ...
86
+ for entry in registry.catalog():
87
+ print(entry["provider"], entry["auth"], entry["has_webhooks"])
88
+ ```
89
+
90
+ Each entry point is loaded on its own: a package that fails to import is logged
91
+ and skipped, so one broken connector cannot hide the others. A host that already
92
+ knows its connectors registers them directly with `registry.use_connector(CONNECTOR)`.
93
+
94
+ The host owns everything the contract leaves out: credential storage and
95
+ encryption, the OAuth routes (minting `state` with `oauth_state.make_state` and
96
+ checking it with `validate_state`), webhook delivery dedupe (claim
97
+ `WebhookDispatch.delivery_id`, or `connector.webhook_delivery_key(body, headers)`
98
+ before calling `handle_webhook`), and running a sync. Token material reaches a
99
+ connector only as the decrypted `tokens` mapping the host passes in.
100
+
101
+ ## How a connector author uses `DescriptorConnector`
102
+
103
+ A Tier 1 provider is a descriptor, a settings class and nothing else:
104
+
105
+ ```python
106
+ from pydantic_settings import SettingsConfigDict
107
+
108
+ from cognee_connectors_core import (
109
+ ConnectorDescriptor,
110
+ ConnectorSettings,
111
+ DescriptorConnector,
112
+ SignatureScheme,
113
+ )
114
+
115
+
116
+ class LinearSettings(ConnectorSettings):
117
+ model_config = SettingsConfigDict(env_prefix="LINEAR_", extra="ignore")
118
+ webhook_secret: str = "" # LINEAR_WEBHOOK_SECRET
119
+
120
+
121
+ DESCRIPTOR = ConnectorDescriptor(
122
+ provider="linear",
123
+ display_name="Linear",
124
+ authorize_url="https://linear.app/oauth/authorize",
125
+ token_url="https://api.linear.app/oauth/token",
126
+ scopes="read",
127
+ authorize_params=(("response_type", "code"), ("actor", "app")),
128
+ account_id_path="organization.id",
129
+ account_label_path="organization.name",
130
+ signature_scheme=SignatureScheme.BARE_HEX,
131
+ signature_header="linear-signature",
132
+ webhook_account_id_path="organizationId",
133
+ webhook_delivery_id_path="webhookId",
134
+ )
135
+
136
+ CONNECTOR = DescriptorConnector(DESCRIPTOR, LinearSettings())
137
+ ```
138
+
139
+ `DescriptorConnector` then implements the whole `Connector` contract:
140
+ `authorize_url(state)`, `exchange_callback(code, params)`,
141
+ `parse_installation(account_data)`, `refresh(credential, tokens)`,
142
+ `webhook_verifier()`, `handle_webhook(raw_body, headers)`,
143
+ `webhook_delivery_key(raw_body, headers)`, `sync_scope(credential, tokens,
144
+ resources=...)`, `dataset_name(credential)`, polling and `content_type`.
145
+ Settings are read at call time, so a value rotated on the settings object takes
146
+ effect on the next request; a missing one raises `RuntimeError` naming the
147
+ environment variable (`LINEAR_CLIENT_ID is not configured`).
148
+
149
+ A Tier 2 provider, whose token response does not say which account authorized,
150
+ subclasses it and overrides one hook:
151
+
152
+ ```python
153
+ class LinearConnector(DescriptorConnector):
154
+ async def resolve_account(self, token_response):
155
+ status, body = await self.http.get_json(
156
+ "https://api.linear.app/graphql?query=...",
157
+ {"Authorization": f"Bearer {token_response['access_token']}"},
158
+ )
159
+ # Merged over the token response; account_id_path then reads organization.id.
160
+ return {"organization": body["data"]["viewer"]["organization"]}
161
+ ```
162
+
163
+ An API-key or local provider is a descriptor with `auth="api_key"` or
164
+ `auth="local"`; the OAuth fields may stay empty and the OAuth members raise
165
+ `NotImplementedError`, while the provider still has a name, a dataset, a
166
+ content type and a catalog entry. A provider whose auth model is not OAuth2 at all
167
+ (GitHub Apps) subclasses `Connector` directly.
168
+
169
+ Webhook verification is a scheme, not code: `HmacVerifier` verifies over the raw
170
+ bytes, in constant time, and refuses with `WebhookVerificationError` carrying the
171
+ status a host should answer with (`401`, `413` over `MAX_BODY_BYTES`). Header
172
+ names are matched case-insensitively.
173
+
174
+ ### Testing a connector
175
+
176
+ ```python
177
+ from cognee_connectors_core.testing import FakeHttpClient, FakeSettings, webhook_headers
178
+
179
+ token_response = {"access_token": "tok", "organization": {"id": "org-1"}}
180
+ http = FakeHttpClient({("POST", DESCRIPTOR.token_url): (200, token_response)})
181
+ connector = DescriptorConnector(DESCRIPTOR, FakeSettings(webhook_secret="s3"), http)
182
+
183
+ account_data = await connector.exchange_callback("code", {})
184
+ installation = connector.parse_installation(account_data)
185
+ assert installation.provider_account_id == "org-1"
186
+ assert http.last_call.data["grant_type"] == "authorization_code"
187
+
188
+ body = b'{"organizationId": "org-1", "webhookId": "d1"}'
189
+ headers = webhook_headers(DESCRIPTOR, "s3", body)
190
+ verified = await connector.webhook_verifier().verify(body, headers)
191
+ dispatch = await connector.handle_webhook(verified, {})
192
+ assert dispatch.provider_account_id == "org-1" and dispatch.delivery_id == "d1"
193
+ ```
194
+
195
+ ## DLT conventions
196
+
197
+ A DLT source opts into cognee's document ingestion by setting the attributes
198
+ named in `dlt_conventions` (`DOCUMENT_SOURCE_ATTR`, `PIPELINE_SCOPE_ATTR`) and
199
+ by writing the `NODE_SET_COLUMN` / `STRUCTURE_COLUMN` columns with
200
+ `DOCUMENT_COLUMN_HINTS`. The values are byte-identical to cognee's
201
+ `cognee.tasks.ingestion.dlt_utils`; connectors import them from here so no
202
+ package needs cognee at runtime.
203
+
204
+ One value is a version, not a name. `DOCUMENT_SYNC_VERSION` is the protocol
205
+ version cognee's ingestion implements and it moves with cognee releases; the
206
+ copy here is the version this package was cut at. A source that needs a
207
+ capability (per-row node sets from version 2, structure from version 3) gates
208
+ on the **host's** value, never on the constant:
209
+
210
+ ```python
211
+ from cognee_connectors_core.dlt_conventions import require_document_sync_version
212
+
213
+ # At the top of the source factory, before any provider call.
214
+ require_document_sync_version(3, provider="Notion", feature="reads per-row node sets and structure")
215
+ ```
216
+
217
+ `host_document_sync_version()` is what it reads: the installed cognee's value,
218
+ `0` for a cognee without DLT document ingestion, and this package's own value
219
+ only when cognee is not installed at all (nothing can ingest then, and a
220
+ connector's tests run without it).
221
+
222
+ ## Development
223
+
224
+ From the repo root, with a Python that has pytest and pytest-asyncio:
225
+
226
+ ```bash
227
+ PYTHONPATH=core python -m pytest core/tests -q
228
+ ruff check core && ruff format --check core
229
+ ```
230
+
231
+ The suite is pure: no network, no database, no cognee. One test compares the
232
+ DLT conventions against cognee's own module when cognee happens to be
233
+ importable, and skips otherwise.