Skip to main content

Pretty dir printing with joy

Project description

pdir2: Pretty dir() printing with joy

Build status Supported Python versions PyPI Version Code style: black

Have you ever dreamed of a better output of dir()? I do. So I created this.

Features

  • Attributes are grouped by types/functionalities, with beautiful colors.

  • Support color customization, here's how.

  • Support all platforms including Windows(Thanks to colorama).

  • Support ipython, ptpython, bpython and Jupyter Notebook! See wiki for details.

  • The return value of pdir() can still be used as a list of names.

  • ✨ Attribute searching

    You can search for certain names with .s() or .search():

    Search is case-insensitive by default. search(name, case_sensitive=True) does case-sensitive searching.

  • :star2: Attribute filtering

    properties: Find properties/variables defined in the inspected object.

    methods: Find methods/functions defined in the inspected object.

    public: Find public attributes.

    own: Find attributes that are not inherited from parent classes.

    These filters can be chained! Order does NOT matter.

    For example, use pdir(obj).public.own.methods to find all public own methods.

    You can also call search on the returned results.

    See a complete example.

Install

Generic

pip install pdir2

About the name. I wanted to call it "pdir", but there's already one with this name on pypi. Mine is better, of course.

Fedora

dnf install python3-pdir2

Automatic Import

As a better alternative of dir(), it's more convenient to automatically import pdir2 when launching REPL. Luckily, Python provides a way to do this. In you .bashrc(or .zshrc), add this line:

export PYTHONSTARTUP=$HOME/.pythonstartup

Then, create .pythonstartup in your home folder. Add one line:

import pdir

Next time you launch REPL, pdir() is already there, Hooray!

Development

  1. Set up development environment

    • PDM: pdir2 uses PDM to manage dependencies, so you want to make sure it's installed.
    • pyenv: Since you need to test pdir2 on multiple Python versions, pyenv is highly recommended. Make sure you have Python 3.10, 3.11, 3.12, 3.13, and 3.14 installed.
  2. Install dev dependencies

    Simply run pdm install.

    If you want to work on a specific Python version, run pdm use [PYTHON_VERSION] first to switch PDM to that version (e.g. pdm use 3.9 if you want to debug a Python 3.9 specific issue).

  3. Run tests

    Run pdm run tox

The guide may be incomplete. Please file bugs if you encounter any issues.

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

pdir2-1.1.2.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdir2-1.1.2-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file pdir2-1.1.2.tar.gz.

File metadata

  • Download URL: pdir2-1.1.2.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdir2-1.1.2.tar.gz
Algorithm Hash digest
SHA256 34de77cec1250e0f00a1a50c1b9252c2a1a7fe4768b8d31fb95289d9ebdde991
MD5 6edeea626d86192d8ca2d3d71a60d5cd
BLAKE2b-256 53b3168492af4a5265fb1389c9037c0afc2e7c5e5cd11e85b27ca79399700915

See more details on using hashes here.

File details

Details for the file pdir2-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: pdir2-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pdir2-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5f18a56e4f5483f6307434bd46f354375d1a8d7327e5786d2dd20b98463b9d5
MD5 7af1e1b905b7e884501fc79c6595923a
BLAKE2b-256 76cc5f939bdb8f06a9e809a71a58a3f07c770f89dc85a3a6a70fce28990cf056

See more details on using hashes here.

Supported by

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