This directory contains example applications demonstrating various use cases of the Reflexive Python SDK.
# Install Reflexive CLI (Node.js)
npm install -g reflexive
# Run any example with full AI capabilities
reflexive --debug simple_app.py
reflexive --debug web_server.py
reflexive --debug data_pipeline.pyThis gives you:
- ✅ Full
.chat()functionality - ✅ Debugger with breakpoints
- ✅ Web dashboard
- ✅ Real-time log streaming
- ✅ State inspection
# Install Python SDK
pip install reflexive
# Run standalone (limited chat capabilities)
python simple_app.py
python web_server.py
python data_pipeline.pyWhat it demonstrates:
- Creating a Reflexive instance
- Setting and tracking state
- Logging events
- Using
.chat()to ask AI questions
Run it:
reflexive --debug simple_app.pyWhat to try:
- Watch the state updates in real-time
- See periodic AI analysis of application state
- Inspect logs through the dashboard
What it demonstrates:
- Using
.chat()to generate dynamic content - Building an AI-native web API
- Tracking request metrics
- Inline AI generation
Run it:
reflexive --debug web_server.pyTry these URLs:
- http://localhost:8080/
- http://localhost:8080/story?topic=space+adventure
- http://localhost:8080/story?topic=mystery+detective
What's cool:
- Each story is generated by AI on-the-fly
- The AI has context about your app's state
- You can ask the AI questions via the CLI
Example interaction:
User (via CLI): "How many stories have been generated?"
AI: "Based on the state, 5 stories have been generated so far."
What it demonstrates:
- Real-time monitoring of a data pipeline
- Using AI to analyze performance metrics
- Periodic health checks via
.chat() - Web UI for visualization
Run it:
reflexive --debug data_pipeline.pyFeatures:
- Simulates processing 100 data records
- Tracks success rate, errors, processing time
- AI analyzes performance every 20 records
- Full metrics available in web dashboard (http://localhost:3099)
What to watch for:
- How AI interprets error rates
- Performance recommendations from AI
- Real-time state updates
import reflexive
r = reflexive.make_reflexive()
# Generate content dynamically
def handle_request(topic):
content = r.chat(f'Write about: {topic}')
return contentUse cases:
- Content generation APIs
- Dynamic responses
- AI-assisted processing
import reflexive
r = reflexive.make_reflexive({'web_ui': True})
# Track application metrics
r.set_state('requests.count', count)
r.set_state('errors.rate', error_rate)
# Ask AI for insights
analysis = r.chat('Should I be concerned about the error rate?')Use cases:
- Application monitoring
- Performance analysis
- Anomaly detection
import reflexive
import time
r = reflexive.make_reflexive()
while processing:
process_batch()
if iteration % 10 == 0:
health = r.chat('Analyze system health')
if 'warning' in health.lower():
alert_team(health)Use cases:
- Background job monitoring
- ETL pipeline health
- System diagnostics
Keep state small and informative:
# Good: Metrics and counters
r.set_state('users.active', 42)
r.set_state('cache.hit_rate', 0.95)
# Bad: Large objects
r.set_state('all_users', huge_list) # Don't do this!Use structured logging:
r.log('info', f'Processing batch {id}: {count} records')
r.log('warn', f'Slow query detected: {query_time}ms')
r.log('error', f'Failed to connect: {error}')Be specific:
# Vague
r.chat('How are things?')
# Specific
r.chat('What is the error rate over the last 10 minutes?')
r.chat('Is memory usage trending up?')Cache AI responses when appropriate:
# Cache static content
@lru_cache(maxsize=100)
def get_ai_description(category):
return r.chat(f'Describe: {category}')- Try the examples with
reflexive --debug - Modify them to fit your use case
- Build your own AI-native app
- Read the docs at
../README.md
- 📚 Read the full API docs:
../README.md - 🏗️ Understand the design:
../DESIGN.md - 🆚 Compare with Node.js:
../COMPARISON.md - 💬 Ask the AI:
r.chat('How do I...')