flintai-sdk-py 1.0.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,181 @@
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 made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of recording and
55
+ discussing modifications to the Work, but excluding communication that
56
+ is conspicuously marked or designated in writing by the copyright owner
57
+ as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any patent
81
+ claim embodied in the Work constitutes direct or contributory patent
82
+ infringement, then any patent licenses granted to You under this
83
+ License for that Work shall terminate as of the date such litigation
84
+ is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the Work,
121
+ as an additional requirement beyond those described in Section 4.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer only
163
+ conditions that are (1) consistent with the terms of this License,
164
+ and (2) do not impose restrictions on the granting of rights required
165
+ by this License.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ Copyright 2024 SB Technology, Inc. dba SandboxAQ
170
+
171
+ Licensed under the Apache License, Version 2.0 (the "License");
172
+ you may not use this file except in compliance with the License.
173
+ You may obtain a copy of the License at
174
+
175
+ http://www.apache.org/licenses/LICENSE-2.0
176
+
177
+ Unless required by applicable law or agreed to in writing, software
178
+ distributed under the License is distributed on an "AS IS" BASIS,
179
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180
+ See the License for the specific language governing permissions and
181
+ limitations under the License.
@@ -0,0 +1,324 @@
1
+ Metadata-Version: 2.4
2
+ Name: flintai-sdk-py
3
+ Version: 1.0.0
4
+ Summary: Lightweight SDK for routing AI agent LLM traffic through the FlintAI guardrails proxy
5
+ Author: SandboxAQ
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/sandbox-quantum/flintai-sdk-py
8
+ Project-URL: Bug Tracker, https://github.com/sandbox-quantum/flintai-sdk-py/issues
9
+ Keywords: ai,agents,guardrails
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Provides-Extra: openai
23
+ Requires-Dist: openai<3,>=2.40.0; extra == "openai"
24
+ Provides-Extra: anthropic
25
+ Requires-Dist: anthropic<1,>=0.105.2; extra == "anthropic"
26
+ Provides-Extra: genai
27
+ Requires-Dist: google-genai<3,>=2.7; extra == "genai"
28
+ Provides-Extra: langchain
29
+ Requires-Dist: langchain-openai<2,>=1.2; extra == "langchain"
30
+ Requires-Dist: langchain-anthropic<2,>=1.4; extra == "langchain"
31
+ Requires-Dist: langchain-google-genai<5,>=4.2; extra == "langchain"
32
+ Provides-Extra: adk
33
+ Requires-Dist: google-adk<3,>=2.1; extra == "adk"
34
+ Requires-Dist: google-genai<3,>=2.7; extra == "adk"
35
+ Provides-Extra: dotenv
36
+ Requires-Dist: python-dotenv<2,>=1.2.2; extra == "dotenv"
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=9.0.3; extra == "dev"
39
+ Requires-Dist: ruff>=0.15.15; extra == "dev"
40
+ Requires-Dist: mypy>=2.1.0; extra == "dev"
41
+ Provides-Extra: audit
42
+ Requires-Dist: build>=1.0; extra == "audit"
43
+ Requires-Dist: twine>=6.0; extra == "audit"
44
+ Requires-Dist: pip-licenses>=5.0; extra == "audit"
45
+ Requires-Dist: cyclonedx-bom>=6.0; extra == "audit"
46
+ Requires-Dist: pip-audit>=2.7; extra == "audit"
47
+ Requires-Dist: pip-tools>=7.4; extra == "audit"
48
+ Provides-Extra: all
49
+ Requires-Dist: flintai-sdk-py[adk,anthropic,audit,dev,dotenv,genai,langchain,openai]; extra == "all"
50
+ Dynamic: license-file
51
+
52
+ # FlintAI SDK (Python)
53
+
54
+ Lightweight SDK for routing LLM traffic through a guardrails proxy. Wraps OpenAI, Anthropic, Google GenAI, and LangChain LLM clients, with agent framework plugins for Google ADK.
55
+
56
+ ## Features
57
+
58
+ - **LLM SDK wrapping** — route LLM traffic through the FlintAI guardrails proxy with a single `flintai.wrap()` call. Supports OpenAI, Anthropic, Google GenAI, and LangChain chat models.
59
+ - **Agent framework plugins** — deeper integration with agent lifecycle hooks for metadata extraction and guardrails routing. Currently supports Google ADK.
60
+ - **Plugin system** for extensibility
61
+
62
+ ## Supported Integrations
63
+
64
+ | Integration | Category | Guardrails Routing |
65
+ |---|---|---|
66
+ | OpenAI SDK | LLM SDK | `flintai.wrap()` |
67
+ | Anthropic SDK | LLM SDK | `flintai.wrap()` |
68
+ | Google GenAI SDK | LLM SDK | `flintai.wrap()` |
69
+ | LangChain (`ChatOpenAI`, `ChatAnthropic`, `ChatGoogleGenerativeAI`) | LLM SDK | `flintai.wrap()` |
70
+ | Google ADK | Agent Framework | `ADKGuardrailsPlugin` |
71
+
72
+ ## Install
73
+
74
+ ```bash
75
+ pip install flintai-sdk-py
76
+
77
+ # With optional extras for your LLM provider
78
+ pip install "flintai-sdk-py[openai]" # OpenAI SDK
79
+ pip install "flintai-sdk-py[anthropic]" # Anthropic SDK
80
+ pip install "flintai-sdk-py[genai]" # Google GenAI SDK
81
+ pip install "flintai-sdk-py[adk]" # Google ADK (includes GenAI)
82
+ pip install "flintai-sdk-py[langchain]" # LangChain integrations
83
+ pip install "flintai-sdk-py[all]" # Everything
84
+ ```
85
+
86
+ ## Guardrails
87
+
88
+ Route all LLM traffic through the FlintAI guardrails proxy. Create your sync client as usual, then call `flintai.wrap()` — it auto-detects the provider and applies guardrails routing. Async clients (`AsyncOpenAI`, `AsyncAnthropic`) are not supported.
89
+
90
+ ### OpenAI
91
+
92
+ ```python
93
+ import openai
94
+ import flintai
95
+
96
+ client = openai.OpenAI(api_key="your-openai-api-key")
97
+ client = flintai.wrap(
98
+ client,
99
+ gateway_url="https://guardrails.example.com",
100
+ api_key="your-guardrails-api-key",
101
+ policy_id="your-policy-id", # optional
102
+ )
103
+
104
+ response = client.chat.completions.create(
105
+ model="gpt-4",
106
+ messages=[{"role": "user", "content": "Hello"}],
107
+ )
108
+ ```
109
+
110
+ ### Anthropic
111
+
112
+ ```python
113
+ import anthropic
114
+ import flintai
115
+
116
+ client = anthropic.Anthropic(api_key="your-anthropic-api-key")
117
+ client = flintai.wrap(
118
+ client,
119
+ gateway_url="https://guardrails.example.com",
120
+ api_key="your-guardrails-api-key",
121
+ )
122
+
123
+ message = client.messages.create(
124
+ model="claude-sonnet-4-20250514",
125
+ max_tokens=1024,
126
+ messages=[{"role": "user", "content": "Hello"}],
127
+ )
128
+ ```
129
+
130
+ ### Google GenAI
131
+
132
+ Google GenAI clients don't expose `api_key` as an attribute, so `llm_api_key` must be passed explicitly:
133
+
134
+ ```python
135
+ import google.genai
136
+ import flintai
137
+
138
+ client = google.genai.Client(api_key="your-gemini-api-key")
139
+ client = flintai.wrap(
140
+ client,
141
+ gateway_url="https://guardrails.example.com",
142
+ api_key="your-guardrails-api-key",
143
+ llm_api_key="your-gemini-api-key",
144
+ )
145
+
146
+ response = client.models.generate_content(
147
+ model="gemini-2.5-flash",
148
+ contents="Hello",
149
+ )
150
+ ```
151
+
152
+ ### LangChain
153
+
154
+ Create your LangChain chat model as usual, then call `flintai.wrap()` — it detects the LangChain model, finds the underlying SDK client, and applies guardrails routing:
155
+
156
+ ```python
157
+ from langchain_openai import ChatOpenAI
158
+ import flintai
159
+
160
+ llm = ChatOpenAI(model="gpt-4", api_key="your-openai-api-key")
161
+ llm = flintai.wrap(
162
+ llm,
163
+ gateway_url="https://guardrails.example.com",
164
+ api_key="your-guardrails-api-key",
165
+ )
166
+
167
+ response = llm.invoke("Hello")
168
+ ```
169
+
170
+ Works with `ChatOpenAI`, `ChatAnthropic`, and `ChatGoogleGenerativeAI`.
171
+
172
+ ### Google ADK
173
+
174
+ ADK agents lazily create their GenAI client at runtime and use `generate_content_config` for per-request routing, so `flintai.wrap()` cannot be used. Use the ADK plugin instead:
175
+
176
+ ```python
177
+ from flintai.plugins.adk import ADKGuardrailsPlugin
178
+ from google.adk import Agent
179
+
180
+ plugin = ADKGuardrailsPlugin(
181
+ gateway_url="https://guardrails.example.com",
182
+ api_key="your-guardrails-api-key",
183
+ llm_api_key="your-gemini-api-key",
184
+ )
185
+
186
+ agent = Agent(
187
+ model="gemini-2.5-flash",
188
+ generate_content_config=plugin.content_config,
189
+ before_model_callback=plugin.before_model_callback,
190
+ on_model_error_callback=plugin.on_model_error,
191
+ )
192
+ ```
193
+
194
+ `before_model_callback` automatically extracts agent identity and session metadata on each LLM call — it reads the agent name from the ADK callback context and attaches `X-Agent-Id` and `X-Agent-Session-Id` headers to the guardrails request. It fails closed: if guardrails routing was never applied (the request has no `http_options`), it raises `FlintAIGuardrailsError` rather than sending an unguarded request — pass `require_guardrails=False` to the plugin for best-effort behavior. `on_model_error_callback` converts guardrails blocks (detected via the `GUARDRAIL_BLOCKED` error code) into an `LlmResponse` so the agent can handle them gracefully.
195
+
196
+ ## Configuration Reference
197
+
198
+ `flintai.wrap()` and `flintai.init()` accept these guardrails parameters:
199
+
200
+ | Parameter | Type | Description |
201
+ |-----------|------|-------------|
202
+ | `gateway_url` | `str` | Guardrails proxy URL |
203
+ | `api_key` | `str` | Your guardrails API key |
204
+ | `llm_api_key` | `str \| None` | Your upstream LLM provider API key, forwarded to the gateway as `X-LLM-API-Key`. Optional — by default the gateway supplies its own upstream credentials, so the key is not sent. |
205
+ | `forward_llm_key` | `bool` | `wrap()` only. When `True`, auto-extract the provider key from the client (`client.api_key`) and forward it. Default `False` (opt-in) — the caller's key is not sent to the gateway unless requested. |
206
+ | `policy_id` | `str \| None` | Guardrails policy ID to apply (optional) |
207
+
208
+ **Fail-closed by default:** `require_guardrails` defaults to `True` on `init()`, `wrap()`, and the plugins. If guardrails can't be applied — missing config, an unrecognized client, or a plugin used standalone (e.g. passed straight to `create_agent`/`Agent` without `flintai.init()`) — a `FlintAIGuardrailsError` is raised instead of sending traffic unguarded. Pass `require_guardrails=False` to opt out.
209
+
210
+ ## Environment Variables
211
+
212
+ Instead of passing credentials in code, you can set them as environment variables:
213
+
214
+ | Environment Variable | Parameter | Description |
215
+ |---|---|---|
216
+ | `FLINTAI_GATEWAY_URL` | `gateway_url` | Guardrails proxy URL |
217
+ | `FLINTAI_API_KEY` | `api_key` | Your guardrails API key |
218
+ | `FLINTAI_LLM_API_KEY` | `llm_api_key` | Your upstream LLM provider API key |
219
+ | `FLINTAI_POLICY_ID` | `policy_id` | Guardrails policy ID (optional) |
220
+ | `AGENT_ID` | `agent_id` | Agent identifier attached to guardrails requests (overrides `agent_name`) |
221
+ | `FLINTAI_ALLOWED_GATEWAY_HOSTS` | — | Comma-separated allowlist of permitted gateway hostnames. Defaults to `app.flintai.dev`; set to override (or `*` to allow any host). Loopback is always allowed. |
222
+
223
+ Set the variables in your shell or in a `.env` file (requires `pip install "flintai-sdk-py[dotenv]"`):
224
+
225
+ ```bash
226
+ # .env
227
+ FLINTAI_GATEWAY_URL=https://guardrails.example.com
228
+ FLINTAI_API_KEY=your-guardrails-api-key
229
+ FLINTAI_LLM_API_KEY=your-llm-api-key
230
+ ```
231
+
232
+ Then use the FlintAI SDK without passing credentials:
233
+
234
+ ```python
235
+ import openai
236
+ import flintai
237
+
238
+ client = openai.OpenAI()
239
+ client = flintai.wrap(client) # reads from env vars / .env file
240
+ ```
241
+
242
+ **Precedence:** Explicit parameters > environment variables > auto-extract from `client.api_key` (only in `wrap()`, and only when `forward_llm_key=True`).
243
+
244
+ **Multiple provider keys:** If multiple provider API keys are set in the environment (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`), auto-detection will fail. Pass `provider` explicitly to `flintai.init()` to disambiguate.
245
+
246
+ ## Gateway Allowlist
247
+
248
+ By default, `gateway_url` must resolve to `app.flintai.dev` (the hosted FlintAI guardrails gateway); any other host is rejected so provider keys can't be sent to an unintended endpoint. To use a self-hosted or alternate gateway, set `FLINTAI_ALLOWED_GATEWAY_HOSTS` to a comma-separated list of allowed hostnames (or `*` to disable the check). Loopback hosts (`localhost`, `127.0.0.1`, `::1`) are always allowed for local development. Plaintext `http://` is rejected except for loopback.
249
+
250
+ ## How It Works
251
+
252
+ 1. `flintai.wrap(client, gateway_url=..., ...)` auto-detects the provider from the client type, computes the provider-specific path prefix (`/openai`, `/anthropic`, `/gemini`), rewrites the client's base URL, and injects custom headers (`X-FlintAI-API-Key`, `X-Guardrails-Policy-Id`, and `X-LLM-API-Key` only when a provider key is provided or `forward_llm_key=True`)
253
+ 2. The guardrails proxy intercepts the request, applies policy checks (detectors), and strips the custom headers
254
+ 3. The proxy injects the appropriate upstream auth credentials and forwards the request to the LLM provider
255
+
256
+ **Global state:** Each `flintai.wrap()` call updates the global FlintAI SDK client's guardrails config. If you wrap multiple clients with different parameters, each client retains its own headers and base URL, but only the last `wrap()` call's config is stored globally. For most applications (single provider, shared credentials), this is transparent.
257
+
258
+ ## Known Limitations
259
+
260
+ **Private attribute mutation:** `flintai.wrap()` modifies internal attributes of LLM SDK clients (`_base_url`, `_custom_headers`, `_api_client._http_options`) to redirect traffic through the guardrails proxy. These are not part of the public API of the respective SDKs and may change without notice. Pin your SDK versions to the tested ranges:
261
+
262
+ - `openai>=2.40.0,<3`
263
+ - `anthropic>=0.105.2,<1`
264
+ - `google-genai>=2.7,<3`
265
+
266
+ **Google GenAI `api_key`:** Google GenAI clients do not expose `api_key` as an attribute. You must pass `llm_api_key=` explicitly when calling `flintai.wrap()`.
267
+
268
+ **Google GenAI URL normalization:** The Google GenAI SDK requires a trailing slash on the base URL. The FlintAI SDK normalizes this automatically — do not add a trailing slash to `gateway_url`.
269
+
270
+ **Async clients:** Async clients (`AsyncOpenAI`, `AsyncAnthropic`) are not supported. Use sync clients only.
271
+
272
+ **Thread safety:** `flintai.init()`, `flintai.wrap()`, and `flintai.shutdown()` are not thread-safe. Call them from the main thread during application startup. Once initialized, wrapped clients can be used from any thread — the underlying SDK clients handle their own thread safety.
273
+
274
+ ## Plugins
275
+
276
+ Plugins handle events from the FlintAI SDK lifecycle. Subclass `FlintAIPlugin` and override the methods you care about:
277
+
278
+ ```python
279
+ from flintai.plugins import FlintAIPlugin
280
+
281
+ class MyPlugin(FlintAIPlugin):
282
+ name = "my-plugin"
283
+
284
+ def on_init(self, client):
285
+ print(f"Plugin initialized with {client}")
286
+
287
+ def on_shutdown(self):
288
+ print("Shutting down")
289
+
290
+ # Register after init
291
+ flintai.init()
292
+ flintai.register_plugin(MyPlugin())
293
+ ```
294
+
295
+ ### Plugin Methods
296
+
297
+ | Method | Called when |
298
+ |--------|-----------|
299
+ | `on_init(client)` | Plugin is registered |
300
+ | `on_shutdown()` | `flintai.shutdown()` is called |
301
+
302
+ ## Development
303
+
304
+ ```bash
305
+ # Install with dev dependencies
306
+ pip install -e ".[dev]"
307
+
308
+ # Run tests
309
+ pytest
310
+
311
+ # Lint
312
+ ruff check .
313
+
314
+ # Type check
315
+ mypy src
316
+ ```
317
+
318
+ ## Contributing
319
+
320
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
321
+
322
+ ## License
323
+
324
+ Apache 2.0 — see [LICENSE](LICENSE).