Skip to main content

Simple, beautiful health checks for Python applications

Project description

✅ Allgreen - Python Health Checks Made Simple

Python 3.8+ License: MIT

Add quick, simple, and beautiful health checks to your Python application via a /healthcheck endpoint.

Perfect for monitoring application health, smoke testing, and ensuring your services are running properly in production.

Health Check Dashboard

🚀 Features

  • 🎯 Simple DSL - Define health checks in intuitive, readable Python
  • 🌐 Beautiful Web Dashboard - Responsive UI with automatic dark mode
  • ⚡ Fast & Lightweight - Minimal dependencies, maximum performance
  • ⏰ Timeout Protection - Prevent hanging checks with configurable timeouts
  • 🔄 Rate Limiting - Control expensive operations ("2 times per hour")
  • 🌍 Environment Conditions - Run checks only in specific environments
  • 💾 Result Caching - Cache expensive operations between rate-limited runs
  • 📊 Multiple Output Formats - HTML dashboard, JSON API, or both
  • 🔧 Framework Agnostic - Works with Flask, Django, FastAPI, or standalone

📦 Installation

pip install allgreen

🎯 Quick Start

1. Create your health checks

Create an allgood.py file in your project root:

# allgood.py

@check("Database connection is healthy")
def database_check():
    # Your database connection logic
    make_sure(db.is_connected(), "Database should be accessible")

@check("API response time is acceptable")
def api_performance_check():
    response_time = api.ping()
    expect(response_time).to_be_less_than(200)  # milliseconds

@check("Disk space is sufficient") 
def disk_space_check():
    usage_percent = get_disk_usage()
    expect(usage_percent).to_be_less_than(90)

2. Add to your web application

Flask:

from flask import Flask
from allgreen import mount_healthcheck

app = Flask(__name__)
mount_healthcheck(app, app_name="My API")

Django: Add to urls.py

from allgreen import create_app
from django.urls import path, include

healthcheck_app = create_app(app_name="My Django App")
urlpatterns = [
    path('healthcheck/', include(healthcheck_app)),
]

Standalone:

from allgreen import run_standalone
run_standalone(app_name="My Service", port=8080)

3. View your dashboard

Visit /healthcheck in your browser to see a beautiful dashboard, or add ?format=json for machine-readable output.

📚 Complete DSL Reference

Basic Assertions

@check("Basic truthiness check")
def basic_check():
    make_sure(True, "Custom failure message")
    make_sure(user.is_authenticated())

Expectation Methods

@check("Mathematical expectations")
def math_check():
    expect(2 + 2).to_eq(4)
    expect(api.response_time()).to_be_less_than(100)
    expect(database.connection_count()).to_be_greater_than(0)

⏰ Advanced Features

Timeout Protection

@check("Slow external service", timeout=30)  # 30 seconds max
def external_service_check():
    # This check will be terminated if it takes longer than 30 seconds
    response = external_api.health_check()
    make_sure(response.ok)

Rate Limiting for Expensive Operations

@check("Expensive API call", run="2 times per hour", timeout=60)
def expensive_check():
    # This check only runs twice per hour, caching results between runs
    result = paid_api.run_diagnostics()
    expect(result.status).to_eq("healthy")

@check("Daily backup verification", run="1 time per day")
def daily_backup_check():
    # Perfect for expensive operations that should only run occasionally
    backup_status = verify_backup_integrity()
    make_sure(backup_status.valid)

Supported rate limiting patterns:

  • "1 time per minute"
  • "5 times per hour"
  • "2 times per day"

Environment-Specific Checks

@check("Production database performance", only="production")
def prod_db_check():
    # Only runs in production environment
    expect(db.query_time()).to_be_less_than(10)

@check("Development tools available", except_env=["production", "staging"])
def dev_tools_check():
    # Skipped in production and staging
    make_sure(debug_tools.available())

@check("Conditional feature check", if_condition=lambda: feature_flag.enabled())
def feature_check():
    # Only runs when condition is true
    expect(new_feature.status()).to_eq("operational")

🌐 Web Interface

HTML Dashboard

Visit /healthcheck for a beautiful, responsive dashboard featuring:

  • ✅ Color-coded check results (pass/fail/skip)
  • 🌙 Automatic dark mode based on system preferences
  • ⏱️ Execution timing for each check
  • 📊 Summary statistics
  • 📱 Mobile-responsive design

JSON API

Access /healthcheck.json or /healthcheck?format=json for machine-readable output:

{
  "status": "passed",
  "environment": "production", 
  "stats": {
    "total": 8,
    "passed": 6,
    "failed": 1,
    "skipped": 1
  },
  "checks": [
    {
      "description": "Database connection",
      "status": "passed",
      "duration_ms": 23.4
    }
  ]
}

HTTP Status Codes

  • 200 OK - All checks passing
  • 503 Service Unavailable - One or more checks failing

Perfect for integration with monitoring tools like:

  • UptimeRobot
  • Pingdom
  • Datadog
  • Custom monitoring solutions

🔧 Framework Integration

Flask Application

from flask import Flask
from allgreen import mount_healthcheck

app = Flask(__name__)

# Mount health checks
mount_healthcheck(
    app, 
    app_name="My Flask API",
    config_path="config/allgood.py",
    environment="production"
)

if __name__ == '__main__':
    app.run()

Django Integration

# health/urls.py
from allgreen import create_app

healthcheck_app = create_app(
    app_name="My Django App",
    config_path="myapp/health_checks.py"
)

# main/urls.py  
urlpatterns = [
    path('health/', include('health.urls')),
]

FastAPI Integration

from fastapi import FastAPI
from allgreen import create_app

app = FastAPI()
healthcheck_app = create_app(app_name="My FastAPI")

app.mount("/health", healthcheck_app)

Standalone Server

from allgreen import run_standalone

if __name__ == "__main__":
    run_standalone(
        app_name="Health Check Service",
        config_path="checks/allgood.py", 
        host="0.0.0.0",
        port=8080,
        environment="production"
    )

📁 Examples

Check out the examples/ directory for complete working examples:

🧪 Configuration File Locations

Allgreen automatically looks for configuration files in these locations:

  1. allgood.py (project root)
  2. config/allgood.py
  3. Custom path via config_path parameter

🎛️ Environment Variables

  • ENVIRONMENT - Sets the environment for conditional checks (default: "development")

📊 Best Practices

✅ Good Health Check Examples

@check("Database queries are fast")
def db_performance():
    start = time.time()
    users = User.objects.all()[:10] 
    duration = (time.time() - start) * 1000
    expect(duration).to_be_less_than(100)  # under 100ms

@check("External API is responsive")  
def api_health():
    response = requests.get("https://api.example.com/health", timeout=5)
    expect(response.status_code).to_eq(200)
    
@check("Cache is working", run="5 times per hour")
def cache_check():
    cache.set('test_key', 'test_value')
    expect(cache.get('test_key')).to_eq('test_value')

❌ What to Avoid

  • Don't make checks that modify data
  • Avoid checks that depend on external timing
  • Don't put business logic in health checks
  • Avoid checks that could cause cascading failures

🔒 Security Notes

  • Health check endpoints don't require authentication by default
  • Consider restricting access in production environments
  • Avoid exposing sensitive system information in check descriptions
  • Rate limiting helps prevent abuse of expensive operations

🛠️ Development

git clone https://github.com/navinpai/allgreen
cd allgreen
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"

# Run tests
python -m pytest

# Run linting  
ruff check .

# Start example server
python test_server.py

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (python -m pytest)
  6. Run linting (ruff check .)
  7. Commit your changes (git commit -m 'Add amazing feature')
  8. Push to the branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

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

allgreen-0.1.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

allgreen-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: allgreen-0.1.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for allgreen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5c044cb052cec1f2b8a5f8341ab03c145645c35f92a6dd25a0b71ef102b5d56
MD5 fdb2ec6c1b6ebd6b3536ae93d1ad3fca
BLAKE2b-256 fec7edf747f9f2abde02ded8bda1201c3d444f3b85859fdf30224fe885e44406

See more details on using hashes here.

File details

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

File metadata

  • Download URL: allgreen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for allgreen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e8d47e92e0b06532c884a6ae361e94957444bde058c4c4d33d01106a05d49f4
MD5 1f94adbbb80dc4d91b05aa41f476f850
BLAKE2b-256 d8a2f9178aff598a76f97672a23f23afcb89363925d9916ac2021572143c937d

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