Skip to main content

Powerful human readable version of dir().

Project description

explor

Python object explorer which shows you what you can do with an object.

It takes the output from dir(), checks this and classifies it in a table. With that, you don't have to read the entire output of dir() and visually filter it for the relevant information.

Installation

Install the package:

pip install explor

or

pip install git+git://github.com/Talon24/explore

or

pip install git+https://github.com/Talon24/explore

Example

From this

# Very long line with very specific information, like all the dunder-methods
import datetime
print(dir(datetime.datetime.now()))
['__add__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fold', 'fromisocalendar', 'fromisoformat', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timestamp', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']

To this

from explor import explore as ex
import datetime

ex(datetime.datetime.now())
  Inherits:
datetime -> date -> object
  Description:
datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])

The year, month and day arguments are required. tzinfo may be None, or an
instance of a tzinfo subclass. The remaining arguments may be ints.
+ Class datetime --+-----------------------+------+
| Methods          | Data                  | Ops  |
+------------------+-----------------------+------+
| astimezone       | day: int              | !=   |
| combine          | fold: int             | +    |
| ctime            | hour: int             | -    |
| date             | max: datetime         | <    |
| dst              | microsecond: int      | <=   |
| fromisocalendar  | min: datetime         | ==   |
| fromisoformat    | minute: int           | >    |
| fromordinal      | month: int            | >=   |
| fromtimestamp    | resolution: timedelta | hash |
| isocalendar      | second: int           | str  |
| isoformat        | tzinfo: NoneType      |      |
| isoweekday       | year: int             |      |
| now              |                       |      |
| replace          |                       |      |
| strftime         |                       |      |
| strptime         |                       |      |
| time             |                       |      |
| timestamp        |                       |      |
| timetuple        |                       |      |
| timetz           |                       |      |
| today            |                       |      |
| toordinal        |                       |      |
| tzname           |                       |      |
| utcfromtimestamp |                       |      |
| utcnow           |                       |      |
| utcoffset        |                       |      |
| utctimetuple     |                       |      |
| weekday          |                       |      |
+------------------+-----------------------+------+

Usage

The module's name is explore and it provides a function called explore(). To simplify exploration, i'd recommend aliasing it as something short like ex.

Settings

You can change the style of the table. The DoubleTable is the default, if the text viewer can't handle unicode, then the AsciiTable might be useful. Some examples to change the Table style:

import explor
explor.TABLETYPE = explor.terminaltables.AsciiTable
explor.TABLETYPE = explor.terminaltables.SingleTable
explor.TABLETYPE = explor.terminaltables.DoubleTable
explor.TABLETYPE = explor.terminaltables.GithubFlavoredMarkdownTable

Module

from explore import explor as ex
import pathlib

ex(pathlib)
+ module: pathlib ------+---------------------+-----------------+
| Constants | Modules   | Functions           | Classes         |
+-----------+-----------+---------------------+-----------------+
| EBADF     | fnmatch   | urlquote_from_bytes | Path            |
| EINVAL    | functools |                     | PosixPath       |
| ELOOP     | io        |                     | PurePath        |
| ENOENT    | ntpath    |                     | PurePosixPath   |
| ENOTDIR   | os        |                     | PureWindowsPath |
| S_ISBLK   | posixpath |                     | Sequence        |
| S_ISCHR   | re        |                     | WindowsPath     |
| S_ISDIR   | sys       |                     | attrgetter      |
| S_ISFIFO  | warnings  |                     |                 |
| S_ISLNK   |           |                     |                 |
| S_ISREG   |           |                     |                 |
| S_ISSOCK  |           |                     |                 |
+-----------+-----------+---------------------+-----------------+

Function

from explor import explore as ex
def a_function(pos: int, /, both: float, untyped=4, *, kw_only: str = "blue") -> complex:
    """Kinds of arguments."""
ex(a_function)
  Description:
Kinds of arguments.
+ Function a_function -> complex --------------------+
| Argument | Default | Type  | Kind                  |
+----------+---------+-------+-----------------------+
| pos      | ---     | int   | positional-only       |
| both     | ---     | float | positional or keyword |
| untyped  | 4       | Any   | positional or keyword |
| kw_only  | 'blue'  | str   | keyword-only          |
+----------+---------+-------+-----------------------+

Class

On Classes (Not instances), the constructor is also printed.

from explor import explore as ex
import requests
ex(requests.Request)
  Inherits:
Request -> RequestHooksMixin -> object
  Description:
A user-created :class:`Request <Request>` object.
+ type: Request --+------+
| Functions       | Ops  |
+-----------------+------+
| deregister_hook | !=   |
| prepare         | <    |
| register_hook   | <=   |
|                 | ==   |
|                 | >    |
|                 | >=   |
|                 | hash |
|                 | str  |
+-----------------+------+
  Description:
A user-created :class:`Request <Request>` object.
...
+ Constructor -------+
| Argument | Default |
+----------+---------+
| method   | None    |
| url      | None    |
| headers  | None    |
| files    | None    |
| data     | None    |
| params   | None    |
| auth     | None    |
| cookies  | None    |
| hooks    | None    |
| json     | None    |
+----------+---------+
from explor import explore as ex
import fractions
ex(fractions.Fraction)
  Inherits:
Fraction -> Rational -> Real -> Complex -> Number -> object
  Description:
This class implements rational numbers.
...
+ ABCMeta: Fraction ---------------+-----------------------+--------+
| Methods      | Functions         | Data                  | Ops    |
+--------------+-------------------+-----------------------+--------+
| from_decimal | as_integer_ratio  | denominator: property | !=     |
| from_float   | conjugate         | imag: property        | %      |
|              | limit_denominator | numerator: property   | *      |
|              |                   | real: property        | **     |
|              |                   |                       | +      |
|              |                   |                       | +()    |
|              |                   |                       | -      |
|              |                   |                       | -()    |
|              |                   |                       | /      |
|              |                   |                       | //     |
|              |                   |                       | <      |
|              |                   |                       | <=     |
|              |                   |                       | ==     |
|              |                   |                       | >      |
|              |                   |                       | >=     |
|              |                   |                       | abs    |
|              |                   |                       | divmod |
|              |                   |                       | float  |
|              |                   |                       | hash   |
|              |                   |                       | round  |
|              |                   |                       | str    |
+--------------+-------------------+-----------------------+--------+
  Description:
This class implements rational numbers.
...
+ Constructor +---------+-----------------------+
| Argument    | Default | Kind                  |
+-------------+---------+-----------------------+
| numerator   | 0       | positional or keyword |
| denominator | None    | positional or keyword |
| _normalize  | True    | keyword-only          |
+-------------+---------+-----------------------+

Automatic import

If you have ipython, you can create a file in ~/.ipython/profile_default/startup/ that imports it, it will then be available at the start of ipython.

This can look like this:

from explor import explore as ex
from explor import explore_signature as exs
from explor import explore_object as exo

get_ipython().magic("%autocall 1")  # With this, it's callable without parens; e.g. `ex os.path`

More explanation here.

Limitations

The library won't always work on some builtin objects like print or libraries written in c, e.g. numpy.array.

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

explor-0.1.18.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

explor-0.1.18-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file explor-0.1.18.tar.gz.

File metadata

  • Download URL: explor-0.1.18.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for explor-0.1.18.tar.gz
Algorithm Hash digest
SHA256 5386f9de30d500e32e6b6ebd8c42a9b92665b3c31d504b9d415ea2d1ee2b5a82
MD5 84fc2951c2ed2d9f4da8ba93f685ad66
BLAKE2b-256 3607f46ef642244c6f1676acd92e15a9cd1a85033111c2e1fdd51623417dcae5

See more details on using hashes here.

File details

Details for the file explor-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: explor-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

File hashes

Hashes for explor-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 acfff82c0bbb53b883263b5edce7ccc96c817d7a008896919878fd4b50bfdba5
MD5 00de631c13ff78a35a2351df994fa90a
BLAKE2b-256 92a231f1955b7b18090062b7eeb904db6056e09f8fe89ff244a90f5d81871b3a

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