driftrail 2.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DriftRail
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: driftrail
3
+ Version: 2.0.0
4
+ Summary: DriftRail SDK - AI Safety & Observability Platform for LLM monitoring, guardrails, and compliance
5
+ Author-email: DriftRail <support@driftrail.com>
6
+ Maintainer-email: DriftRail <support@driftrail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://driftrail.com
9
+ Project-URL: Documentation, https://docs.driftrail.com
10
+ Project-URL: Repository, https://github.com/cutmob/DriftRail-Python
11
+ Project-URL: Changelog, https://github.com/cutmob/DriftRail-Python/blob/main/CHANGELOG.md
12
+ Project-URL: Bug Tracker, https://github.com/cutmob/DriftRail-Python/issues
13
+ Keywords: ai,llm,observability,safety,monitoring,audit,guardrails,compliance,openai,anthropic,gemini,machine-learning,mlops
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
27
+ Classifier: Topic :: System :: Monitoring
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.8
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Provides-Extra: async
33
+ Requires-Dist: aiohttp>=3.8.0; extra == "async"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
36
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
37
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
38
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # DriftRail Python SDK
42
+
43
+ [![PyPI version](https://badge.fury.io/py/driftrail.svg)](https://pypi.org/project/driftrail/)
44
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
45
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
46
+
47
+ AI Safety & Observability Platform — Monitor, classify, and audit every LLM interaction.
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install driftrail
53
+
54
+ # For async support
55
+ pip install driftrail[async]
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ```python
61
+ from driftrail import DriftRail
62
+
63
+ client = DriftRail(
64
+ api_key="dr_live_...",
65
+ app_id="my-app"
66
+ )
67
+
68
+ # Log an LLM interaction
69
+ response = client.ingest(
70
+ model="claude-sonnet-4",
71
+ provider="anthropic",
72
+ input={"prompt": "What is the capital of France?"},
73
+ output={"text": "The capital of France is Paris."}
74
+ )
75
+
76
+ print(f"Event ID: {response.event_id}")
77
+ ```
78
+
79
+ ## Inline Guardrails
80
+
81
+ Block dangerous outputs BEFORE they reach users:
82
+
83
+ ```python
84
+ from driftrail import DriftRail
85
+
86
+ client = DriftRail(api_key="...", app_id="my-app")
87
+
88
+ # Get response from your LLM
89
+ llm_response = your_llm_call(user_prompt)
90
+
91
+ # Guard it before returning to user
92
+ result = client.guard(
93
+ output=llm_response,
94
+ input=user_prompt,
95
+ mode="strict" # or "permissive"
96
+ )
97
+
98
+ if result.allowed:
99
+ return result.output # May be redacted if PII was found
100
+ else:
101
+ print(f"Blocked: {[t.reason for t in result.triggered]}")
102
+ return "Sorry, I can't help with that."
103
+ ```
104
+
105
+ ### Guard Modes
106
+
107
+ - `strict` (default): Blocks on medium+ risk (PII, moderate toxicity, prompt injection)
108
+ - `permissive`: Only blocks on high risk (severe toxicity, high-risk injection)
109
+
110
+ ### Fail-Open vs Fail-Closed
111
+
112
+ ```python
113
+ # Fail-open (default): If DriftRail is unavailable, content is allowed through
114
+ client = DriftRail(api_key="...", app_id="...", guard_mode="fail_open")
115
+
116
+ # Fail-closed: If DriftRail is unavailable, raises exception
117
+ client = DriftRail(api_key="...", app_id="...", guard_mode="fail_closed")
118
+
119
+ try:
120
+ result = client.guard(output=llm_response)
121
+ except GuardBlockedError as e:
122
+ print(f"Blocked: {e.result.triggered}")
123
+ ```
124
+
125
+ ## Async Usage
126
+
127
+ ```python
128
+ import asyncio
129
+ from driftrail import DriftRailAsync
130
+
131
+ async def main():
132
+ async with DriftRailAsync(api_key="...", app_id="my-app") as client:
133
+ response = await client.ingest(
134
+ model="claude-3",
135
+ provider="anthropic",
136
+ input={"prompt": "Hello"},
137
+ output={"text": "Hi there!"}
138
+ )
139
+
140
+ asyncio.run(main())
141
+ ```
142
+
143
+ ## Fire-and-Forget (Non-blocking)
144
+
145
+ ```python
146
+ # Won't block your main thread
147
+ client.ingest_async(
148
+ model="gpt-4o",
149
+ provider="openai",
150
+ input={"prompt": "..."},
151
+ output={"text": "..."}
152
+ )
153
+ ```
154
+
155
+ > ⚠️ **Serverless Warning**: Do not use `ingest_async()` in AWS Lambda, Google Cloud Functions, or other serverless environments. Use the synchronous `ingest()` method instead.
156
+
157
+ ## With Metadata
158
+
159
+ ```python
160
+ import time
161
+
162
+ start = time.time()
163
+ # ... your LLM call ...
164
+ latency = int((time.time() - start) * 1000)
165
+
166
+ client.ingest(
167
+ model="gpt-4o",
168
+ provider="openai",
169
+ input={"prompt": "..."},
170
+ output={"text": "..."},
171
+ metadata={
172
+ "latency_ms": latency,
173
+ "tokens_in": 50,
174
+ "tokens_out": 150,
175
+ "temperature": 0.7
176
+ }
177
+ )
178
+ ```
179
+
180
+ ## With RAG Sources
181
+
182
+ ```python
183
+ client.ingest(
184
+ model="claude-3.5-haiku",
185
+ provider="anthropic",
186
+ input={
187
+ "prompt": "What does our refund policy say?",
188
+ "retrieved_sources": [
189
+ {"id": "doc-123", "content": "Refunds are available within 30 days..."},
190
+ {"id": "doc-456", "content": "Contact support for refund requests..."}
191
+ ]
192
+ },
193
+ output={"text": "According to our policy, refunds are available within 30 days..."}
194
+ )
195
+ ```
196
+
197
+ ## Enterprise Features
198
+
199
+ ```python
200
+ from driftrail import DriftRailEnterprise
201
+
202
+ client = DriftRailEnterprise(api_key="...", app_id="my-app")
203
+
204
+ # Incident management
205
+ stats = client.get_incident_stats()
206
+
207
+ # Compliance status
208
+ compliance = client.get_compliance_status()
209
+
210
+ # Model leaderboard
211
+ leaderboard = client.get_model_leaderboard(metric="avg_risk_score")
212
+
213
+ # Brand safety checks
214
+ violations = client.check_brand_safety("Some AI output text")
215
+ ```
216
+
217
+ ## Documentation
218
+
219
+ - [Full Documentation](https://docs.driftrail.com)
220
+ - [API Reference](https://docs.driftrail.com/api)
221
+ - [Dashboard](https://app.driftrail.com)
222
+ - [GitHub Repository](https://github.com/cutmob/DriftRail-Python)
223
+
224
+ ## License
225
+
226
+ MIT
@@ -0,0 +1,186 @@
1
+ # DriftRail Python SDK
2
+
3
+ [![PyPI version](https://badge.fury.io/py/driftrail.svg)](https://pypi.org/project/driftrail/)
4
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ AI Safety & Observability Platform — Monitor, classify, and audit every LLM interaction.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install driftrail
13
+
14
+ # For async support
15
+ pip install driftrail[async]
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```python
21
+ from driftrail import DriftRail
22
+
23
+ client = DriftRail(
24
+ api_key="dr_live_...",
25
+ app_id="my-app"
26
+ )
27
+
28
+ # Log an LLM interaction
29
+ response = client.ingest(
30
+ model="claude-sonnet-4",
31
+ provider="anthropic",
32
+ input={"prompt": "What is the capital of France?"},
33
+ output={"text": "The capital of France is Paris."}
34
+ )
35
+
36
+ print(f"Event ID: {response.event_id}")
37
+ ```
38
+
39
+ ## Inline Guardrails
40
+
41
+ Block dangerous outputs BEFORE they reach users:
42
+
43
+ ```python
44
+ from driftrail import DriftRail
45
+
46
+ client = DriftRail(api_key="...", app_id="my-app")
47
+
48
+ # Get response from your LLM
49
+ llm_response = your_llm_call(user_prompt)
50
+
51
+ # Guard it before returning to user
52
+ result = client.guard(
53
+ output=llm_response,
54
+ input=user_prompt,
55
+ mode="strict" # or "permissive"
56
+ )
57
+
58
+ if result.allowed:
59
+ return result.output # May be redacted if PII was found
60
+ else:
61
+ print(f"Blocked: {[t.reason for t in result.triggered]}")
62
+ return "Sorry, I can't help with that."
63
+ ```
64
+
65
+ ### Guard Modes
66
+
67
+ - `strict` (default): Blocks on medium+ risk (PII, moderate toxicity, prompt injection)
68
+ - `permissive`: Only blocks on high risk (severe toxicity, high-risk injection)
69
+
70
+ ### Fail-Open vs Fail-Closed
71
+
72
+ ```python
73
+ # Fail-open (default): If DriftRail is unavailable, content is allowed through
74
+ client = DriftRail(api_key="...", app_id="...", guard_mode="fail_open")
75
+
76
+ # Fail-closed: If DriftRail is unavailable, raises exception
77
+ client = DriftRail(api_key="...", app_id="...", guard_mode="fail_closed")
78
+
79
+ try:
80
+ result = client.guard(output=llm_response)
81
+ except GuardBlockedError as e:
82
+ print(f"Blocked: {e.result.triggered}")
83
+ ```
84
+
85
+ ## Async Usage
86
+
87
+ ```python
88
+ import asyncio
89
+ from driftrail import DriftRailAsync
90
+
91
+ async def main():
92
+ async with DriftRailAsync(api_key="...", app_id="my-app") as client:
93
+ response = await client.ingest(
94
+ model="claude-3",
95
+ provider="anthropic",
96
+ input={"prompt": "Hello"},
97
+ output={"text": "Hi there!"}
98
+ )
99
+
100
+ asyncio.run(main())
101
+ ```
102
+
103
+ ## Fire-and-Forget (Non-blocking)
104
+
105
+ ```python
106
+ # Won't block your main thread
107
+ client.ingest_async(
108
+ model="gpt-4o",
109
+ provider="openai",
110
+ input={"prompt": "..."},
111
+ output={"text": "..."}
112
+ )
113
+ ```
114
+
115
+ > ⚠️ **Serverless Warning**: Do not use `ingest_async()` in AWS Lambda, Google Cloud Functions, or other serverless environments. Use the synchronous `ingest()` method instead.
116
+
117
+ ## With Metadata
118
+
119
+ ```python
120
+ import time
121
+
122
+ start = time.time()
123
+ # ... your LLM call ...
124
+ latency = int((time.time() - start) * 1000)
125
+
126
+ client.ingest(
127
+ model="gpt-4o",
128
+ provider="openai",
129
+ input={"prompt": "..."},
130
+ output={"text": "..."},
131
+ metadata={
132
+ "latency_ms": latency,
133
+ "tokens_in": 50,
134
+ "tokens_out": 150,
135
+ "temperature": 0.7
136
+ }
137
+ )
138
+ ```
139
+
140
+ ## With RAG Sources
141
+
142
+ ```python
143
+ client.ingest(
144
+ model="claude-3.5-haiku",
145
+ provider="anthropic",
146
+ input={
147
+ "prompt": "What does our refund policy say?",
148
+ "retrieved_sources": [
149
+ {"id": "doc-123", "content": "Refunds are available within 30 days..."},
150
+ {"id": "doc-456", "content": "Contact support for refund requests..."}
151
+ ]
152
+ },
153
+ output={"text": "According to our policy, refunds are available within 30 days..."}
154
+ )
155
+ ```
156
+
157
+ ## Enterprise Features
158
+
159
+ ```python
160
+ from driftrail import DriftRailEnterprise
161
+
162
+ client = DriftRailEnterprise(api_key="...", app_id="my-app")
163
+
164
+ # Incident management
165
+ stats = client.get_incident_stats()
166
+
167
+ # Compliance status
168
+ compliance = client.get_compliance_status()
169
+
170
+ # Model leaderboard
171
+ leaderboard = client.get_model_leaderboard(metric="avg_risk_score")
172
+
173
+ # Brand safety checks
174
+ violations = client.check_brand_safety("Some AI output text")
175
+ ```
176
+
177
+ ## Documentation
178
+
179
+ - [Full Documentation](https://docs.driftrail.com)
180
+ - [API Reference](https://docs.driftrail.com/api)
181
+ - [Dashboard](https://app.driftrail.com)
182
+ - [GitHub Repository](https://github.com/cutmob/DriftRail-Python)
183
+
184
+ ## License
185
+
186
+ MIT
@@ -0,0 +1,19 @@
1
+ """
2
+ DriftRail Python SDK
3
+ AI Safety & Observability Platform
4
+ """
5
+
6
+ from .client import DriftRail, DriftRailAsync, DriftRailEnterprise
7
+ from .types import IngestPayload, IngestResponse, Provider, GuardResult, GuardBlockedError
8
+
9
+ __version__ = "2.0.0"
10
+ __all__ = [
11
+ "DriftRail",
12
+ "DriftRailAsync",
13
+ "DriftRailEnterprise",
14
+ "IngestPayload",
15
+ "IngestResponse",
16
+ "Provider",
17
+ "GuardResult",
18
+ "GuardBlockedError",
19
+ ]