A performance testing framework for Django that helps you understand and fix performance issues, not just detect them
Project description
Django Mercury
Part of the 80-20 Human in the Loop ecosystem
Test Django app speed. Learn why it's slow. Fix it.
Django Mercury is a performance testing framework that adapts to your experience level - teaching beginners, empowering experts, and enabling automation while preserving human understanding.
โก Quick Start
Install
pip install django-mercury-performance
Choose Your Profile
Mercury adapts to three audiences through its plugin system:
# ๐ Students - Learn while testing
mercury-test --profile student
# ๐ผ Experts - Fast and efficient
mercury-test --profile expert
# ๐ค Agents - Structured output for CI/CD
mercury-test --profile agent
Write Your First Test
# For investigation and learning
from django_mercury import DjangoMercuryAPITestCase
class QuickCheck(DjangoMercuryAPITestCase):
"""Mercury automatically monitors all tests in this class."""
def test_user_api(self):
response = self.client.get('/api/users/')
# Mercury detects issues and explains them!
# For production with specific assertions
from django_mercury import DjangoPerformanceAPITestCase
from django_mercury import monitor_django_view
class ProductionTests(DjangoPerformanceAPITestCase):
"""Enforce performance standards."""
def test_user_api_performance(self):
with monitor_django_view("user_api") as monitor:
response = self.client.get('/api/users/')
self.assertResponseTimeLess(monitor, 100) # Must be under 100ms
self.assertQueriesLess(monitor, 10) # Max 10 queries
self.assertNoNPlusOne(monitor) # No N+1 patterns
๐ Plugin Architecture
Mercury uses a small core, big plugin design that enables different experiences:
mercury-test --list-plugins
Available Plugins:
โ
discovery - Smart Django project finding
โ
wizard - Interactive test selection (students)
โ
learn - Quizzes and tutorials (students)
โ
hints - Performance tips (students)
Each profile automatically configures the right plugins:
- Student: All educational plugins enabled
- Expert: Minimal plugins for speed
- Agent: Non-interactive with JSON output
Learn more about the plugin system โ
๐ What Mercury Shows You
๐ Student Mode - Educational Output
๐ LEARNING MOMENT DETECTED
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Found: N+1 Query Pattern
Location: UserSerializer.get_profile_data()
๐ What's happening:
Your code makes 1 query to get users, then 1 query
per user to get profiles. With 100 users = 101 queries!
๐ก Why this matters:
Each query adds ~2ms overhead. This gets slower as
your data grows.
๐ง How to fix:
Add .select_related('profile') to your queryset:
User.objects.select_related('profile').all()
๐ Want to learn more?
Run: mercury-test --learn n1-queries
๐ผ Expert Mode - Concise Results
test_user_list 156ms 45q 23MB โ ๏ธ N+1@L45 SLOW
test_user_detail 23ms 3q 12MB โ
PASS
Critical: N+1 in views.py:45. Fix: select_related('profile')
๐ค Agent Mode - Structured JSON
{
"test": "test_user_list",
"metrics": {
"response_time_ms": 156,
"queries": 45,
"memory_mb": 23
},
"issues": [{
"type": "n_plus_one",
"severity": "high",
"location": "views.py:45",
"auto_fixable": false,
"requires_human_review": true
}]
}
๐ Educational Features
Mercury doesn't just find problems - it teaches you to understand them:
Interactive Learning
# Start learning mode
mercury-test --learn
# Take quizzes
mercury-test --learn --quiz
# Get step-by-step tutorials
mercury-test --learn n1-queries
Progress Tracking
mercury-test --learn --progress
๐ YOUR PROGRESS
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Level: Intermediate (750 XP)
Topics Mastered: N+1 Queries โ
, Indexing โ
Currently Learning: Caching (70%)
Next Goal: Complete Caching module
Real-time Teaching
When Mercury finds issues, it explains them in context, shows why they matter, and teaches you how to fix them.
๐ Performance Grading
Mercury grades your application's performance:
| Grade | Score | Meaning |
|---|---|---|
| S | 100 | Perfect performance |
| A+ | 95-99 | Excellent |
| A | 90-94 | Very good |
| B | 80-89 | Good |
| C | 70-79 | Acceptable |
| D | 60-69 | Poor |
| F | <60 | Failing |
๐ ๏ธ CI/CD Integration
# .github/workflows/performance.yml
name: Performance Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Mercury Tests
run: |
pip install django-mercury-performance
mercury-test --profile agent --export-metrics=json
- name: Check Performance
run: |
python -c "import json; exit(0 if json.load(open('metrics.json'))['grade'] >= 'B' else 1)"
๐ Documentation
- Quick Start Guide - Get running in 5 minutes
- Educational Mode - Learn performance optimization
- Understanding Reports - Interpret Mercury's output
- Plugin System - Extend Mercury's capabilities
- API Reference - Complete API documentation
๐ค Contributing
Mercury is part of the 80-20 Human-in-the-Loop ecosystem. We welcome contributions from everyone!
Our Values
- Education First: Tools should teach, not just detect
- Human Understanding: Preserve human decision-making
- Open Community: Built together, shared freely
How to Contribute
- Use Mercury - Test it on your projects
- Report Issues - Help us improve
- Share Knowledge - Write tutorials, create quizzes
- Code - Fix bugs, add features
- Translate - Make Mercury accessible globally
See CONTRIBUTING.md for details.
๐ง Roadmap
Current (v1.0)
- โ Three-audience plugin system
- โ Educational mode with quizzes
- โ Performance grading system
- โ N+1 detection
- โ Smart project discovery
Next (v1.1)
- ๐จ MCP server for AI integration
- ๐จ Performance trend tracking
- ๐จ Custom plugin API
- ๐จ More educational content
Future (v2.0)
- ๐ค AI-assisted optimization
- ๐ค Auto-fix for simple issues
- ๐ค Performance prediction
- ๐ค Team learning features
๐ License
GNU General Public License v3.0 (GPL-3.0)
We chose GPL to ensure Mercury remains:
- Free - No barriers to learning
- Open - Transparent development
- Fair - Improvements benefit everyone
๐ Acknowledgments
- EduLite - Where Mercury was born
- 80-20 Human-in-the-Loop - For the philosophy
- Django Community - For the amazing framework
- You - For making Django apps faster!
Mercury: Making performance testing educational, accessible, and effective.
Because every developer deserves to understand their code's performance.
Get Started โข Documentation โข Community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_mercury_performance-0.0.9b1.tar.gz.
File metadata
- Download URL: django_mercury_performance-0.0.9b1.tar.gz
- Upload date:
- Size: 194.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
969e0fcd1efd7efa97b5dd5885854de60f13f02d9cd72a439628c28b41d66a8c
|
|
| MD5 |
d260fd6334cd57d16f70f37a6fb85bde
|
|
| BLAKE2b-256 |
f5dbe895f66a4d57ce416ca8e80aca911c98b9a9f668c5e0d1878243906fba7f
|
File details
Details for the file django_mercury_performance-0.0.9b1-py3-none-any.whl.
File metadata
- Download URL: django_mercury_performance-0.0.9b1-py3-none-any.whl
- Upload date:
- Size: 217.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f348f0cf731134dfe3585cd9cb71a5c1fc46ac59198a4149ad2a6fe48196290
|
|
| MD5 |
e050c6f249c76415e83d577aac9a1662
|
|
| BLAKE2b-256 |
bc47060362dce1d2904fff2b7e999cf2a1b2482ddebdf6168b959d62253f780d
|