santati 0.2.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 (55) hide show
  1. santati-0.2.0/.gitignore +19 -0
  2. santati-0.2.0/.python-version +1 -0
  3. santati-0.2.0/CHANGELOG.md +51 -0
  4. santati-0.2.0/LICENSE +190 -0
  5. santati-0.2.0/PKG-INFO +213 -0
  6. santati-0.2.0/README.md +181 -0
  7. santati-0.2.0/pyproject.toml +66 -0
  8. santati-0.2.0/src/santati/__init__.py +79 -0
  9. santati-0.2.0/src/santati/_client.py +522 -0
  10. santati-0.2.0/src/santati/_errors.py +68 -0
  11. santati-0.2.0/src/santati/_outbox.py +278 -0
  12. santati-0.2.0/src/santati/_retry.py +67 -0
  13. santati-0.2.0/src/santati/_types.py +94 -0
  14. santati-0.2.0/src/santati/integrations/__init__.py +41 -0
  15. santati-0.2.0/src/santati/integrations/_core.py +247 -0
  16. santati-0.2.0/src/santati/integrations/claude_agent_sdk.py +82 -0
  17. santati-0.2.0/src/santati/integrations/django.py +258 -0
  18. santati-0.2.0/src/santati/integrations/langchain.py +165 -0
  19. santati-0.2.0/src/santati/integrations/openai_agents.py +112 -0
  20. santati-0.2.0/src/santati/integrations/pydantic_ai.py +92 -0
  21. santati-0.2.0/src/santati/outbox/__init__.py +12 -0
  22. santati-0.2.0/src/santati/outbox/redis.py +123 -0
  23. santati-0.2.0/src/santati/py.typed +0 -0
  24. santati-0.2.0/src/santati_core/__init__.py +72 -0
  25. santati-0.2.0/src/santati_core/api/__init__.py +5 -0
  26. santati-0.2.0/src/santati_core/api/audit_events_api.py +843 -0
  27. santati-0.2.0/src/santati_core/api_client.py +833 -0
  28. santati-0.2.0/src/santati_core/api_response.py +21 -0
  29. santati-0.2.0/src/santati_core/configuration.py +679 -0
  30. santati-0.2.0/src/santati_core/exceptions.py +218 -0
  31. santati-0.2.0/src/santati_core/models/__init__.py +28 -0
  32. santati-0.2.0/src/santati_core/models/audit_event.py +128 -0
  33. santati-0.2.0/src/santati_core/models/error_body.py +97 -0
  34. santati-0.2.0/src/santati_core/models/event_actor.py +94 -0
  35. santati-0.2.0/src/santati_core/models/event_actor_request.py +94 -0
  36. santati-0.2.0/src/santati_core/models/event_batch_item_result.py +105 -0
  37. santati-0.2.0/src/santati_core/models/event_batch_request.py +95 -0
  38. santati-0.2.0/src/santati_core/models/event_batch_result.py +99 -0
  39. santati-0.2.0/src/santati_core/models/event_envelope_request.py +122 -0
  40. santati-0.2.0/src/santati_core/models/event_ingest_request.py +137 -0
  41. santati-0.2.0/src/santati_core/models/event_target.py +94 -0
  42. santati-0.2.0/src/santati_core/models/event_target_request.py +94 -0
  43. santati-0.2.0/src/santati_core/models/paginated_audit_event_list.py +109 -0
  44. santati-0.2.0/src/santati_core/rest.py +334 -0
  45. santati-0.2.0/tests/chaos_driver.py +145 -0
  46. santati-0.2.0/tests/test_conformance.py +332 -0
  47. santati-0.2.0/tests/test_integration_claude_agent_sdk.py +99 -0
  48. santati-0.2.0/tests/test_integration_django.py +181 -0
  49. santati-0.2.0/tests/test_integration_langchain.py +202 -0
  50. santati-0.2.0/tests/test_integration_openai_agents.py +108 -0
  51. santati-0.2.0/tests/test_integration_pydantic_ai.py +104 -0
  52. santati-0.2.0/tests/test_integrations_core.py +166 -0
  53. santati-0.2.0/tests/test_outbox.py +40 -0
  54. santati-0.2.0/tests/test_outbox_redis.py +48 -0
  55. santati-0.2.0/uv.lock +2958 -0
@@ -0,0 +1,19 @@
1
+ .DS_Store
2
+ __pycache__/
3
+ .venv/
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ python/dist/
8
+ typescript/node_modules/
9
+ typescript/dist/
10
+ rust/target/
11
+ elixir/_build/
12
+ elixir/deps/
13
+ elixir/doc/
14
+ ruby/vendor/
15
+ ruby/*.gem
16
+ php/vendor/
17
+ php/.phpunit.cache/
18
+ erl_crash.dump
19
+ chaos/.results/
@@ -0,0 +1 @@
1
+ 3.14
@@ -0,0 +1,51 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are documented here. The format is based
4
+ on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2026-10-06
10
+
11
+ ### Added
12
+
13
+ - An opt-in outbox: with `outbox=` (`MemoryOutbox`, or Redis Streams via
14
+ `santati.outbox.redis.RedisOutbox`, `santati[redis]`) `events.emit` stores the
15
+ event and returns at once with `EmitResult.queued` true; a background worker
16
+ sends the outbox in batches of `batch_size` every `flush_interval_ms`
17
+ through `emit_batch`, with `pre_send`/`post_send` hooks, `Santati.flush()`,
18
+ and `OutboxError`. `close()` now stops the worker and flushes the outbox
19
+ first. A queued `emit` stores a copy of the event; a batch that fails with
20
+ anything but a `SantatiError` (e.g. a malformed `pre_send` result) is
21
+ reported to `post_send` as `OutboxError` `hook_failed` and dropped, never
22
+ raised. Each batch is sent once, without `max_retries`: a retryable failure releases it for the next pass.
23
+
24
+ ### Changed
25
+
26
+ - `EmitResult` has a new `queued` field, and its `event` is `None` for a
27
+ queued emit.
28
+
29
+ ### Fixed
30
+
31
+ - `events.emit_batch` raises `santati.ValidationError` (with `field`) for an
32
+ item the request model rejects, such as an actor without `type`, instead of
33
+ a raw `pydantic.ValidationError`.
34
+
35
+ ## [0.1.0] - 2026-10-01
36
+
37
+ ### Added
38
+
39
+ - Framework integrations under `santati.integrations`, each behind an extra:
40
+ Django auth signals (`santati[django]`), LangChain/LangGraph tool calls
41
+ (`santati[langchain]`), OpenAI Agents SDK tool calls
42
+ (`santati[openai-agents]`), Pydantic AI tool executions
43
+ (`santati[pydantic-ai]`) and Claude Agent SDK tool calls
44
+ (`santati[claude-agent-sdk]`). Each sends events inline through `client` or
45
+ hands them to a `dispatch` callable, and never raises into the framework.
46
+ - Emit one audit event or a batch, with generated idempotency keys and retries.
47
+ - List audit events with filters and cursor pagination, and iterate across pages.
48
+
49
+ [Unreleased]: https://github.com/jamescarr/santati-sdks/compare/python-v0.2.0...HEAD
50
+ [0.2.0]: https://github.com/jamescarr/santati-sdks/compare/python-v0.1.0...python-v0.2.0
51
+ [0.1.0]: https://github.com/jamescarr/santati-sdks/releases/tag/python-v0.1.0
santati-0.2.0/LICENSE ADDED
@@ -0,0 +1,190 @@
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
44
+ purposes of this License, Derivative Works shall not include works
45
+ that remain separable from, or merely link (or bind by name) to the
46
+ interfaces of, the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the
49
+ 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
141
+ the 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
+ Copyright 2026 The Ankusa Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
santati-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.5
2
+ Name: santati
3
+ Version: 0.2.0
4
+ Summary: Official Python SDK for the Santati audit-log API: emit audit events (one or a batch) and list or iterate over them.
5
+ Project-URL: Repository, https://github.com/jamescarr/santati-sdks
6
+ Project-URL: Homepage, https://github.com/jamescarr/santati-sdks/tree/main/python
7
+ Project-URL: Issues, https://github.com/jamescarr/santati-sdks/issues
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: audit,audit-log,events,logging,santati
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: pydantic>=2.11
13
+ Requires-Dist: python-dateutil>=2.8.2
14
+ Requires-Dist: typing-extensions>=4.7.1
15
+ Requires-Dist: urllib3<3,>=2.1.0
16
+ Provides-Extra: claude-agent-sdk
17
+ Requires-Dist: anyio>=4; extra == 'claude-agent-sdk'
18
+ Requires-Dist: claude-agent-sdk>=0.1.46; extra == 'claude-agent-sdk'
19
+ Provides-Extra: django
20
+ Requires-Dist: django>=5.2; extra == 'django'
21
+ Provides-Extra: langchain
22
+ Requires-Dist: langchain-core>=1.2; extra == 'langchain'
23
+ Provides-Extra: openai-agents
24
+ Requires-Dist: anyio>=4; extra == 'openai-agents'
25
+ Requires-Dist: openai-agents>=0.22.3; extra == 'openai-agents'
26
+ Provides-Extra: pydantic-ai
27
+ Requires-Dist: anyio>=4; extra == 'pydantic-ai'
28
+ Requires-Dist: pydantic-ai-slim>=2.52; extra == 'pydantic-ai'
29
+ Provides-Extra: redis
30
+ Requires-Dist: redis>=5; extra == 'redis'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # santati (Python)
34
+
35
+ Official Python SDK for the [Santati](https://santati.io) audit-log API: emit
36
+ audit events (one or a batch) and read them back with cursor pagination.
37
+
38
+ ## Install
39
+
40
+ ```sh
41
+ pip install santati
42
+ ```
43
+
44
+ ## Quickstart
45
+
46
+ ```python
47
+ import santati
48
+
49
+ with santati.Santati("sat_sk_...", trail="billing") as client:
50
+ # Emit one event. A missing idempotency key is generated for you, and the
51
+ # request is retried on transport failures, 500/502/503/504 and 429.
52
+ result = client.events.emit(
53
+ "invoice.voided",
54
+ organization_id="org_acme",
55
+ actor={"type": "user", "id": "usr_123", "name": "Dana Ortiz"},
56
+ targets=[{"type": "invoice", "id": "inv_555"}],
57
+ data={"amount_cents": 4200, "currency": "usd"},
58
+ )
59
+ print(result.event.id, result.duplicate)
60
+
61
+ # Emit a batch: one generated key per item, per-item results on 202/207.
62
+ batch = client.events.emit_batch([{"event": "invoice.paid"}, {"event": "invoice.voided"}])
63
+ print(batch.accepted, batch.rejected)
64
+
65
+ # List a page, then iterate across every page.
66
+ page = client.events.list(trail="billing", limit=50)
67
+ for event in page.results:
68
+ print(event.id, event.event)
69
+
70
+ for event in client.events.iterate(trail="billing", limit=100):
71
+ print(event.id)
72
+ ```
73
+
74
+ ## Client options
75
+
76
+ `Santati(api_key, *, base_url="https://api.santati.io", trail=None,
77
+ timeout_ms=10000, max_retries=2, initial_backoff_ms=250, max_backoff_ms=8000,
78
+ headers=None, outbox=None, batch_size=100, flush_interval_ms=1000,
79
+ pre_send=None, post_send=None)`. `trail` is the default trail for emits and is
80
+ never applied to reads; the last four only matter with an `outbox` (below).
81
+
82
+ ## Outbox
83
+
84
+ With no `outbox`, `events.emit` sends the event and returns the stored one.
85
+ Pass `outbox=` (a `santati.MemoryOutbox()` or any `OutboxStore`) and `emit`
86
+ validates the event the same way, stores the envelope in the outbox and returns
87
+ at once with `queued=True`, `event=None` and the idempotency key, without making
88
+ a request. A background thread sends the outbox every `flush_interval_ms` in
89
+ batches of `batch_size` through `emit_batch`; `client.flush()` sends it now and
90
+ `client.close()` (or leaving the `with` block) stops the thread and flushes
91
+ once.
92
+
93
+ ```python
94
+ import redis
95
+ import santati
96
+ from santati.outbox.redis import RedisOutbox
97
+
98
+
99
+ def report(event: santati.EventInput, outcome: santati.SendOutcome) -> None:
100
+ if outcome.status in ("rejected", "failed"):
101
+ print(event["idempotency_key"], outcome.error)
102
+
103
+
104
+ with santati.Santati("sat_sk_...", trail="billing", outbox=santati.MemoryOutbox(), post_send=report) as client:
105
+ result = client.events.emit("invoice.voided", organization_id="org_acme")
106
+ assert result.queued
107
+
108
+ # Survive restarts: keep the outbox in Redis (pip install "santati[redis]").
109
+ client = santati.Santati("sat_sk_...", trail="billing", outbox=RedisOutbox(redis.Redis()))
110
+ ```
111
+
112
+ `santati.MemoryOutbox(max_pending=10000)` is the in-process store; a full one
113
+ makes a queued `emit` raise `OutboxError` (`code="outbox_full"`). `close()` sends each
114
+ batch once; if the endpoint is down, what it could not send stays in the store and, in
115
+ memory, is lost with the process (use `RedisOutbox` above to keep it). `pre_send(event)` may
116
+ return a modified event or `None` to drop it; `post_send(event, outcome)`
117
+ receives each original event with a `SendOutcome` (`accepted`, `duplicate`,
118
+ `rejected` or `failed`). A batch that fails with `TransportError`,
119
+ `ServerError` or `RateLimitedError` stays in the outbox for the next pass; any
120
+ other failure drops it. Implement `santati.OutboxStore` (`enqueue`, `claim`,
121
+ `ack`, `release`) for another backend.
122
+
123
+ ## Errors
124
+
125
+ Every failure raises a subclass of `santati.SantatiError`: `ValidationError`,
126
+ `AuthError`, `NotFoundError`, `RateLimitedError`, `ServerError`,
127
+ `TransportError`, `ApiError` or `OutboxError`. Each carries `status`, `code`,
128
+ `field`, `retry_after` and `message`; `status` is `None` for local validation
129
+ failures, transport errors and outbox errors.
130
+
131
+ `AuditEvent`, `EventActor` and `EventTarget` are the generated read models,
132
+ re-exported from the package root. See `docs/sdk-surface.md` in the repository
133
+ for the surface every Santati SDK implements.
134
+
135
+ ## Framework integrations
136
+
137
+ `santati.integrations` turns the callbacks of the frameworks you already run
138
+ into audit events. Each integration lives behind its own extra:
139
+
140
+ | module | extra | records |
141
+ |---|---|---|
142
+ | `santati.integrations.django` | `santati[django]` | `user.logged_in`, `user.logged_out`, `user.login_failed` |
143
+ | `santati.integrations.langchain` | `santati[langchain]` | `agent.tool_call.succeeded` / `.failed` |
144
+ | `santati.integrations.openai_agents` | `santati[openai-agents]` | `agent.tool_call.succeeded` / `.failed` |
145
+ | `santati.integrations.pydantic_ai` | `santati[pydantic-ai]` | `agent.tool_call.succeeded` / `.failed` |
146
+ | `santati.integrations.claude_agent_sdk` | `santati[claude-agent-sdk]` | `agent.tool_call.succeeded` / `.failed` |
147
+
148
+ ```python
149
+ from santati.integrations.django import instrument_auth
150
+
151
+
152
+ class BillingConfig(AppConfig):
153
+ def ready(self) -> None:
154
+ instrument_auth(client, organization_id="org_acme")
155
+ ```
156
+
157
+ Every integration takes exactly one of `client` — sent inline through the
158
+ synchronous client — or `dispatch`, a callable that receives each built
159
+ envelope (a Celery task's `delay`, an RQ queue, a thread pool):
160
+
161
+ ```python
162
+ handler = SantatiCallbackHandler(dispatch=record_event.delay, organization_id="org_acme")
163
+ agent.invoke({"messages": [...]}, config={"callbacks": [handler]})
164
+ ```
165
+
166
+ The four agent adapters fix `organization_id` and `actor` per instance, so a
167
+ multi-tenant app builds one per request — or passes it per run, which all four
168
+ agent frameworks support. Their default actor is
169
+ `{"type": "system", "id": <agent name or framework slug>}`; the agent name is
170
+ also kept in `metadata.agent`. Every integration lets you override its event
171
+ names, which teams with a declared action catalog need. Django is different:
172
+ see its entry below.
173
+
174
+ Nothing an integration does can raise into the framework that called it: a
175
+ failed emit is logged to the `santati.integrations` logger at WARNING and
176
+ dropped. Events are built with a fixed idempotency key, so a dispatcher's
177
+ retry replays instead of double-recording.
178
+
179
+ Per framework:
180
+
181
+ - **Django** — `instrument_auth` connects to `user_logged_in`,
182
+ `user_logged_out` and `user_login_failed`. Call it once, from
183
+ `AppConfig.ready`, and never per request: it installs one process-wide set
184
+ of receivers and a repeated call replaces the previous instrumentation, so
185
+ concurrent requests would overwrite each other's settings and could record
186
+ one tenant's logins under another's `organization_id`. A multi-tenant app
187
+ passes `organization_id` as a callable `(request, user)` that returns the
188
+ tenant's organization, or `None`/`""` to skip the event; `user` is `None`
189
+ for a failed login, and `request` is `None` when `authenticate()` ran
190
+ without one. `actor` is likewise a callable `(request, user)` returning the
191
+ actor to record instead of the Django user, for logins and logouts (a
192
+ failed login is always `anonymous`). A failed login records the attempted
193
+ identifier only (`metadata.username`) and never any other credential value.
194
+ Pass `context` to replace the default IP/user-agent context, and set an
195
+ `*_event` name to `None` to leave that signal alone.
196
+ - **LangChain / LangGraph** — `SantatiCallbackHandler` audits `ToolNode`,
197
+ `create_agent` and bare `tool.invoke` calls. It runs in an executor thread
198
+ during async runs, so emits never stall the event loop. A call LangGraph
199
+ pauses with `interrupt()` produces no event; the resumed run audits the call
200
+ that actually executes.
201
+ - **OpenAI Agents SDK** — `SantatiRunHooks` audits local tool calls.
202
+ Failures are opt-in: the SDK's default formatter turns a tool exception into
203
+ a result nothing can observe, so a failing tool is recorded as succeeded
204
+ unless the tool is given `failure_error_function=record_tool_failure` (or
205
+ retrofitted with `set_function_tool_failure_error_function`). Hosted tools
206
+ and handoffs produce no events, and a nested `agent.as_tool(...)` run is
207
+ audited only when it is given the hooks too (`as_tool(..., hooks=hooks)`).
208
+ - **Pydantic AI** — `SantatiCapability` audits every tool execution. A call
209
+ that never ran (deferred, awaiting approval, skipped) produces no event.
210
+ - **Claude Agent SDK** — `santati_hooks(...)` returns the hook configuration for
211
+ `ClaudeAgentOptions(hooks=...)`: it audits `PostToolUse` and
212
+ `PostToolUseFailure`. Tools denied by a permission hook produce no events.
213
+
@@ -0,0 +1,181 @@
1
+ # santati (Python)
2
+
3
+ Official Python SDK for the [Santati](https://santati.io) audit-log API: emit
4
+ audit events (one or a batch) and read them back with cursor pagination.
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ pip install santati
10
+ ```
11
+
12
+ ## Quickstart
13
+
14
+ ```python
15
+ import santati
16
+
17
+ with santati.Santati("sat_sk_...", trail="billing") as client:
18
+ # Emit one event. A missing idempotency key is generated for you, and the
19
+ # request is retried on transport failures, 500/502/503/504 and 429.
20
+ result = client.events.emit(
21
+ "invoice.voided",
22
+ organization_id="org_acme",
23
+ actor={"type": "user", "id": "usr_123", "name": "Dana Ortiz"},
24
+ targets=[{"type": "invoice", "id": "inv_555"}],
25
+ data={"amount_cents": 4200, "currency": "usd"},
26
+ )
27
+ print(result.event.id, result.duplicate)
28
+
29
+ # Emit a batch: one generated key per item, per-item results on 202/207.
30
+ batch = client.events.emit_batch([{"event": "invoice.paid"}, {"event": "invoice.voided"}])
31
+ print(batch.accepted, batch.rejected)
32
+
33
+ # List a page, then iterate across every page.
34
+ page = client.events.list(trail="billing", limit=50)
35
+ for event in page.results:
36
+ print(event.id, event.event)
37
+
38
+ for event in client.events.iterate(trail="billing", limit=100):
39
+ print(event.id)
40
+ ```
41
+
42
+ ## Client options
43
+
44
+ `Santati(api_key, *, base_url="https://api.santati.io", trail=None,
45
+ timeout_ms=10000, max_retries=2, initial_backoff_ms=250, max_backoff_ms=8000,
46
+ headers=None, outbox=None, batch_size=100, flush_interval_ms=1000,
47
+ pre_send=None, post_send=None)`. `trail` is the default trail for emits and is
48
+ never applied to reads; the last four only matter with an `outbox` (below).
49
+
50
+ ## Outbox
51
+
52
+ With no `outbox`, `events.emit` sends the event and returns the stored one.
53
+ Pass `outbox=` (a `santati.MemoryOutbox()` or any `OutboxStore`) and `emit`
54
+ validates the event the same way, stores the envelope in the outbox and returns
55
+ at once with `queued=True`, `event=None` and the idempotency key, without making
56
+ a request. A background thread sends the outbox every `flush_interval_ms` in
57
+ batches of `batch_size` through `emit_batch`; `client.flush()` sends it now and
58
+ `client.close()` (or leaving the `with` block) stops the thread and flushes
59
+ once.
60
+
61
+ ```python
62
+ import redis
63
+ import santati
64
+ from santati.outbox.redis import RedisOutbox
65
+
66
+
67
+ def report(event: santati.EventInput, outcome: santati.SendOutcome) -> None:
68
+ if outcome.status in ("rejected", "failed"):
69
+ print(event["idempotency_key"], outcome.error)
70
+
71
+
72
+ with santati.Santati("sat_sk_...", trail="billing", outbox=santati.MemoryOutbox(), post_send=report) as client:
73
+ result = client.events.emit("invoice.voided", organization_id="org_acme")
74
+ assert result.queued
75
+
76
+ # Survive restarts: keep the outbox in Redis (pip install "santati[redis]").
77
+ client = santati.Santati("sat_sk_...", trail="billing", outbox=RedisOutbox(redis.Redis()))
78
+ ```
79
+
80
+ `santati.MemoryOutbox(max_pending=10000)` is the in-process store; a full one
81
+ makes a queued `emit` raise `OutboxError` (`code="outbox_full"`). `close()` sends each
82
+ batch once; if the endpoint is down, what it could not send stays in the store and, in
83
+ memory, is lost with the process (use `RedisOutbox` above to keep it). `pre_send(event)` may
84
+ return a modified event or `None` to drop it; `post_send(event, outcome)`
85
+ receives each original event with a `SendOutcome` (`accepted`, `duplicate`,
86
+ `rejected` or `failed`). A batch that fails with `TransportError`,
87
+ `ServerError` or `RateLimitedError` stays in the outbox for the next pass; any
88
+ other failure drops it. Implement `santati.OutboxStore` (`enqueue`, `claim`,
89
+ `ack`, `release`) for another backend.
90
+
91
+ ## Errors
92
+
93
+ Every failure raises a subclass of `santati.SantatiError`: `ValidationError`,
94
+ `AuthError`, `NotFoundError`, `RateLimitedError`, `ServerError`,
95
+ `TransportError`, `ApiError` or `OutboxError`. Each carries `status`, `code`,
96
+ `field`, `retry_after` and `message`; `status` is `None` for local validation
97
+ failures, transport errors and outbox errors.
98
+
99
+ `AuditEvent`, `EventActor` and `EventTarget` are the generated read models,
100
+ re-exported from the package root. See `docs/sdk-surface.md` in the repository
101
+ for the surface every Santati SDK implements.
102
+
103
+ ## Framework integrations
104
+
105
+ `santati.integrations` turns the callbacks of the frameworks you already run
106
+ into audit events. Each integration lives behind its own extra:
107
+
108
+ | module | extra | records |
109
+ |---|---|---|
110
+ | `santati.integrations.django` | `santati[django]` | `user.logged_in`, `user.logged_out`, `user.login_failed` |
111
+ | `santati.integrations.langchain` | `santati[langchain]` | `agent.tool_call.succeeded` / `.failed` |
112
+ | `santati.integrations.openai_agents` | `santati[openai-agents]` | `agent.tool_call.succeeded` / `.failed` |
113
+ | `santati.integrations.pydantic_ai` | `santati[pydantic-ai]` | `agent.tool_call.succeeded` / `.failed` |
114
+ | `santati.integrations.claude_agent_sdk` | `santati[claude-agent-sdk]` | `agent.tool_call.succeeded` / `.failed` |
115
+
116
+ ```python
117
+ from santati.integrations.django import instrument_auth
118
+
119
+
120
+ class BillingConfig(AppConfig):
121
+ def ready(self) -> None:
122
+ instrument_auth(client, organization_id="org_acme")
123
+ ```
124
+
125
+ Every integration takes exactly one of `client` — sent inline through the
126
+ synchronous client — or `dispatch`, a callable that receives each built
127
+ envelope (a Celery task's `delay`, an RQ queue, a thread pool):
128
+
129
+ ```python
130
+ handler = SantatiCallbackHandler(dispatch=record_event.delay, organization_id="org_acme")
131
+ agent.invoke({"messages": [...]}, config={"callbacks": [handler]})
132
+ ```
133
+
134
+ The four agent adapters fix `organization_id` and `actor` per instance, so a
135
+ multi-tenant app builds one per request — or passes it per run, which all four
136
+ agent frameworks support. Their default actor is
137
+ `{"type": "system", "id": <agent name or framework slug>}`; the agent name is
138
+ also kept in `metadata.agent`. Every integration lets you override its event
139
+ names, which teams with a declared action catalog need. Django is different:
140
+ see its entry below.
141
+
142
+ Nothing an integration does can raise into the framework that called it: a
143
+ failed emit is logged to the `santati.integrations` logger at WARNING and
144
+ dropped. Events are built with a fixed idempotency key, so a dispatcher's
145
+ retry replays instead of double-recording.
146
+
147
+ Per framework:
148
+
149
+ - **Django** — `instrument_auth` connects to `user_logged_in`,
150
+ `user_logged_out` and `user_login_failed`. Call it once, from
151
+ `AppConfig.ready`, and never per request: it installs one process-wide set
152
+ of receivers and a repeated call replaces the previous instrumentation, so
153
+ concurrent requests would overwrite each other's settings and could record
154
+ one tenant's logins under another's `organization_id`. A multi-tenant app
155
+ passes `organization_id` as a callable `(request, user)` that returns the
156
+ tenant's organization, or `None`/`""` to skip the event; `user` is `None`
157
+ for a failed login, and `request` is `None` when `authenticate()` ran
158
+ without one. `actor` is likewise a callable `(request, user)` returning the
159
+ actor to record instead of the Django user, for logins and logouts (a
160
+ failed login is always `anonymous`). A failed login records the attempted
161
+ identifier only (`metadata.username`) and never any other credential value.
162
+ Pass `context` to replace the default IP/user-agent context, and set an
163
+ `*_event` name to `None` to leave that signal alone.
164
+ - **LangChain / LangGraph** — `SantatiCallbackHandler` audits `ToolNode`,
165
+ `create_agent` and bare `tool.invoke` calls. It runs in an executor thread
166
+ during async runs, so emits never stall the event loop. A call LangGraph
167
+ pauses with `interrupt()` produces no event; the resumed run audits the call
168
+ that actually executes.
169
+ - **OpenAI Agents SDK** — `SantatiRunHooks` audits local tool calls.
170
+ Failures are opt-in: the SDK's default formatter turns a tool exception into
171
+ a result nothing can observe, so a failing tool is recorded as succeeded
172
+ unless the tool is given `failure_error_function=record_tool_failure` (or
173
+ retrofitted with `set_function_tool_failure_error_function`). Hosted tools
174
+ and handoffs produce no events, and a nested `agent.as_tool(...)` run is
175
+ audited only when it is given the hooks too (`as_tool(..., hooks=hooks)`).
176
+ - **Pydantic AI** — `SantatiCapability` audits every tool execution. A call
177
+ that never ran (deferred, awaiting approval, skipped) produces no event.
178
+ - **Claude Agent SDK** — `santati_hooks(...)` returns the hook configuration for
179
+ `ClaudeAgentOptions(hooks=...)`: it audits `PostToolUse` and
180
+ `PostToolUseFailure`. Tools denied by a permission hook produce no events.
181
+