Giter Club home page Giter Club logo

peep-dis's Introduction

                    Python Contributions welcome Dependencies Code style: black GitHub Issues License

                                                                           PyPI version Build Status

A colorful CLI object inspector for python

peep dis (verb phrase, imperative): "Check this out" or "Hey! Have a look at this."

OverviewFeaturesUsageUpcoming Features

Overview

Show the outputs of methods and attributes of an object. An example for a numpy array is shown here.

Features

  • Evaluates and color codes attributes and callables
  • Duplicates object to avoid state alterations
  • Choose whether builtin and private attributes and methods are included
  • Attempt to forge arguments from type hints (in development)
  • Track object state changes (in development)

Usage

Install

pip install peepdis

Import

from peepdis import peep

Peep Imported Objects

import pandas as pd

df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
peep(df)

Peep Your Own Objects

class Square:
    def __init__(self, a, b, name=None):
        self.a = a
        self.b = b
        self.name = name
    
    def ratio(self):
        return self.a / self.b
    
    def area(self):
        return self.a * self.b
 
 
sq = Rect(4, 4)
peep(sq)

Include Builtins (i.e. Magics)

Controls the inclusion of "magic" methods and attributes, which are denoted by leading and trailing double underscores -- e.g., "init". They are excluded by default.

peep(sq, builtins=True)

Include Private Attributes and Methods

Controls the inclusion of private methods and attributes, which are denoted by a single leading underscore -- e.g., "_method_name". They are excluded by default.

peep(sq, privates=True)

Print Docstrings With Output

peep(sq, docstrings=True)

Truncate Output Length

Controls maximum number of characters for each method or attribute output. No truncation will occur if None or 0. Set at 250 characters by default.

peep(sq, truncate_len=None)

In the Debugger

To call peep in the debugger, it must be wrapped in a print statement. This is consistent across pdb, ipdb, PyCharm's built-in debugger, etc.

(Pdb) print(peep(sq))

Example Usage

I. The Mystery Object

We have a simple mystery_obj which contains an array of San Francisco temperatures somewhere within it, but we don't know where. We could call dir, then iteratively check each method/attribute, or we could just peep the object.

Example 1

We can quickly identify stdtemp as the attribute we need. Built-ins are filtered out, and outputs for the rest of the attributes and methods without positional arguments are printed. Methods are colored purple, and attributes are cyan. The outputs from methods requiring positional arguments are grayed out to allow us to skim others more quickly.

II. What's the name of that method?

We have a DataFrame with the columns temp and humidity for San Francisco, which we want to convert to a narrow data model for an API we are building. There's a one-liner for this, but nothing stands out in dir, and nothing turns up on Stack Overflow. If we peep the DataFrame, we'll quickly identify melt as the method we need.

Example 2 call Example 2 output

Upcoming Features

Argument Forging

Sometimes a method requires one simple argument to run, like an index. By forging simple arguments like these, we can see example outputs from methods that we wouldn't otherwise be able to see. The sample code which this feature will be based on can be found in the accompanying blog post at ____.

Tracking State Changes

Often, a method call changes the state of the object. Tracking state changes would allow us to see understand what these types of methods do. The sample code which this feature will be based on can be found in the accompanying blog post at ____.

Customizable Preferences and Color Scheme

peep-dis's People

Contributors

theaustinator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

alvinjamur

peep-dis's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.