kalibr 1.0.9__tar.gz → 1.0.10__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,647 @@
1
+ # Kalibr SDK - Complete Multi-Model AI Integration Framework 🚀
2
+
3
+ ## Overview
4
+
5
+ **Kalibr** is an enhanced SDK that enables developers to build AI-integrated applications that automatically work with **all major AI models** from a single codebase. Write once, deploy anywhere, connect to any AI model.
6
+
7
+ ### The Problem Kalibr Solves
8
+
9
+ **Before Kalibr:**
10
+ ```
11
+ Developer needs AI integration →
12
+ ├── Build GPT Action (OpenAPI + auth + deployment)
13
+ ├── Build Claude MCP (WebSocket + JSON-RPC + hosting)
14
+ ├── Build Gemini Extension (Google format + infrastructure)
15
+ ├── Build Copilot Plugin (Microsoft schema + servers)
16
+ └── Build Future Model X (Unknown requirements + research)
17
+ = Months of work, 5+ codebases, complex infrastructure
18
+ ```
19
+
20
+ **With Kalibr SDK:**
21
+ ```python
22
+ # Write once
23
+ from kalibr import KalibrApp
24
+
25
+ app = KalibrApp("My Business API")
26
+
27
+ @app.action("analyze_data", "Analyze business data")
28
+ def analyze(data: str) -> dict:
29
+ return {"analysis": my_business_logic(data)}
30
+
31
+ # Deploy once
32
+ kalibr deploy my_app.py --platform fly --name my-api
33
+
34
+ # All AI models supported automatically:
35
+ ✅ GPT Actions: https://my-api.fly.dev/openapi.json
36
+ ✅ Claude MCP: https://my-api.fly.dev/mcp.json
37
+ ✅ Gemini: https://my-api.fly.dev/schemas/gemini
38
+ ✅ Copilot: https://my-api.fly.dev/schemas/copilot
39
+ ```
40
+
41
+ ## 🎯 Key Features
42
+
43
+ ### ✅ 1. Multi-Model AI Integration
44
+ - **GPT Actions** - Automatic OpenAPI 3.0 schema generation
45
+ - **Claude MCP** - WebSocket-compatible JSON-RPC manifests
46
+ - **Gemini Extensions** - Google's extension format
47
+ - **Microsoft Copilot** - Plugin schema generation
48
+ - **Future Models** - Extensible architecture for new AI platforms
49
+
50
+ ### ✅ 2. Enhanced App-Level Capabilities
51
+ - **File Upload Handling** - Multi-format validation and processing
52
+ - **Session Management** - Stateful interactions across requests
53
+ - **Streaming Responses** - Real-time data streaming
54
+ - **Complex Workflows** - Multi-step processing with state tracking
55
+ - **Advanced Data Types** - Files, images, tables, custom objects
56
+
57
+ ### ✅ 3. Built-in Authentication System
58
+ - **JWT Token Management** - Secure authentication helpers
59
+ - **User Management** - Built-in user stores (in-memory, database)
60
+ - **Protected Routes** - Easy auth decorators and middleware
61
+ - **Multiple Backends** - MongoDB, PostgreSQL, or custom implementations
62
+
63
+ ### ✅ 4. Deployment Automation
64
+ - **Fly.io Integration** - One-command deployment to Fly.io
65
+ - **AWS Lambda** - Serverless deployment support
66
+ - **Docker Generation** - Automatic Dockerfile creation
67
+ - **Environment Management** - Configuration and secrets handling
68
+
69
+ ### ✅ 5. Built-in Analytics & Logging
70
+ - **Automatic Tracking** - Every API call logged automatically
71
+ - **Performance Metrics** - Response times, success rates, error tracking
72
+ - **Custom Events** - Track business-specific analytics
73
+ - **Multiple Storage** - File, memory, or database backends
74
+
75
+ ## 🚀 Quick Start
76
+
77
+ ### Installation
78
+ ```bash
79
+ pip install kalibr
80
+ ```
81
+
82
+ ### Create Your First App
83
+ ```bash
84
+ # Generate a starter app
85
+ kalibr init --template basic --name "My API"
86
+
87
+ # Or create enhanced app with all features
88
+ kalibr init --template enhanced --name "My Enhanced API"
89
+ ```
90
+
91
+ ### Basic Example
92
+ ```python
93
+ from kalibr import Kalibr
94
+
95
+ app = Kalibr(title="My Business API")
96
+
97
+ @app.action("hello", "Greet someone")
98
+ def hello(name: str = "World"):
99
+ return {"message": f"Hello, {name}!"}
100
+
101
+ @app.action("analyze_sentiment", "Analyze text sentiment")
102
+ def analyze_sentiment(text: str):
103
+ # Your business logic here
104
+ sentiment = "positive" if "good" in text.lower() else "negative"
105
+ return {"text": text, "sentiment": sentiment, "confidence": 0.95}
106
+ ```
107
+
108
+ ### Enhanced Example with All Features
109
+ ```python
110
+ from kalibr import KalibrApp
111
+ from kalibr.types import FileUpload, Session, StreamingResponse
112
+ from kalibr.auth_helpers import kalibr_auth, KalibrAuth, InMemoryUserStore
113
+ from kalibr.analytics import kalibr_analytics
114
+
115
+ @kalibr_auth("your-secret-key")
116
+ @kalibr_analytics(storage="file", auto_track=True)
117
+ class MyEnhancedApp(KalibrApp):
118
+ def __init__(self):
119
+ super().__init__(title="Enhanced Business API")
120
+
121
+ # Setup authentication
122
+ self.auth = KalibrAuth("your-secret-key")
123
+ self.user_store = InMemoryUserStore()
124
+
125
+ app = MyEnhancedApp()
126
+
127
+ # File upload handler
128
+ @app.file_handler("analyze_document", [".txt", ".pdf", ".docx"])
129
+ async def analyze_document(file: FileUpload):
130
+ content = file.content.decode('utf-8')
131
+
132
+ # Your document analysis logic
133
+ word_count = len(content.split())
134
+
135
+ return {
136
+ "filename": file.filename,
137
+ "word_count": word_count,
138
+ "analysis": "Document processed successfully",
139
+ "upload_id": file.upload_id
140
+ }
141
+
142
+ # Session-aware action
143
+ @app.session_action("save_analysis", "Save analysis to user session")
144
+ async def save_analysis(session: Session, analysis_result: dict):
145
+ session.set("last_analysis", analysis_result)
146
+ session.set("analysis_count", session.get("analysis_count", 0) + 1)
147
+
148
+ return {
149
+ "saved": True,
150
+ "session_id": session.session_id,
151
+ "total_analyses": session.get("analysis_count")
152
+ }
153
+
154
+ # Streaming action
155
+ @app.stream_action("process_large_dataset", "Process large dataset with progress")
156
+ async def process_large_dataset(dataset_size: int = 100):
157
+ for i in range(dataset_size):
158
+ # Simulate processing
159
+ processed_item = {"item_id": i, "processed_at": "2024-01-01T00:00:00Z"}
160
+
161
+ yield {
162
+ "progress": (i + 1) / dataset_size * 100,
163
+ "item": processed_item,
164
+ "remaining": dataset_size - i - 1
165
+ }
166
+
167
+ await asyncio.sleep(0.1) # Simulate processing time
168
+
169
+ # Protected action requiring authentication
170
+ @app.action("get_private_data", "Get user's private data")
171
+ async def get_private_data(current_user = Depends(app.auth.create_auth_dependency(app.user_store.get_user))):
172
+ return {
173
+ "message": f"Private data for {current_user.username}",
174
+ "user_id": current_user.id,
175
+ "account_type": "premium"
176
+ }
177
+ ```
178
+
179
+ ## 📦 Development Workflow
180
+
181
+ ### 1. Local Development
182
+ ```bash
183
+ # Test your app locally
184
+ kalibr serve my_app.py
185
+
186
+ # Available at:
187
+ # • http://localhost:8000/docs (Swagger UI)
188
+ # • http://localhost:8000/mcp.json (Claude MCP)
189
+ # • http://localhost:8000/openapi.json (GPT Actions)
190
+ # • http://localhost:8000/schemas/gemini (Gemini)
191
+ # • http://localhost:8000/schemas/copilot (Copilot)
192
+ ```
193
+
194
+ ### 2. Platform Setup
195
+ ```bash
196
+ # Setup deployment platform
197
+ kalibr setup fly
198
+ kalibr setup aws
199
+
200
+ # Or list available platforms
201
+ kalibr list-platforms
202
+ ```
203
+
204
+ ### 3. Deployment
205
+ ```bash
206
+ # Deploy to Fly.io
207
+ kalibr deploy my_app.py --platform fly --name my-api
208
+
209
+ # Deploy to AWS Lambda
210
+ kalibr deploy my_app.py --platform aws-lambda --name my-api
211
+
212
+ # Deploy with environment variables
213
+ kalibr deploy my_app.py --platform fly --name my-api --env-file .env
214
+ ```
215
+
216
+ ### 4. Monitoring
217
+ ```bash
218
+ # Check deployment status
219
+ kalibr status https://my-api.fly.dev
220
+
221
+ # Test all endpoints
222
+ kalibr test --url https://my-api.fly.dev
223
+ ```
224
+
225
+ ## 🤖 AI Model Integration
226
+
227
+ Once deployed, your Kalibr app automatically provides schemas for all major AI models:
228
+
229
+ ### GPT Actions Integration
230
+ ```json
231
+ GET https://your-app.fly.dev/openapi.json
232
+
233
+ {
234
+ "openapi": "3.0.0",
235
+ "info": {"title": "My API", "version": "1.0.0"},
236
+ "servers": [{"url": "https://your-app.fly.dev"}],
237
+ "paths": {
238
+ "/proxy/analyze_sentiment": {
239
+ "post": {
240
+ "operationId": "analyze_sentiment",
241
+ "requestBody": {
242
+ "content": {
243
+ "application/json": {
244
+ "schema": {
245
+ "type": "object",
246
+ "properties": {"text": {"type": "string"}},
247
+ "required": ["text"]
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ }
256
+ ```
257
+
258
+ ### Claude MCP Integration
259
+ ```json
260
+ GET https://your-app.fly.dev/mcp.json
261
+
262
+ {
263
+ "mcp": "1.0",
264
+ "name": "my-api",
265
+ "tools": [{
266
+ "name": "analyze_sentiment",
267
+ "description": "Analyze text sentiment",
268
+ "input_schema": {
269
+ "type": "object",
270
+ "properties": {"text": {"type": "string"}},
271
+ "required": ["text"]
272
+ },
273
+ "server": {"url": "https://your-app.fly.dev/proxy/analyze_sentiment"}
274
+ }]
275
+ }
276
+ ```
277
+
278
+ ### Usage in AI Models
279
+ **GPT Custom Actions:**
280
+ 1. Copy OpenAPI schema from `/openapi.json`
281
+ 2. Create new GPT Action
282
+ 3. Paste schema and set base URL
283
+
284
+ **Claude Desktop MCP:**
285
+ ```json
286
+ {
287
+ "mcp": {
288
+ "servers": {
289
+ "my-business-api": {
290
+ "command": "curl",
291
+ "args": ["https://your-app.fly.dev/mcp.json"]
292
+ }
293
+ }
294
+ }
295
+ }
296
+ ```
297
+
298
+ ## 🔒 Authentication & Security
299
+
300
+ ### Built-in Authentication
301
+ ```python
302
+ from kalibr.auth_helpers import KalibrAuth, InMemoryUserStore
303
+
304
+ # Initialize authentication
305
+ auth = KalibrAuth(secret_key="your-secret-key")
306
+ user_store = InMemoryUserStore()
307
+
308
+ # Create auth dependency
309
+ get_current_user = auth.create_auth_dependency(user_store.get_user)
310
+
311
+ @app.action("protected_action", "Requires authentication")
312
+ async def protected_action(current_user = Depends(get_current_user)):
313
+ return {"message": f"Hello {current_user.username}"}
314
+ ```
315
+
316
+ ### User Management
317
+ ```python
318
+ # Register users
319
+ @app.action("register", "Register new user")
320
+ async def register(username: str, email: str, password: str):
321
+ user = user_store.create_user(username, email, password)
322
+ token = auth.create_access_token({"sub": user.id})
323
+ return {"user": user, "token": token}
324
+
325
+ # Login
326
+ @app.action("login", "User login")
327
+ async def login(email: str, password: str):
328
+ user = user_store.get_user_by_email(email)
329
+ if user and user_store.verify_password(user.id, password):
330
+ token = auth.create_access_token({"sub": user.id})
331
+ return {"token": token}
332
+ raise HTTPException(401, "Invalid credentials")
333
+ ```
334
+
335
+ ### Database Integration
336
+ ```python
337
+ from kalibr.auth_helpers import MongoUserStore
338
+
339
+ # Use MongoDB for user storage
340
+ user_store = MongoUserStore(database)
341
+
342
+ # Or implement your own
343
+ class CustomUserStore(DatabaseUserStore):
344
+ async def create_user(self, username, email, hashed_password):
345
+ # Your implementation
346
+ pass
347
+ ```
348
+
349
+ ## 📊 Analytics & Monitoring
350
+
351
+ ### Automatic Analytics
352
+ ```python
353
+ from kalibr.analytics import kalibr_analytics
354
+
355
+ @kalibr_analytics(storage="file", auto_track=True)
356
+ class MyApp(KalibrApp):
357
+ pass
358
+
359
+ app = MyApp()
360
+
361
+ # All actions automatically tracked for:
362
+ # • Response times
363
+ # • Success/error rates
364
+ # • Usage patterns
365
+ # • User analytics
366
+ ```
367
+
368
+ ### Custom Analytics
369
+ ```python
370
+ @app.action("business_action", "Track custom business metrics")
371
+ def business_action(data: str):
372
+ # Your business logic
373
+ result = process_data(data)
374
+
375
+ # Record custom analytics
376
+ app.record_custom_event("business_process",
377
+ data_size=len(data),
378
+ result_type=result.get("type"),
379
+ processing_time=result.get("duration"))
380
+
381
+ return result
382
+
383
+ # Get analytics
384
+ @app.action("get_analytics", "View app analytics")
385
+ def get_analytics():
386
+ return app.get_analytics()
387
+ ```
388
+
389
+ ### Analytics Backends
390
+ ```python
391
+ # File storage (default)
392
+ @kalibr_analytics(storage="file")
393
+
394
+ # Memory storage (development)
395
+ @kalibr_analytics(storage="memory")
396
+
397
+ # Database storage
398
+ from kalibr.analytics import MongoAnalyticsBackend
399
+ analytics_backend = MongoAnalyticsBackend(database)
400
+ ```
401
+
402
+ ## 🏗️ Advanced Features
403
+
404
+ ### Complex Workflows
405
+ ```python
406
+ @app.workflow("data_pipeline", "Multi-step data processing pipeline")
407
+ async def data_pipeline(input_data: dict, workflow_state):
408
+ # Step 1: Validation
409
+ workflow_state.step = "validation"
410
+ if not validate_input(input_data):
411
+ workflow_state.status = "error"
412
+ return {"error": "Invalid input"}
413
+
414
+ # Step 2: Processing
415
+ workflow_state.step = "processing"
416
+ processed = await process_data_async(input_data)
417
+ workflow_state.data["processed_records"] = len(processed)
418
+
419
+ # Step 3: Output
420
+ workflow_state.step = "output_generation"
421
+ result = generate_output(processed)
422
+
423
+ workflow_state.step = "completed"
424
+ workflow_state.status = "success"
425
+
426
+ return {
427
+ "workflow_id": workflow_state.workflow_id,
428
+ "result": result,
429
+ "records_processed": len(processed)
430
+ }
431
+ ```
432
+
433
+ ### File Processing
434
+ ```python
435
+ @app.file_handler("process_csv", [".csv", ".xlsx"])
436
+ async def process_csv(file: FileUpload):
437
+ import pandas as pd
438
+ import io
439
+
440
+ # Read file content
441
+ if file.filename.endswith('.csv'):
442
+ df = pd.read_csv(io.StringIO(file.content.decode('utf-8')))
443
+ else:
444
+ df = pd.read_excel(io.BytesIO(file.content))
445
+
446
+ # Process data
447
+ summary = {
448
+ "filename": file.filename,
449
+ "rows": len(df),
450
+ "columns": len(df.columns),
451
+ "column_names": list(df.columns),
452
+ "data_types": df.dtypes.to_dict(),
453
+ "summary_stats": df.describe().to_dict()
454
+ }
455
+
456
+ return summary
457
+ ```
458
+
459
+ ### Real-time Streaming
460
+ ```python
461
+ @app.stream_action("live_data_feed", "Stream live data updates")
462
+ async def live_data_feed(source: str = "default"):
463
+ import asyncio
464
+
465
+ for i in range(100):
466
+ # Simulate real-time data
467
+ data_point = {
468
+ "timestamp": datetime.now().isoformat(),
469
+ "source": source,
470
+ "value": random.random() * 100,
471
+ "sequence": i
472
+ }
473
+
474
+ yield data_point
475
+ await asyncio.sleep(0.5)
476
+ ```
477
+
478
+ ## 🚀 Deployment Options
479
+
480
+ ### Fly.io (Recommended)
481
+ ```bash
482
+ # Setup
483
+ kalibr setup fly
484
+
485
+ # Deploy
486
+ kalibr deploy my_app.py --platform fly --name my-api
487
+
488
+ # Results in:
489
+ # ✅ https://my-api.fly.dev/openapi.json
490
+ # ✅ https://my-api.fly.dev/mcp.json
491
+ # ✅ Automatic SSL, global CDN, scaling
492
+ ```
493
+
494
+ ### AWS Lambda
495
+ ```bash
496
+ # Setup
497
+ kalibr setup aws
498
+
499
+ # Deploy
500
+ kalibr deploy my_app.py --platform aws-lambda --name my-api
501
+
502
+ # Results in:
503
+ # ✅ https://my-api.lambda-url.us-east-1.on.aws/
504
+ # ✅ Serverless, pay-per-use, automatic scaling
505
+ ```
506
+
507
+ ### Docker (Self-hosted)
508
+ ```python
509
+ # Kalibr automatically generates Dockerfile
510
+ FROM python:3.11-slim
511
+ WORKDIR /app
512
+ RUN pip install kalibr
513
+ COPY my_app.py .
514
+ EXPOSE 8000
515
+ CMD ["kalibr", "serve", "my_app.py", "--host", "0.0.0.0"]
516
+ ```
517
+
518
+ ## 📚 CLI Reference
519
+
520
+ ```bash
521
+ # App Creation
522
+ kalibr init # Basic app
523
+ kalibr init --template enhanced # Enhanced app with all features
524
+ kalibr init --template auth # App with authentication
525
+ kalibr init --template analytics # App with built-in analytics
526
+
527
+ # Development
528
+ kalibr serve my_app.py # Run locally
529
+ kalibr test --url http://localhost:8000 # Test endpoints
530
+
531
+ # Deployment
532
+ kalibr setup fly # Setup Fly.io
533
+ kalibr setup aws # Setup AWS
534
+ kalibr list-platforms # Show available platforms
535
+ kalibr deploy my_app.py --platform fly --name my-api
536
+ kalibr status https://my-api.fly.dev
537
+ kalibr version # Show SDK version
538
+ ```
539
+
540
+ ## 🎯 Use Cases
541
+
542
+ ### Business API Integration
543
+ ```python
544
+ # Customer service chatbot backend
545
+ @app.action("get_customer_info", "Get customer information")
546
+ def get_customer_info(customer_id: str):
547
+ return database.get_customer(customer_id)
548
+
549
+ @app.action("create_support_ticket", "Create support ticket")
550
+ def create_support_ticket(customer_id: str, issue: str, priority: str = "medium"):
551
+ return support_system.create_ticket(customer_id, issue, priority)
552
+ ```
553
+
554
+ ### Data Analysis Service
555
+ ```python
556
+ # Data analysis API for AI models
557
+ @app.action("analyze_sales_data", "Analyze sales performance")
558
+ def analyze_sales_data(start_date: str, end_date: str, region: str = "all"):
559
+ data = get_sales_data(start_date, end_date, region)
560
+ return {
561
+ "revenue": calculate_revenue(data),
562
+ "growth": calculate_growth(data),
563
+ "trends": identify_trends(data)
564
+ }
565
+ ```
566
+
567
+ ### Document Processing
568
+ ```python
569
+ # Document processing service
570
+ @app.file_handler("analyze_contract", [".pdf", ".docx"])
571
+ async def analyze_contract(file: FileUpload):
572
+ text = extract_text(file.content)
573
+ return {
574
+ "key_terms": extract_terms(text),
575
+ "risks": identify_risks(text),
576
+ "summary": generate_summary(text)
577
+ }
578
+ ```
579
+
580
+ ### Workflow Automation
581
+ ```python
582
+ # Multi-step business process
583
+ @app.workflow("order_processing", "Complete order processing workflow")
584
+ async def order_processing(order_data: dict, workflow_state):
585
+ # Validate → Payment → Inventory → Shipping → Notification
586
+ # Full workflow with state tracking and error handling
587
+ pass
588
+ ```
589
+
590
+ ## 🔮 Roadmap
591
+
592
+ ### Current Version (2.0.0)
593
+ - ✅ Multi-model AI integration (GPT, Claude, Gemini, Copilot)
594
+ - ✅ Enhanced app-level framework
595
+ - ✅ Built-in authentication system
596
+ - ✅ Deployment automation (Fly.io, AWS)
597
+ - ✅ Analytics and logging
598
+ - ✅ Comprehensive CLI tools
599
+
600
+ ### Coming Soon
601
+ - 🔄 **More AI Models**: Anthropic Computer Use, Mistral, Local models
602
+ - 🔄 **Advanced Auth**: OAuth, SSO, API key management
603
+ - 🔄 **More Platforms**: Google Cloud Run, Azure Functions, Railway
604
+ - 🔄 **Enhanced Analytics**: Real-time dashboards, billing integration
605
+ - 🔄 **Developer Tools**: VS Code extension, debugging tools
606
+
607
+ ## 💝 Why Choose Kalibr SDK?
608
+
609
+ ### ✅ **Developer Experience First**
610
+ - **Single Codebase** → All AI models supported
611
+ - **Zero Configuration** → Works out of the box
612
+ - **Production Ready** → Authentication, analytics, deployment included
613
+ - **Type Safe** → Full Python type hints and auto-completion
614
+
615
+ ### ✅ **Future Proof**
616
+ - **Extensible Architecture** → Easy to add new AI models
617
+ - **Backward Compatible** → Your apps keep working as we add features
618
+ - **Open Source** → Community-driven development
619
+ - **Active Development** → Regular updates and new features
620
+
621
+ ### ✅ **Production Scale**
622
+ - **Performance Optimized** → Async/await throughout
623
+ - **Secure by Default** → Built-in auth, input validation, error handling
624
+ - **Monitoring Included** → Analytics, logging, health checks
625
+ - **Deployment Ready** → One command to production
626
+
627
+ ---
628
+
629
+ ## 🚀 Get Started Now
630
+
631
+ ```bash
632
+ # Install the SDK
633
+ pip install kalibr
634
+
635
+ # Create your first app
636
+ kalibr init --template enhanced --name "My AI API"
637
+
638
+ # Test locally
639
+ kalibr serve enhanced_app.py
640
+
641
+ # Deploy to production
642
+ kalibr deploy enhanced_app.py --platform fly --name my-ai-api
643
+
644
+ # Connect to any AI model instantly!
645
+ ```
646
+
647
+ **Transform how you build AI-integrated applications with Kalibr SDK! 🎯**
@@ -1,8 +1,5 @@
1
- include LICENSE.txt
2
1
  include README.md
3
- include pyproject.toml
4
- include setup.py
5
- recursive-include kalibr *.py
2
+ include LICENSE.txt
3
+ include KALIBR_SDK_COMPLETE.md
6
4
  recursive-include examples *.py
7
- recursive-include docs *
8
5
  global-exclude __pycache__ *.py[cod] .DS_Store