A Python package for performance monitoring, logging utilities, and code analysis
Project description
AI-powered observability and debugging toolkit for Python applications
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
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 sherlock_ai-1.13.8.tar.gz.
File metadata
- Download URL: sherlock_ai-1.13.8.tar.gz
- Upload date:
- Size: 34.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
051ae223ff34aa9917ebc95502ae24249befc5b14239228f4caad0ca3cf0b056
|
|
| MD5 |
c712fdf29913f2968b4ec3ed0dad61d6
|
|
| BLAKE2b-256 |
897fc287f4cf195cb069e2d31aaa0745acf7d0b5a8ca483c4d9626727d0708b8
|
Provenance
The following attestation bundles were made for sherlock_ai-1.13.8.tar.gz:
Publisher:
publish.yml on pranawmishra/sherlock-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sherlock_ai-1.13.8.tar.gz -
Subject digest:
051ae223ff34aa9917ebc95502ae24249befc5b14239228f4caad0ca3cf0b056 - Sigstore transparency entry: 1899978235
- Sigstore integration time:
-
Permalink:
pranawmishra/sherlock-ai@a3764858c8889f83a02e3a6ece96788f1ac73155 -
Branch / Tag:
refs/tags/v1.13.8 - Owner: https://github.com/pranawmishra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a3764858c8889f83a02e3a6ece96788f1ac73155 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sherlock_ai-1.13.8-py3-none-any.whl.
File metadata
- Download URL: sherlock_ai-1.13.8-py3-none-any.whl
- Upload date:
- Size: 44.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1695e9d9b57e43a32105abaa7d0869cfea5c7f9073c8e98e6ce10859e8e320f2
|
|
| MD5 |
d2c9cda64086064d712d40d8d8336ad5
|
|
| BLAKE2b-256 |
228ac93908b7f6695d3c617f421d0a45bf9c674536cff0da03eeea09e1f4cd77
|
Provenance
The following attestation bundles were made for sherlock_ai-1.13.8-py3-none-any.whl:
Publisher:
publish.yml on pranawmishra/sherlock-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sherlock_ai-1.13.8-py3-none-any.whl -
Subject digest:
1695e9d9b57e43a32105abaa7d0869cfea5c7f9073c8e98e6ce10859e8e320f2 - Sigstore transparency entry: 1899978375
- Sigstore integration time:
-
Permalink:
pranawmishra/sherlock-ai@a3764858c8889f83a02e3a6ece96788f1ac73155 -
Branch / Tag:
refs/tags/v1.13.8 - Owner: https://github.com/pranawmishra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a3764858c8889f83a02e3a6ece96788f1ac73155 -
Trigger Event:
release
-
Statement type: