Skip to main content

ASnooper

ASnooper is the asynchronous version of Pysnooper, incorporating most of its functionality for easy debugging in async functions as an alternative to print statements.

Installation

$ pip install ASnooper

Example

Here is a base common func. While adding the @snoop() decorator:

import asyncio
from ASnooper import snoop


@snoop(prefix="name")
async def print_name(name: str) -> str:
    await asyncio.sleep(2)  # io

    name = f"hello {name}"  # modify var

    return name


async def main():
    await print_name("Ling")


if __name__ == '__main__':
    asyncio.run(main())

The output is:

name  11:53:19     call    5 print_name()
name           var: name = 'Ling'
name  11:53:19     line    7 print_name() await asyncio.sleep(2)    # io
name  11:53:21     call    7 print_name()
name           var: name = 'Ling'
name  11:53:21     line    9 print_name() name = f"hello {name}"    # modify var
name  11:53:21     line   11 print_name() return name
name      modified: name = 'hello Ling'
name  11:53:21   return   11 print_name()
name         watch: return = 'hello Ling'
name  Elapsed time: 2001.539ms

Or if you don't want to trace an entire function, you can use async with snoop_context():

import asyncio
from ASnooper import snoop_context


async def print_name(name: str) -> str:
    await asyncio.sleep(2)   # io

    name = f"hello {name}"   # modify var | no trace

    async with snoop_context(prefix="name-context"):
        name += f"-context"  # modify var | trace

    return name


async def main():
    await print_name("Ling")


if __name__ == '__main__':
    asyncio.run(main())

The output is:

name-context 14:11:24     line   11 print_name() name += f"-context"   # modify var, will trace
name-context          var: name = 'hello Ling'
name-context 14:11:24     line   10 print_name() async with snoop_context(prefix="name-context"):
name-context     modified: name = 'hello Ling-context'

More

Output stderr to file:

@snoop(output='debug.log')

See values of some expressions that aren't local variables:

@snoop(watch=('user.id',))

No color output:

@snoop(color=False)

Metadata

Release files for ASnooper 1.0.0

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

Source distribution (sdist)

Source distribution for ASnooper 1.0.0
File Size Uploaded
asnooper-1.0.0.tar.gz 9.9 kB Details

Release files / asnooper-1.0.0.tar.gz

Download URL asnooper-1.0.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6418ac0ab1f52247205dbabf8535961b8f9c8392480ff7b8bb08d318359a47ba
BLAKE2b-256 checksum
How to use checksums
d04e958c5b705657f308c6eee232ad46d5f7b96e69caf19d359cb175385560c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

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