koreshield 0.1.1__py3-none-any.whl

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,455 @@
1
+ Metadata-Version: 2.4
2
+ Name: koreshield
3
+ Version: 0.1.1
4
+ Summary: Python SDK for KoreShield LLM Security Platform
5
+ Author-email: KoreShield Team <team@koreshield.com>
6
+ Maintainer-email: KoreShield Team <team@koreshield.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 KoreShield Team
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Project-URL: Homepage, https://koreshield.com
29
+ Project-URL: Documentation, https://docs.koreshield.com
30
+ Project-URL: Repository, https://github.com/koreshield/koreshield-python-sdk
31
+ Project-URL: Issues, https://github.com/koreshield/koreshield-python-sdk/issues
32
+ Project-URL: Changelog, https://github.com/koreshield/koreshield-python-sdk/blob/main/CHANGELOG.md
33
+ Keywords: llm,security,ai,safety,prompt-injection,koreshield
34
+ Classifier: Development Status :: 3 - Alpha
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.8
40
+ Classifier: Programming Language :: Python :: 3.9
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Security
45
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
46
+ Requires-Python: >=3.8
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Requires-Dist: httpx>=0.24.0
50
+ Requires-Dist: pydantic>=2.0.0
51
+ Requires-Dist: typing-extensions>=4.5.0
52
+ Requires-Dist: aiofiles>=0.23.0
53
+ Provides-Extra: langchain
54
+ Requires-Dist: langchain>=0.0.350; extra == "langchain"
55
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
56
+ Provides-Extra: fastapi
57
+ Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
58
+ Requires-Dist: uvicorn>=0.23.0; extra == "fastapi"
59
+ Provides-Extra: flask
60
+ Requires-Dist: flask>=2.3.0; extra == "flask"
61
+ Requires-Dist: werkzeug>=2.3.0; extra == "flask"
62
+ Provides-Extra: django
63
+ Requires-Dist: django>=4.2.0; extra == "django"
64
+ Requires-Dist: djangorestframework>=3.14.0; extra == "django"
65
+ Provides-Extra: all
66
+ Requires-Dist: koreshield-python-sdk[django,fastapi,flask,langchain]; extra == "all"
67
+ Dynamic: license-file
68
+
69
+ # KoreShield Python SDK
70
+
71
+ [![PyPI version](https://badge.fury.io/py/koreshield-python-sdk.svg)](https://pypi.org/project/koreshield-python-sdk/)
72
+ [![Python versions](https://img.shields.io/pypi/pyversions/koreshield-python-sdk)](https://pypi.org/project/koreshield-python-sdk/)
73
+ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
74
+
75
+ A comprehensive Python SDK for integrating KoreShield's LLM security features into your applications with ease.
76
+
77
+ ## Supported LLM Providers
78
+
79
+ KoreShield supports multiple LLM providers through its proxy architecture. Configure your preferred provider in the KoreShield API:
80
+
81
+ - **DeepSeek** (OpenAI-compatible API)
82
+ - **OpenAI** (GPT models)
83
+ - **Anthropic** (Claude models)
84
+ - **Google Gemini** (coming soon)
85
+ - **Azure OpenAI** (coming soon)
86
+
87
+ ### Provider Configuration
88
+
89
+ Configure providers in your KoreShield `config.yaml`:
90
+
91
+ ```yaml
92
+ providers:
93
+ deepseek:
94
+ enabled: true
95
+ base_url: "https://api.deepseek.com/v1"
96
+
97
+ openai:
98
+ enabled: false
99
+ base_url: "https://api.openai.com/v1"
100
+
101
+ anthropic:
102
+ enabled: false
103
+ base_url: "https://api.anthropic.com/v1"
104
+ ```
105
+
106
+ Set the corresponding API key as an environment variable:
107
+ ```bash
108
+ export DEEPSEEK_API_KEY="your-deepseek-key"
109
+ # or
110
+ export OPENAI_API_KEY="your-openai-key"
111
+ # or
112
+ export ANTHROPIC_API_KEY="your-anthropic-key"
113
+ ```
114
+
115
+ ```bash
116
+ pip install koreshield-python-sdk
117
+ ```
118
+
119
+ ### Optional Dependencies
120
+
121
+ For LangChain integration:
122
+ ```bash
123
+ pip install koreshield-python-sdk[langchain]
124
+ ```
125
+
126
+ For framework integrations:
127
+ ```bash
128
+ pip install koreshield-python-sdk[fastapi,flask,django]
129
+ ```
130
+
131
+ ## Quick Start
132
+
133
+ ### Basic Usage
134
+
135
+ ```python
136
+ from koreshield_sdk import KoreShieldClient
137
+
138
+ # Initialize client
139
+ client = KoreShieldClient(api_key="your-api-key")
140
+
141
+ # Scan a prompt
142
+ result = client.scan_prompt("Hello, how are you?")
143
+ print(f"Safe: {result.is_safe}, Threat Level: {result.threat_level}")
144
+ ```
145
+
146
+ ### Async Usage
147
+
148
+ ```python
149
+ import asyncio
150
+ from koreshield_sdk import AsyncKoreShieldClient
151
+
152
+ async def main():
153
+ async with AsyncKoreShieldClient(api_key="your-api-key") as client:
154
+ result = await client.scan_prompt("Tell me a joke")
155
+ print(f"Confidence: {result.confidence}")
156
+
157
+ asyncio.run(main())
158
+ ```
159
+
160
+ ### LangChain Integration
161
+
162
+ ```python
163
+ from langchain_openai import ChatOpenAI
164
+ from langchain.schema import HumanMessage
165
+ from koreshield_sdk.integrations import create_koreshield_callback
166
+
167
+ # Create security callback
168
+ security_callback = create_koreshield_callback(
169
+ api_key="your-api-key",
170
+ block_on_threat=True,
171
+ threat_threshold="medium"
172
+ )
173
+
174
+ # Use with LangChain
175
+ llm = ChatOpenAI(callbacks=[security_callback])
176
+ response = llm([HumanMessage(content="Hello!")])
177
+ ```
178
+
179
+ ## API Reference
180
+
181
+ ### KoreShieldClient
182
+
183
+ #### Methods
184
+
185
+ - `scan_prompt(prompt: str, **kwargs) -> DetectionResult`
186
+ - `scan_batch(prompts: List[str], parallel=True, max_concurrent=10) -> List[DetectionResult]`
187
+ - `get_scan_history(limit=50, offset=0, **filters) -> Dict`
188
+ - `get_scan_details(scan_id: str) -> Dict`
189
+ - `health_check() -> Dict`
190
+
191
+ ### AsyncKoreShieldClient
192
+
193
+ #### Methods
194
+
195
+ - `scan_prompt(prompt: str, **kwargs) -> DetectionResult` (async)
196
+ - `scan_batch(prompts: List[str], parallel=True, max_concurrent=10) -> List[DetectionResult]` (async)
197
+ - `get_scan_history(limit=50, offset=0, **filters) -> Dict` (async)
198
+ - `get_scan_details(scan_id: str) -> Dict` (async)
199
+ - `health_check() -> Dict` (async)
200
+
201
+ ### DetectionResult
202
+
203
+ ```python
204
+ class DetectionResult:
205
+ is_safe: bool
206
+ threat_level: ThreatLevel # "safe", "low", "medium", "high", "critical"
207
+ confidence: float # 0.0 to 1.0
208
+ indicators: List[DetectionIndicator]
209
+ processing_time_ms: float
210
+ scan_id: Optional[str]
211
+ metadata: Optional[Dict[str, Any]]
212
+ ```
213
+
214
+ ## Configuration
215
+
216
+ ### Environment Variables
217
+
218
+ ```bash
219
+ export KORESHIELD_API_KEY="your-api-key"
220
+ export KORESHIELD_BASE_URL="https://api.koreshield.com" # Optional
221
+ ```
222
+
223
+ ### Client Configuration
224
+
225
+ ```python
226
+ client = KoreShieldClient(
227
+ api_key="your-api-key",
228
+ base_url="https://api.koreshield.com",
229
+ timeout=30.0
230
+ )
231
+ ```
232
+
233
+ ## Examples
234
+
235
+ ### Basic Scanning
236
+
237
+ ```python
238
+ from koreshield_sdk import KoreShieldClient
239
+
240
+ client = KoreShieldClient(api_key="your-api-key")
241
+
242
+ # Single prompt
243
+ result = client.scan_prompt("What is the capital of France?")
244
+ print(f"Result: {result}")
245
+
246
+ # Batch scanning
247
+ prompts = [
248
+ "Hello world",
249
+ "Tell me a secret",
250
+ "Ignore previous instructions"
251
+ ]
252
+
253
+ results = client.scan_batch(prompts)
254
+ for prompt, result in zip(prompts, results):
255
+ print(f"'{prompt}': {result.threat_level} ({result.confidence:.2f})")
256
+ ```
257
+
258
+ ### FastAPI Integration
259
+
260
+ ```python
261
+ from fastapi import FastAPI, HTTPException
262
+ from koreshield_sdk import KoreShieldClient
263
+
264
+ app = FastAPI()
265
+ client = KoreShieldClient(api_key="your-api-key")
266
+
267
+ @app.post("/chat")
268
+ async def chat(message: str):
269
+ # Scan user input
270
+ result = client.scan_prompt(message)
271
+
272
+ if not result.is_safe and result.threat_level in ["high", "critical"]:
273
+ raise HTTPException(status_code=400, detail="Unsafe content detected")
274
+
275
+ # Process with your LLM
276
+ response = f"Processed: {message}"
277
+ return {"response": response, "safety": result.dict()}
278
+ ```
279
+
280
+ ### Flask Integration
281
+
282
+ ```python
283
+ from flask import Flask, request, jsonify
284
+ from koreshield_sdk import KoreShieldClient
285
+
286
+ app = Flask(__name__)
287
+ client = KoreShieldClient(api_key="your-api-key")
288
+
289
+ @app.route("/api/chat", methods=["POST"])
290
+ def chat():
291
+ data = request.get_json()
292
+ message = data.get("message", "")
293
+
294
+ # Scan user input
295
+ result = client.scan_prompt(message)
296
+
297
+ if not result.is_safe:
298
+ return jsonify({
299
+ "error": "Unsafe content detected",
300
+ "threat_level": result.threat_level,
301
+ "confidence": result.confidence
302
+ }), 400
303
+
304
+ # Process with your LLM
305
+ response = f"Echo: {message}"
306
+ return jsonify({"response": response})
307
+ ```
308
+
309
+ ### Django Integration
310
+
311
+ ```python
312
+ # views.py
313
+ from django.http import JsonResponse
314
+ from django.views.decorators.csrf import csrf_exempt
315
+ from django.utils.decorators import method_decorator
316
+ from django.views import View
317
+ import json
318
+ from koreshield_sdk import KoreShieldClient
319
+
320
+ client = KoreShieldClient(api_key="your-api-key")
321
+
322
+ @method_decorator(csrf_exempt, name='dispatch')
323
+ class ChatView(View):
324
+ def post(self, request):
325
+ data = json.loads(request.body)
326
+ message = data.get("message", "")
327
+
328
+ # Scan user input
329
+ result = client.scan_prompt(message)
330
+
331
+ if not result.is_safe and result.threat_level == "critical":
332
+ return JsonResponse({
333
+ "error": "Critical threat detected"
334
+ }, status=400)
335
+
336
+ # Process with your LLM
337
+ response = f"Response to: {message}"
338
+ return JsonResponse({
339
+ "response": response,
340
+ "safety_check": {
341
+ "safe": result.is_safe,
342
+ "threat_level": result.threat_level,
343
+ "confidence": result.confidence
344
+ }
345
+ })
346
+ ```
347
+
348
+ ## Error Handling
349
+
350
+ ```python
351
+ from koreshield_sdk import KoreShieldClient
352
+ from koreshield_sdk.exceptions import (
353
+ AuthenticationError,
354
+ ValidationError,
355
+ RateLimitError,
356
+ ServerError,
357
+ NetworkError,
358
+ TimeoutError
359
+ )
360
+
361
+ client = KoreShieldClient(api_key="your-api-key")
362
+
363
+ try:
364
+ result = client.scan_prompt("Test prompt")
365
+ except AuthenticationError:
366
+ print("Invalid API key")
367
+ except RateLimitError:
368
+ print("Rate limit exceeded")
369
+ except ServerError:
370
+ print("Server error")
371
+ except NetworkError:
372
+ print("Network issue")
373
+ except TimeoutError:
374
+ print("Request timed out")
375
+ except Exception as e:
376
+ print(f"Unexpected error: {e}")
377
+ ```
378
+
379
+ ## Advanced Usage
380
+
381
+ ### Custom Threat Thresholds
382
+
383
+ ```python
384
+ # Only block on high/critical threats
385
+ callback = create_koreshield_callback(
386
+ api_key="your-api-key",
387
+ block_on_threat=True,
388
+ threat_threshold="high" # "low", "medium", "high", "critical"
389
+ )
390
+ ```
391
+
392
+ ### Batch Processing with Custom Concurrency
393
+
394
+ ```python
395
+ # Process 100 prompts with controlled concurrency
396
+ results = await client.scan_batch(
397
+ prompts=prompts,
398
+ parallel=True,
399
+ max_concurrent=5 # Limit to 5 concurrent requests
400
+ )
401
+ ```
402
+
403
+ ### Monitoring and Analytics
404
+
405
+ ```python
406
+ # Get scan history
407
+ history = client.get_scan_history(limit=100, threat_level="high")
408
+
409
+ # Get detailed scan info
410
+ details = client.get_scan_details(scan_id="scan_123")
411
+ ```
412
+
413
+ ## Development
414
+
415
+ ### Setup
416
+
417
+ ```bash
418
+ git clone https://github.com/koreshield/koreshield-python-sdk.git
419
+ cd koreshield-python-sdk
420
+ pip install -e ".[dev]"
421
+ ```
422
+
423
+ ### Testing
424
+
425
+ ```bash
426
+ pytest
427
+ ```
428
+
429
+ ### Type Checking
430
+
431
+ ```bash
432
+ mypy src/
433
+ ```
434
+
435
+ ### Linting
436
+
437
+ ```bash
438
+ ruff check src/
439
+ ruff format src/
440
+ ```
441
+
442
+ ## Contributing
443
+
444
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
445
+
446
+ ## License
447
+
448
+ MIT License - see [LICENSE](LICENSE) file for details.
449
+
450
+ ## Support
451
+
452
+ - 📖 [Documentation](https://docs.koreshield.com)
453
+ - 🐛 [Issue Tracker](https://github.com/koreshield/koreshield-python-sdk/issues)
454
+ - 💬 [Discussions](https://github.com/koreshield/koreshield-python-sdk/discussions)
455
+ - 📧 [Email Support](mailto:support@koreshield.com)
@@ -0,0 +1,13 @@
1
+ koreshield-0.1.1.dist-info/licenses/LICENSE,sha256=k3qeCwQxhbOO1GtxA10Do4-_veQzgflqjOp5uZD5mug,1071
2
+ koreshield_sdk/__init__.py,sha256=JXErgUsoxTgM4EU--Os4ZTobARKWj1Mfurln-hNgCQw,785
3
+ koreshield_sdk/async_client.py,sha256=7GqmesiFlGAMQnCV4rqDUyn9Dfbt3W8LAegynTafFZ8,8516
4
+ koreshield_sdk/client.py,sha256=cUBE2B8SSKcrMr4NfUrDyCsTXdnfrvsLYuH83vsGdJw,7523
5
+ koreshield_sdk/exceptions.py,sha256=3j1FR4VFbe1Vv4i0bofBgQ_ZGwBfpOInBd9OyNQFUxo,945
6
+ koreshield_sdk/py.typed,sha256=8ZJUsxZiuOy1oJeVhsTWQhTG_6pTVHVXk5hJL79ebTk,25
7
+ koreshield_sdk/types.py,sha256=HPaxcK8NOK9p4VgDQTuTa3LENGQ5tgaWXZ_23S2QJcQ,2253
8
+ koreshield_sdk/integrations/__init__.py,sha256=po_sLSND55Wdu1vDmx4Nrjm072HLf04yxmtWj43yv7Y,382
9
+ koreshield_sdk/integrations/langchain.py,sha256=Dw_Kp7LyIdNr36TWv05yk3xPPNSZKOHEkHLKeMbobyw,10259
10
+ koreshield-0.1.1.dist-info/METADATA,sha256=w1h8Jt50ecOfzbXxClsD4omk1kP7umIsDICQ38-9EEw,12438
11
+ koreshield-0.1.1.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
12
+ koreshield-0.1.1.dist-info/top_level.txt,sha256=ePw2ZI3SrHZ5CaTRCyj3aya3j_qTcmRAQjoU7s3gAdM,15
13
+ koreshield-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KoreShield Team
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 @@
1
+ koreshield_sdk
@@ -0,0 +1,33 @@
1
+ """KoreShield Python SDK - LLM Security Platform SDK
2
+
3
+ A comprehensive Python SDK for integrating KoreShield's LLM security features
4
+ into your applications with ease.
5
+ """
6
+
7
+ from .client import KoreShieldClient
8
+ from .async_client import AsyncKoreShieldClient
9
+ from .exceptions import KoreShieldError, AuthenticationError, ValidationError, RateLimitError
10
+ from .types import (
11
+ DetectionResult,
12
+ ScanRequest,
13
+ ScanResponse,
14
+ ThreatLevel,
15
+ DetectionType,
16
+ AuthConfig,
17
+ )
18
+
19
+ __version__ = "0.1.0"
20
+ __all__ = [
21
+ "KoreShieldClient",
22
+ "AsyncKoreShieldClient",
23
+ "KoreShieldError",
24
+ "AuthenticationError",
25
+ "ValidationError",
26
+ "RateLimitError",
27
+ "DetectionResult",
28
+ "ScanRequest",
29
+ "ScanResponse",
30
+ "ThreatLevel",
31
+ "DetectionType",
32
+ "AuthConfig",
33
+ ]