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.
wat-demo.mp4
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'eJzlWv2O28YR/99PQVz/EGUz6l3cD0Cp0jrx1THgJIVzaWDcHQhKXN0xpkiBpHy+CALyEH2GPlifpPOxH7P8kHS2CwSoAZ+k3ZnfzszOzs7s7rIqV0GaNMkiT+pa1UG2WpdV45oe6YasqNdq0QRJHdRNGuufpre0dJUy3+r7+tES4Zv7dVbcGORnxX0UPM8WTRS8ymr4+/26ycoiyaPg4n6touBlo6pknsO3HwvoePQ3Jwv9DV7y2F+XxTK7mT4K4F99C9DTYF6WOf1ON0WqKtFQlGm5qEVDXhY34ueiTJX+OTTes6apsvmmUTxkkayAo24q+vUuyTfwE5Sjn6Ay/EJ9GD3Jc1Rpn4TrKnuXNJKkzm6KpNlU0GZsdAnjXTN/uWg3p2pppikkmnL+M4kU0a/HUdtUwSz4e5LXKupI5PdI4/k9zop+uzOn3w52aDePp0b9ogm1+PGyrFaJ1kJrErHkM/obaWln/BGUFUJHJM8M/9gWln3GHxEJNsM/moBGGI+l7bzBf1smHAeffYkuN9UUuACg11sQ4bCZOtaw5hKGGbPem2a9AR1xiZJ3wTCX7HnwKyZ3hyZtK/4dgrGYu1JrTUMrBAixxfVnS0ESzGZIRL04K35PDF3ZOl6UeVmFdmjtNE7SSbJeqyINl6PtDxdvXp3HX71++eKbi/irVz+e71iS7evzH84vdsHWouxGLI4C4z4IEKdgGO5IENTTocj+3dbZYKcpNDYOhsFF2B5/hvQHLSinb+/wFKI8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0AZ3DNB2NP35sorYRlh6DX44gHMIQeAhx7V+DILFfNnuS46Vbj0Kw9tb3Yka6jJPNOsWqvm0AoZUxHSnQszFZHrq/1Yr1AYFyodF83/O21rgx3iCnMft1zAspHAtHWECgU26jISOKR4rqLsbdYKbH3z/xmlrsj54ftOypJdVMYuabaqPS7J2dfOGaU3vnS8DCi4lI6BUnafqRCHl9my2bjwSpPgVIWX2sFB+NkH+sDvqdi0Whh4GHVq/zP+1J5K1+lMR3tJCebkeUFOABVD3a+YvCOqbvuZeaBfM9vIryFyM/0J0FI0wFRkcCEu0BPN71j0XU1AcwMRc4FpFoD+BxnnAsoqY+gAkB/VhAJD2AhhvKABrHm0siOTi3GBhHHxxDu4h6oz8KUtMexLxL2rqKZbdvM0iyWgX2EJGeuAzFXxfmzelsK6PoOZrVEJWa1Jt5WI2u3p/Nry6v0ifhF/Bn/NcVrkb4z8kHofbaktFKfckQmlmJgpAponEEpdZYL/xlxU/n5UuZxabCk2bq0mTeUyHMaWMME/TgP/y8e/bOqOJVbfcU3QxMn5NlPE8Wbx8dD9G96jRArG/31tP8q80bwUgAaGPgg+JcaJqqnHHlDJXS+G2va1vfePD/jfm1wv9T+1PWH8xGV6dPn16erkaPZNVLl4bYcWY7nr/81rZ+bltfnz+3radfPD1r4Xj9Z7KfSi/J+nmb1ac4kxRcwkjup23uFsmZR4Kv4AXzH9rMHsGZJNAPTiT3H23n12+eeSr9yfb89M3LC2/IPwtDPHvjDEs9/wXtjYQ7'
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.
Alternatively, install wat-inspector package and import inspection tool from wat module:
pip install wat-inspectorimport watwat 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:
.shortor.sto hide attributes (variables and methods).longto show non-abbreviated values and documentation.dunderto display dunder attributes.codeto reveal the source code of a function, method, or class.nodocsto hide documentation for functions and classes.allto include all available information.retto return the inspected object
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 UnixIn 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.AltersDataNow that you've identified the actual type, you can put the type annotations in your code to reduce the confusion.
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.
See the docstrings and the signature of a function or a method to see how to use it.
wat / str.splitList the attribues and their types to see what's really inside the inspected object.
wat / re.match('(\d)_(.*)', '1_title')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 / pathlibThen, you can navigate further, e.g. wat / pathlib.fnmatch.
By default, WAT Inspector hides attributes starting with __. Use wat.dunder to see them.
wat.dunder / {}Look up the source code of a function to see how it really works.
import re
wat.code / re.matchYou 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 executionwat / __builtins__wat()
# or
wat.localswat.globals