def python_memory(event: PodEvent, params: MemoryTraceParams):
    """
    Monitor a Python process for X seconds and show memory that was allocated and not freed.

    Use this to track memory leaks in your Python application on Kubernetes.
    """
    if "debug-toolkit:v6.0" not in PYTHON_DEBUGGER_IMAGE:
        logging.error(f"The python_memory action is deprecated and might not work on all platforms. "
                      f"to enable it set the PYTHON_DEBUGGER_IMAGE environment variable to debug-toolkit:v6.0.")
        return
    pod = event.get_pod()
    if not pod:
        logging.info(f"python_memory - pod not found for event: {event}")
        return

    finding = Finding(
        title=f"Memory allocations for {pod.metadata.name} in namespace {pod.metadata.namespace}:",
        source=FindingSource.MANUAL,
        aggregation_key="PythonMemoryAllocations",
        subject=PodFindingSubject(pod),
        finding_type=FindingType.REPORT,
        failure=False,
    )
    process_finder = ProcessFinder(pod, params, ProcessType.PYTHON)
    process = process_finder.get_match_or_report_error(finding, "Profile", python_memory, python_process_inspector)
    if process is None:
        event.add_finding(finding)
        return

    cmd = f"debug-toolkit memory --seconds={params.seconds} {process.pid}"
    output = RobustaPod.exec_in_debugger_pod(
        pod.metadata.name, pod.spec.nodeName, cmd, custom_annotations=params.custom_annotations
    )
    snapshot = PythonMemorySnapshot(**load_json(output))

    blocks = [
        HeaderBlock("Summary"),
        MarkdownBlock(f"*Total unfreed allocations: {humanize.naturalsize(snapshot.total)}*"),
        MarkdownBlock(f"*Additional overhead from tracing: {humanize.naturalsize(snapshot.overhead)}*"),
        DividerBlock(),
        HeaderBlock("Largest unfreed allocations"),
    ]
    blocks.extend([MarkdownBlock(stat.to_markdown()) for stat in snapshot.data])
    blocks.append(MarkdownBlock(f"*Other unfreed memory:* {snapshot.other_data.to_markdown()}"))
    finding.add_enrichment(blocks, annotations={SlackAnnotations.ATTACHMENT: True})
    event.add_finding(finding)

    Monitor a Python process for X seconds and show memory that was allocated and not freed.

    Use this to track memory leaks in your Python application on Kubernetes.
    
playbooks/robusta_playbooks/pod_troubleshooting.py