Skip to main content

Deep inspection of Python objects

Project description

🙀 WAT Inspector

Deep inspection of Python objects.

WAT is a powerful inspection tool that allows you to delve into and examine unknown objects at runtime.

"Wat" is a variant of the English word "what" that is often used to express confusion or disgust

If you find yourself deep within the Python console, feeling dazed and confused, wondering "WAT? What's that thing?", that's where the wat inspector comes in handy.

Start the Python Interpreter (or attach to one) and execute wat / object on any object to investigate its type, formatted value, variables, methods, parent types, signature, documentation, and even its source code. Alternatively, you can use wat(object) syntax.

Import

Insta-Load

If you want to quickly debug something, you can use this inspector without installing anything, in the same session.

Load it on the fly by pasting this snippet to your Python interpreter:

import base64, zlib
code = b'eJzlW/1u28gR/99PQbh/kHR4qn3pB6CrrvUlbi5ALikcX4NANghKXNm8UKRAUnFcQcA9RJ+hD9Yn6XzsJz8k+XwFCtRAbGl35rczs7OzM7ubRVUuvTRpknme1LWovWy5KqvGNB3JhqyoV2LeeEnt1U0ay6+qt9R0lVCf6of6aIHwzcMqK24V8nnxEHkvs3kTeW+yGn6/WzVZWSR55F09rETkvW5Elcxy+PRjAR1HfzGy0G/vNY/9oiwW2e34yIOf+g6gx96sLHP6nq6LVFRWQ1Gm5by2GvKyuLW+zstUyK9D4503TZXN1o3gIYtkCRx1U9G3z0m+hq+gHH0FleEb6sPoSZ6jSrskXFXZ56SxSerstkiadQVtykZTGO+G+ct5uzkVCzVN8aKslkkTEGk5+4kki+jbSdS2mDfx/prktYg6grk9tg3dHmNMt91Y1W0Hc7SbQ++rb9GaY8mIcwu9zlwHJPSEfkdS0An/8coKUSMp5IT/RCTZBH9pApRpgr9kS8g2WjerNdgDXZKsCWNP2dLwLabphSZpV/4egGGZuxIrSUMeAYTYYvqzhUXiTSZIRL0og9sTQ1e2iudlXlaBHjpksxhJR8lqJYo0WPib91cf31zE312+fvX9Vfzdmx8vtizJ5vLi/cXV1ttolK3P4giw+KMAcV6G4Q4EQT0Nit2/3RgbbCWFxMbBcDFZtsevAf1CC9rTt3N4WpKOEtiixlkllSia2hqGW4iodmZ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60RjvCXrCeOwWFYPlt5dxtF6lWIZLneFvusKkC7obB8j+T04cfno0lWqOQzWHm3wqoSUUkPFePebxuxGMS+BIDSmV3Rs+RIcvmqbetDGcmWYXU4+dSYUnLo+87ov1ax9EK8pAx+GgWmlo/iwVzsetOVO3LgHGgD2QKPc7f3R3Iaio84hoAuzoZIXWs8zxX2Mu95ETtlu/SW1lQc4MrfcUIojmayl01RrkWaf9eqx5nDc6xJEYC++JE2fwJ3Xd9mieQJA9VSAsnrK6E/izp8it3yzoxHo2eNwiLvpczTpMuSWbqzGp8KQb298ynLwRK32t67faw90XXQqWTCBxbs1N1DxG+SJ52Nu4x8ISLR78DiNORRRUu/BxOTmUESi3YPHic+hiJJ6DyZsfYcCIukeNIxyA2gcWKZEsgcFw/AeFCTZ6yG46/hP26W6sDJzORxXMuwFvk/atrNAd228SVYLT5+y0hugocBt9gd1fN1KlXrOriVEJUb1ehZU/vWXs9n19Dp9FnwDv8I/L3F1wz/OqnijcrM0hMOalPFE8ZkJsPbUgvoL3Br9sf3fg6gddxhoxonm1i1tqGU9AqCsKgveXz+cX8Uv3r15d0nShJD/3osqMO+wzajWi+PuQ0RFZWve84Sb1ez1G8Ys5WVToNww8gKmiMIISu5QxstFxf+pwn4xNV9XeONAXZLMeTKGtU2M0bVKilsRfN29g2HUXkU1iByY/o4W8SyZfzo6HKJ75a2AWN/u7bf6qdVb0cgCkMbAV+W5pWkqcsa1p6O0jd9eXG3rq9X6f2N+qfB/1f5UsnkT//r0+fPp6dI/sk8/6PIYO850x8vXP+jWr3Xr5cVL3Xr6zfOzFo7Tf2b3U81ss37dZnUpzmwKrj9t7udt7hbJmUOC/xXCYv5dm9khOLMJ5MMjm/v3uvPFx3NHpT/ong/fv75yhvyjZYjzj8aw1PMfMbTFew=='
exec(zlib.decompress(base64.b64decode(code)).decode(), globals())

Now you can use wat object.

[!Warning] Before executing Insta-Load snippet, it's recommended to verify what you're about to run. If you feel uncomfortable, you can either:

  • Verify what's inside the extracted code beforehand:
    print(zlib.decompress(base64.b64decode(code)).decode())
    
  • Paste the content of inspection.py into your interpreter. It has the same effect.
  • Install package with pip and review the code.

Install with pip

Alternatively, install wat-inspector package and import inspection tool from wat module:

pip install wat-inspector
import wat

Usage & modifiers

wat object can quickly inspect things by using the division operator (for faster typing without parentheses). A short syntax wat / object is equivalent to wat(object).

You can call wat.modifiers / object with the following modifiers:

  • .short or .s to hide attributes (variables and methods)
  • .long to show non-abbreviated values and documentation
  • .dunder to display dunder attributes
  • .code to reveal the source code of a function, method, or class
  • .nodocs to hide documentation for functions and classes
  • .all to include all available information
  • .ret to return the inspected object
  • .str to return the output string instead of printing

You can chain modifiers, e.g. wat.long.dunder.nodocs / object.

Call wat.locals or wat() to inspect locals() variables.
Call wat.globals to inspect globals() variables.

Type wat in the interpreter to learn more about this object itself.

There are several alternative syntaxes that are equivalent. Choose the one that works best for you:

wat.short / 'foo'  # fast typing
wat.short('foo')
wat('foo', short=True)  # natural Python syntax
'foo' | wat.short  # similar to piping in Unix

Use Cases Examples

Determine type

In a dynamic typing language like Python, it's often hard to determine the type of an object. WAT Inspector can help you with that by showing the name of the type with the module it comes from.

>>> wat.short / (1,)
value: (1,)
type: tuple
len: 1
>>> wat.short / {None}
value: {None}
type: set
len: 1
>>> wat.short / user
str: admin
repr: <User: admin>
type: django.contrib.auth.models.User
parents: django.contrib.auth.models.AbstractUser, django.contrib.auth.base_user.AbstractBaseUser, django.contrib.auth.models.PermissionsMixin, django.db.models.base.Model, django.db.models.utils.AltersData

Now that you've identified the actual type, you can put the type annotations in your code to reduce the confusion.

Look up methods

Listing methods, functions and looking up their signature is extremely beneficial to see how to use them. Plus, you can read their docstrings.

wat / 'stringy'

Use wat.long if you want to see full doscstrings.

Discover function's signature

See the docstrings and the signature of a function or a method to see how to use it.

wat / str.split

Look up attributes

List the attribues and their types to see what's really inside the inspected object.

wat / re.match('(\d)_(.*)', '1_title')

Explore modules

One of the use cases is to explore modules. For instance you can list functions, classes and the sub-modules of a selected module.

import pathlib
wat / pathlib

Then, you can navigate further, e.g. wat / pathlib.fnmatch.

Explore dunder attributes

By default, WAT Inspector hides attributes starting with __. Use wat.dunder to see them.

wat.dunder / {}

Review the code

Look up the source code of a function to see how it really works.

import re
wat.code / re.match

Debug with breakpoint

You can use Python's breakpoint() keyword to launch an interactive debugger in your program:

logger.debug('init')
x = {'what is it?'}
breakpoint()
logger.debug('done')
(Pdb) import wat  # or paste insta-load snippet
(Pdb) wat / x  # inspect local variable
...
(Pdb) c  # continue execution

Explore Python built-ins

wat / __builtins__

Look up local variables

wat()
# or
wat.locals

Look up global variables

wat.globals

Environment variables

  • WAT_COLOR="false" to disable colorful output in the console.
  • WAT_COLOR="true" to enforce colorful outputs even in non-tty environment.

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

wat_inspector-0.3.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

wat_inspector-0.3.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file wat_inspector-0.3.0.tar.gz.

File metadata

  • Download URL: wat_inspector-0.3.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for wat_inspector-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b9cc9aedced19acc68835eb4fd3cc6cbb73338089b223b35d8213c8c24fbf15b
MD5 360812e3e64390738fc979c1dcdad7c6
BLAKE2b-256 7b6c0e0f7da1ed80f0b45115d6551cd336e53a4dda24ac6dfb5d463e4518c980

See more details on using hashes here.

File details

Details for the file wat_inspector-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wat_inspector-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a917e699c74c3395d332f1543795a7850910631eec409e0698f027192c40be9f
MD5 60ff94b72c6e004d26237302c7a3ed0b
BLAKE2b-256 9a0f3d98267bc200d94256de99df46ace6517fc0f29b48fbdf0afa179f6a0853

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page