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'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+3dbZYK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IkziLVY4gmmG2pBOalsaaAcgcBEBMZN0AZ3DNB2NP35sorYRlh6DX44gHMIQeAhx7V+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.

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

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

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.2.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

wat_inspector-0.2.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wat_inspector-0.2.1.tar.gz
  • Upload date:
  • Size: 20.1 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.2.1.tar.gz
Algorithm Hash digest
SHA256 92999c4ec4efa6d669b24b794eb675ae138945f7282b59fdeaae3076a02b3fd6
MD5 9366fd9002bdd29e5069de86bb56ce1f
BLAKE2b-256 6ae5ec40322be90955415b847d9a7f3389ffe717b990c721edb950cc6e4c1e73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wat_inspector-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4157c414de60b6675bfec0635b8c9895ca687d6ffd1194edfb2a673fec5d4d79
MD5 12736a05fd7128eb0f42107fc1e37f00
BLAKE2b-256 9dbf625e2be2bd91859024f2e3d06801fda5758e2568b64acad564abe28129da

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