Skip to main content

Sherlock AI

AI-powered observability and debugging toolkit for Python applications

PyPI version Python versions MIT License


Documentation: https://docs.sherlockai.dev

Source Code: https://github.com/pranawmishra/sherlock-ai


What is Sherlock AI?

Sherlock AI is a Python observability toolkit that automatically monitors, logs, and analyzes your application — performance, memory, resources, and errors — with minimal setup. Drop in a decorator and you're done.

  • ⚡ Auto-Instrumentation — Zero-code setup for FastAPI (Sentry-style monkey-patching)
  • 🤖 AI-Powered Insights — Error analysis & performance suggestions via Groq or Azure OpenAI
  • 📊 Full-Stack Monitoring — Performance · Memory · CPU/I/O · Resources
  • 🗄️ Flexible Storage — MongoDB or HTTP API ingestion
  • 🔄 Async/Sync — Works seamlessly with both
  • 📋 JSON Logs — Structured output ready for log aggregators

Installation

pip install sherlock-ai

Quick Start

One-liner setup (FastAPI / any app)

from sherlock_ai import SherlockAI, LoggingConfig, get_logger

# Auto-instruments all FastAPI routes — do this BEFORE creating the app
SherlockAI(config=LoggingConfig(auto_instrument=True)).setup()

logger = get_logger(__name__)
from fastapi import FastAPI

app = FastAPI()

@app.get("/health")
def health_check():
    # ✅ Automatically monitored: performance, memory, resources, errors
    return {"status": "healthy"}

Decorator-based setup

from sherlock_ai import sherlock_ai, get_logger, log_performance
from sherlock_ai.monitoring import sherlock_error_handler

sherlock_ai()  # call once at startup
logger = get_logger(__name__)

@log_performance
@sherlock_error_handler
def process_data(user_id: str):
    logger.info("Processing user %s", user_id)
    return {"result": "ok"}

Core Features

Performance Monitoring

from sherlock_ai import log_performance, PerformanceTimer

@log_performance(min_duration=0.1, include_args=True)
def slow_query(user_id, limit=10):
    ...

with PerformanceTimer("batch_job"):
    run_batch()

Memory & Resource Monitoring

from sherlock_ai import monitor_memory, monitor_resources

@monitor_memory(trace_malloc=True)
@monitor_resources(include_io=True, include_network=True)
def heavy_computation():
    ...

AI Error Analysis

import os
from sherlock_ai.monitoring import sherlock_error_handler

os.environ["GROQ_API_KEY"] = "your-key"          # default provider
# os.environ["LLM_PROVIDER"] = "azure_openai"    # or Azure

@sherlock_error_handler
def risky_operation():
    return 1 / 0  # error auto-analyzed and stored

Configuration

Custom config

from sherlock_ai import SherlockAI, LoggingConfig, LogFileConfig

config = LoggingConfig(
    logs_dir="my_logs",
    log_format_type="json",          # creates .json files
    auto_instrument=True,
    log_files={
        "app":         LogFileConfig("application", max_bytes=100*1024*1024),
        "errors":      LogFileConfig("errors", level="ERROR"),
        "performance": LogFileConfig("perf"),
    }
)
SherlockAI(config).setup()

LLM Providers

Groq (default) Azure OpenAI
Env vars GROQ_API_KEY LLM_PROVIDER=azure_openai + 3 vars
Models Open-source (fast) GPT-3.5 / GPT-4
Best for Dev / small teams Enterprise
# Groq
export GROQ_API_KEY="gsk_..."

# Azure OpenAI
export LLM_PROVIDER="azure_openai"
export AZURE_OPENAI_API_KEY="..."
export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/"
export AZURE_OPENAI_DEPLOYMENT_NAME="gpt-4-turbo"

API / MongoDB storage

# Send insights to your own backend
export SHERLOCK_AI_API_KEY="your-key"
export SHERLOCK_AI_API_BASE_URL="https://your-backend.com/v1"  # optional

# Or use local MongoDB
export MONGO_URI="mongodb://localhost:27017"

Log Format

Standard

2025-07-15 20:51:19 - aa580b62 - PerformanceLogger - INFO - PERFORMANCE | my_module.fn | SUCCESS | 1.003s

JSON (log_format_type="json")

{"timestamp": "2025-07-15 20:51:19", "level": "INFO", "message": "PERFORMANCE | my_module.fn | SUCCESS | 1.003s", "request_id": "aa580b62"}

Requirements

  • Python ≥ 3.8
  • psutil · astor · groq · openai · pymongo · requests

Authors

Pranaw Mishra · pranawmishra73@gmail.com

Kunal Aggarwal · aggarwalkunu263@gmail.com


License

MIT

Metadata

Release files for sherlock-ai 1.14.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sherlock-ai 1.14.8
File Size Uploaded
sherlock_ai-1.14.8.tar.gz 34.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sherlock-ai 1.14.8
File Interpreter ABI Platform
sherlock_ai-1.14.8-py3-none-any.whl Python 3 none any Details

Total release size: 79.2 kB

Release files / sherlock_ai-1.14.8.tar.gz

Download URL sherlock_ai-1.14.8.tar.gz
Size 34.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8300a7ec7655b2c6a6cc45d5a6fd5f0d74055d4d58a3703b1c8303c99e486dbf
BLAKE2b-256 checksum
How to use checksums
1ba55112c07d092254897ce704004f652d850a9eedf08d663c77263bdf17ee7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.

Transparency log

Release files / sherlock_ai-1.14.8-py3-none-any.whl

Download URL sherlock_ai-1.14.8-py3-none-any.whl
Size 44.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24c248db4eba255d69544c68ddd4f81dcfa2c2c75bd6c64ab3c76840d1a6d587
BLAKE2b-256 checksum
How to use checksums
e6b9a244928ba59a732749a1f9952e257a2e55c480773780a2a7fbb0724c7fda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.14.8 This release

2 release files

1.13.8

2 release files

1.13.7

2 release files

1.13.3

2 release files

1.13.2

2 release files

1.13.1

2 release files

1.13.0

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.1

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page