A pretty-printed version of dir(obj) for more comfortable debugging
Project description
Overview
How often have you wished for a more well organized output from Python's built-in dir function when looking through a deeply nested pydantic model after seeing page due to tens of private methods? Running dir on a pandas DataFrame produces a list of 443 entries!
The goal of this library is to create a more useful debugging tool than the built-in function dir(<class>). The issues with the built-in dir(<class>) addressed by this library are:
- Inclusion of dunder methods that are very rarely useful
- No differentiation between attributes/methods
- No docstring display
- No grouping of similar functionality together, only alphabetical sorting
- No way to jump to the source code of the
This library takes the output of dir and runs the following steps:
- Groups the attributes and methods by the class they are defined by
- Identifies the source code location of the class, allowing you to quickly jump to them for a deeper dive in IDEs like VS Code.
- Prints the docstring summary of the class.
- Identifies if it is a dunder method, non-dunder method, or attribute
- Within non-dunder methods, adds a "ᶜ" or "ˢ" to indicate if it is a classmethod or staticmethod rather than a standard instance method.
- Pulls the summary of the docstring for each attribute/method, if it exists
- For attributes, there is no
__doc__attribute, but we follow the convention of PEP-258 and most autocompletion tools of the next literal expression if it exists
- For attributes, there is no
- Colorizes the output to visually differentiate the classes, attributes, methods, and dunder methods
Limitations
Currently, this library only works with classes. For all other entities - functions, modules, etc - it falls back to the built-in dir implementation.
Installation
You can install the library using pip:
pip install pretty-dir
Auto-loading in PDB (Breakpoint)
PDB is the built-in Python debugger that you can invoke with the breakpoint() function (or import pdb; pdb.set_trace() in Python versions before 3.7). To make ppdir automatically available in every PDB session, you can include it in a PDB configuration file.
To make and add ppdir to your global PDB configuration, create a file named ~/.pdbrc if it doesn't already exist, and add the following lines to it:
from ppdir import ppdir, defaults
defaults(include_docs=True) # remember to set your preferred defaults!
Now ppdir will be automatically available whenever you call breakpoint() in your code.
Basic Usage Example
from ppdir import ppdir
class BaseClass:
base: int
class MyClass(BaseClass):
a: int
"example attr docstring"
b: str
def my_method(self):
"""This is my method."""
pass
ppdir(MyClass)
Demo
Running the code in demo.py, you should see the difference between the built-in dir and ppdir like the following images:
Before:
After:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pretty_dir-0.9.13.tar.gz.
File metadata
- Download URL: pretty_dir-0.9.13.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e54a2999289229aa6205b3276efe29a5da632680e28408840c35ea9e065f41a5
|
|
| MD5 |
5abc0059733adb16d510bf6377ce2df1
|
|
| BLAKE2b-256 |
be24aff09da970bf5e18bbde6498aa6f6af9ecbae2e7969b57c8b48f9ae66d2c
|
Provenance
The following attestation bundles were made for pretty_dir-0.9.13.tar.gz:
Publisher:
deploy.yml on douglassimonsen/ppdir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pretty_dir-0.9.13.tar.gz -
Subject digest:
e54a2999289229aa6205b3276efe29a5da632680e28408840c35ea9e065f41a5 - Sigstore transparency entry: 495451953
- Sigstore integration time:
-
Permalink:
douglassimonsen/ppdir@ca714c4bea539fc698ba26cd77b2ef9aceb2409a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/douglassimonsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@ca714c4bea539fc698ba26cd77b2ef9aceb2409a -
Trigger Event:
push
-
Statement type:
File details
Details for the file pretty_dir-0.9.13-py3-none-any.whl.
File metadata
- Download URL: pretty_dir-0.9.13-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
420c71115f28ab36658bda14ca695a5d10af9a0c2649f8ff87cb333bf4af24f9
|
|
| MD5 |
75449b4f7c22b729f77e71d925973857
|
|
| BLAKE2b-256 |
7f13f7a5b07d950de72c9cfd91edceb38ffa87b03f61557e6eb3e049492fdb6a
|
Provenance
The following attestation bundles were made for pretty_dir-0.9.13-py3-none-any.whl:
Publisher:
deploy.yml on douglassimonsen/ppdir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pretty_dir-0.9.13-py3-none-any.whl -
Subject digest:
420c71115f28ab36658bda14ca695a5d10af9a0c2649f8ff87cb333bf4af24f9 - Sigstore transparency entry: 495451985
- Sigstore integration time:
-
Permalink:
douglassimonsen/ppdir@ca714c4bea539fc698ba26cd77b2ef9aceb2409a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/douglassimonsen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@ca714c4bea539fc698ba26cd77b2ef9aceb2409a -
Trigger Event:
push
-
Statement type: