Skip to main content

A package for capturing and comparing function input/output snapshots

Reason this release was yanked:

contained bug for multiple calls

Project description

Detective Snapshot 🕵️‍♂️🔍

A Python package for capturing function input/output snapshots. Perfect for debugging, testing, and understanding complex function call hierarchies.

Features

  • 📸 Capture function inputs and outputs
  • 🌳 Track nested function calls
  • 🎯 Select specific fields to snapshot
  • 📦 Support for Python objects, dataclasses, and protobufs

Install

pip install detective-snapshot

Quick Start

from detective import snapshot

@snapshot()
def calculate_cat_food(cats):
    total = sum(get_cat_appetite(cat) for cat in cats)
    return f"Need {total}oz of food per day"

@snapshot()
def get_cat_appetite(cat):
    # Cats eat about 0.5oz per pound of weight
    return cat["weight"] * 0.5

# Feed the kitties
cats = [
    {"name": "Whiskers", "weight": 10},
    {"name": "Chonk", "weight": 15}
]
result = calculate_cat_food(cats)

With debug mode on, each call to an outermost decorated function creates a new snapshot file in ./debug_snapshots/ with a unique UUID:

{
    "FUNCTION": "calculate_cat_food",
    "INPUTS": {
        "cats": [
            {"name": "Whiskers", "weight": 10},
            {"name": "Chonk", "weight": 15}
        ]
    },
    "OUTPUT": "Need 12.5oz of food per day",
    "CALLS": [
        {
            "FUNCTION": "get_cat_appetite",
            "INPUTS": {"cat": {"name": "Whiskers", "weight": 10}},
            "OUTPUT": 5.0
        },
        {
            "FUNCTION": "get_cat_appetite",
            "INPUTS": {"cat": {"name": "Chonk", "weight": 15}},
            "OUTPUT": 7.5
        }
    ]
}

Field Selection

Capture only the fields you care about:

@snapshot(
    input_fields=["cat.name", "cat.weight"],
    output_fields=["daily_food"]
)
def calculate_cat_diet(cat):
    daily_food = cat["weight"] * 0.5
    return {"daily_food": daily_food, "feeding_schedule": "twice daily"}

Selection Patterns

Pattern Example Description
Direct Field name Select a field directly from root
Nested Field cat.weight Navigate through nested objects
Array Index cats[0].name Select specific array element
Array Wildcard cats[*].weight Select field from all array elements
Multiple Fields cat.(name,weight) Select multiple fields from an object
Wildcard Object pets.*.name Select field from all child objects
Args Syntax args[0].name Select from function arguments
Mixed Access pets[*].records.*.weight Combine array and object access

Full JSONPath support is also available for more complex queries.

Advanced Usage

Capture Complex Objects

@dataclass
class Cat:
    name: str
    breed: str
    medical_records: List[Record]

@snapshot(input_fields=["cat.medical_records[*].weight"])
def track_weight_history(cat: Cat):
    return [record.weight for record in cat.medical_records]

Handle Nested Function Calls

@snapshot()
def process_cattery(cattery):
    cats = get_cats(cattery.id)
    return categorize_cats(cats)

@snapshot()
def get_cats(cattery_id):
    return ["Whiskers", "Chonk"]

@snapshot()
def categorize_cats(cats):
    return {"chonky": cats}

The debug file will include the complete call hierarchy with inputs and outputs for each function.

Contributing

Contributions are welcome! Please check out our Contributing Guide for details.

License

MIT License - see LICENSE

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

detective_snapshot-0.1.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

detective_snapshot-0.1.2-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file detective_snapshot-0.1.2.tar.gz.

File metadata

  • Download URL: detective_snapshot-0.1.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for detective_snapshot-0.1.2.tar.gz
Algorithm Hash digest
SHA256 393e3bef1e7b563682c08c693185ddf9f22d329ac755d5f83b2301994a239869
MD5 0d3e46fed9dbf4607f0c8ac633fbf711
BLAKE2b-256 4380209515239f5bdce3e930fd8e339c9b178df349cb760034b9da79cd57cbad

See more details on using hashes here.

File details

Details for the file detective_snapshot-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for detective_snapshot-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24b156e34d7c2e3f51ac91d3448892f8221cf40a4b5db165209d25b4d3c15cb8
MD5 504396ce5a945f2cdfc8b007e63a9c60
BLAKE2b-256 da07b3caed1ac8191664c1293c25bf1b0a98e193cb6a1ed55e847d35afad6d4d

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