Skip to content

Quick Start

smattymatty edited this page Aug 3, 2025 · 2 revisions

Quick Start Guide

Get Django Mercury running in your Django project in under 5 minutes.

Installation

pip install django-mercury-performance

Basic Usage

Option 1: Automatic Monitoring (Recommended for Beginners)

from django_mercury import DjangoMercuryAPITestCase

class UserAPITestCase(DjangoMercuryAPITestCase):
    def test_user_list(self):
        # Mercury automatically monitors this test
        response = self.client.get('/api/users/')
        self.assertEqual(response.status_code, 200)
        # Performance analysis happens automatically!

Option 2: Manual Control (For Experts)

from django_mercury import DjangoPerformanceAPITestCase, monitor_django_view

class AdvancedUserAPITestCase(DjangoPerformanceAPITestCase):
    def test_user_search_performance(self):
        with monitor_django_view("user_search") as monitor:
            response = self.client.get('/api/users/search/?q=john')
        
        # Make specific assertions
        self.assertResponseTimeLess(monitor, 100)  # Under 100ms
        self.assertQueriesLess(monitor, 10)        # Under 10 queries
        self.assertNoNPlusOne(monitor)             # No N+1 problems

What You'll See

When you run your tests, Mercury provides detailed performance feedback:

๐ŸŽจ MERCURY PERFORMANCE DASHBOARD - UserAPITestCase
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ ๐Ÿš€ Overall Status: EXCELLENT                                โ”‚
โ”‚ ๐ŸŽ“ Overall Grade: A (87.3/100)                             โ”‚
โ”‚ ๐Ÿ“Š Tests Executed: 3                                       โ”‚
โ”‚ โฑ๏ธ  Avg Response Time: 45.2ms                               โ”‚
โ”‚ ๐Ÿง  Avg Memory Usage: 12.1MB                                โ”‚
โ”‚ ๐Ÿ—ƒ๏ธ  Total Queries: 8 (2.7 avg)                             โ”‚
โ”‚ โœ… N+1 Issues: None detected                               โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Custom Configuration

class MyPerformanceTestCase(DjangoMercuryAPITestCase):
    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        
        # Configure Mercury behavior
        cls.configure_mercury(
            enabled=True,
            auto_scoring=True,
            educational_guidance=True
        )
        
        # Set performance thresholds
        cls.set_performance_thresholds({
            'response_time_ms': 200,    # Max 200ms
            'query_count_max': 15,      # Max 15 queries
            'memory_overhead_mb': 30,   # Max 30MB overhead
        })

Verification

Run your tests to verify Mercury is working:

python manage.py test

You should see Mercury's performance analysis in your test output!

Next Steps

Need Help?


Welcome to the Django Mercury community! ๐ŸŽ‰

Django Mercury Wiki

๐Ÿ  Overview

Clone this wiki locally