Skip to main content

A performance testing framework for Django that helps you understand and fix performance issues, not just detect them

Project description

Django Mercury

PyPI version Python 3.10+ Django 3.2-5.1 License: GPL v3 Built for: EduLite Values: Open

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

๐Ÿค 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

  1. Use Mercury - Test it on your projects
  2. Report Issues - Help us improve
  3. Share Knowledge - Write tutorials, create quizzes
  4. Code - Fix bugs, add features
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_mercury_performance-0.1.0.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_mercury_performance-0.1.0-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file django_mercury_performance-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django_mercury_performance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a2f46fed6fb7799cb9ee940fa087b81f925a78bb01de4f376c6c753beaab868
MD5 b006a5ad6de839a96c391d1199fa8db0
BLAKE2b-256 449d8bea3f64db479bf8c066a0cc575fab6b103912e6ceeb45f7b1ce9e73dbc1

See more details on using hashes here.

File details

Details for the file django_mercury_performance-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_mercury_performance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a7a3724ac7dd531b450d10d2f7e38a7342e57fea6fd26c42eeb111fd4689e53
MD5 5c8dbebfc86b18c26e9fe4817596607d
BLAKE2b-256 535e9b9b906e3b6818c557f1b9efc3d5874322d2918f7595d290da37aa4cd7a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page