vb-console
A custom Python object inspector with a fancy style.
Installation
$ pip install vb-console
By default, console output is disabled. You can enable output via
- setting
ENABLE_CONSOLEenvironment variable - passing
enabled=Truekeyword argument
Usage
Let’s try with-in the python repl:
$ ENABLE_CONSOLE=1 python
then;
Python 3.8.5 (default, Nov 17 2020, 17:58:11)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from console import console
>>> console = console(source='repl', enabled=True)
>>> console('hello', 'world')
('hello', 'world')
>>>
This usage above is always better choice. Helps you to keep out un-wanted outputs in the production environment!
Let’s try with enabled=True;
$ python
then;
Python 3.8.5 (default, Nov 17 2020, 17:58:11)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from console import console
>>> console = console(source='repl', enabled=True)
>>> console.dir([1,2])
{ 'internal_methods': [ '__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__',
'__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__',
'__setitem__', '__sizeof__', '__str__', '__subclasshook__'],
'public_attributes': ['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']}
>>>
In this mode, console will always be available. Here is a quick usage with
Django:
from django.conf import settings
from console import console
console = console(source='repl', enabled=settings.DEBUG) # will be disabled in production!
You have few options for console output:
console(object)console(object, object, object, ...)console.dir(object)
All you need is this piece of code:
# import area
from console import console
console = console(source=__name__, enabled=True)
console('hello', 'world')
console.dir([])
Here is an example class:
class MyClass:
"""Example class"""
klass_var1 = 1
klass_var2 = 2
klass_var3 = 'string'
klass_var4 = list()
klass_var5 = dict()
klass_var6 = set()
def __init__(self):
self.name = 'Name'
def get_name_and_method(self):
return self.name + ' get_name_and_method'
def _private_method(self):
return self.name + ' _private_method'
@property
def admin(self):
return True
@staticmethod
def statik():
return 'Static'
@classmethod
def klass_method(cls):
return 'kls'
my_class_instance = MyClass()
console.dir(my_class_instance)
outputs:
{ 'class_methods': ['klass_method'],
'class_variables': ['klass_var1', 'klass_var2', 'klass_var3', 'klass_var4', 'klass_var5', 'klass_var6'],
'data_attributes': ['name'],
'internal_methods': [ '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__'],
'methods': ['get_name_and_method'],
'private_methods': ['_private_method'],
'properties': ['admin'],
'public_attributes': [ 'admin', 'get_name_and_method', 'klass_method', 'klass_var1', 'klass_var2', 'klass_var3', 'klass_var4',
'klass_var5', 'klass_var6', 'name', 'statik'],
'static_methods': ['statik']}
Now, let’s disable basic output:
from console import console
console = console(source=__name__, enabled=True, basic=False)
outputs with header and footer. source gets it’s value from __name__ and
currently the value is set to __main__:
[__main__ : instance of MyClass | <class '__main__.MyClass'>].........................................................................
{ 'class_methods': ['klass_method'],
'class_variables': ['klass_var1', 'klass_var2', 'klass_var3', 'klass_var4', 'klass_var5', 'klass_var6'],
'data_attributes': ['name'],
'internal_methods': [ '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
'__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__'],
'methods': ['get_name_and_method'],
'private_methods': ['_private_method'],
'properties': ['admin'],
'public_attributes': [ 'admin', 'get_name_and_method', 'klass_method', 'klass_var1', 'klass_var2', 'klass_var3', 'klass_var4',
'klass_var5', 'klass_var6', 'name', 'statik'],
'static_methods': ['statik']}
......................................................................................................................................
Options
source: Name of the header if thebasicoption is set toFalse. It’s good idea to set to__name__indent: Indentation value, default is:4width: Output’s width. Default is set to Terminal’s current width.enabled: Default isFalse. Can be modified viaENABLE_CONSOLEenv-var or setting this arg toTrueseperator_char: Default is:.colored: Default isFalse. Set this toTruefor colored outputdir_colors: This is adict, default isdict(keys='yellow', values='default')out_color: Default isyellowheader_color: Default isgreenfooter_color: Default isgreenbasic: Default isTrue. In basic mode, header and footer are not availablewriter: Default issys.stdout
Valid colors are: black, red, green, yellow, blue, magenta,
cyan, white and default
Here are some examples for configuration usage:
from console import console
# colorized with header/footer
console = console(source=__name__, basic=False, colored=True)
from console import console
# custom colors without header/footer
console = console(source=__name__, colored=True, dir_colors=dict(keys='red', values='yellow'))
Quick tip; console = console(source=__name__, basic=False, colored=True) kills/overrides
console from import. I mean;
>>> from console import console
>>> console = console(source=__name__, enabled=True)
>>> console('hello')
('hello',)
# now, let’s try to re-define console
>>> console = console(source=__name__, enabled=True, colored=True)
>>> console(console)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
If you want to keep console from import statement;
>>> from console import console as base_console
>>> console = base_console(source=__name__, enabled=True)
>>> console('hello')
('hello',)
>>> console = base_console(source=__name__, enabled=True, colored=True)
>>> console(console)
(<console.console.Console object at 0x10277cf40>,)
>>> console.dir([])
{ 'internal_methods': [ '__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__dir__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__',
'__imul__', '__init__', '__init_subclass__', '__iter__', '__le__',
'__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__',
'__setitem__', '__sizeof__', '__str__', '__subclasshook__'],
'public_attributes': [ 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop',
'remove', 'reverse', 'sort']}
>>>
Development
I’ve prepared few rake tasks:
$ rake -T
rake build # Build package
rake bump[revision] # Bump version
rake clean # Remove/Delete build..
rake default # Default task => :install
rake install # Install package for local development purpose
rake test # Run test
rake upload:main # Upload package to main distro (release)
rake upload:test # Upload package to test distro
Default rake task installs package locally for development purposes:
$ rake # runs rake install
License
This project is licensed under MIT
Contributer(s)
- Uğur "vigo" Özyılmazel - Creator, maintainer
Contribute
All PR’s are welcome!
fork(https://github.com/vbyazilim/django-vb-console/fork)- Create your
branch(git checkout -b my-features) commityours (git commit -am 'added killer options')pushyourbranch(git push origin my-features)- Than create a new Pull Request!
Change Log
2021-08-17
- Add
out_coloroption.console('foo')will be green by default. Useconsole = console(source=__name__, enabled=True, colored=True, out_color='white')for white output!
2021-02-05
- Re-write whole package from scracth
2021-01-16
- Add
output_toparam for streaming output to different targets - Add
basicparam for simple output - Add unit tests
- Add Travis
- Make small changes in the
console.py
2019-10-03
- Fix some of the code
- Add
ENABLE_CONSOLEenvironment variable - Update README
2019-09-29
- Init repo!
Metadata
Release files for vb-console 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vb-console-1.1.2.tar.gz | 10.4 kB | Without provenance | Details for vb-console-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vb_console-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for vb_console-1.1.2-py3-none-any.whl |
Total release size: 18.0 kB
Release files / vb-console-1.1.2.tar.gz
| Download URL | vb-console-1.1.2.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
956b498820ffaf5ff8867dd3a0f3f66e433c1b038679b28301d92e51844461e6
|
|
BLAKE2b-256 checksum How to use checksums |
ad0c81de16f3eaa7603cba8d2a0975bea3083a045a438aa941ba9625a346f378
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Release files / vb_console-1.1.2-py3-none-any.whl
| Download URL | vb_console-1.1.2-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef1d1af486b5b346e2f881d868392ee494785f2d055d07f71e3a55e285318698
|
|
BLAKE2b-256 checksum How to use checksums |
4c607dc2a6a5029b496d58471c596766e8f2d484f7bb57840090e5ad9d4135b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Security for vb-console 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.