Package: vb-console
vb-consoleA custom Python object inspector with a fancy style.Installation$pipinstallvb-consoleBy default, console output is disabled. You can enable output viasettingENABLE_CONSOLEenvironment variablepassingenabled=Truekeyword argumentUsageLet’s try with-in the python repl:$ENABLE_CONSOLE=1pythonthen;Python3.8.5(default,Nov172020,17:58:11)[Clang12.0.0(clang-1200.0.32.27)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>fromconsoleimportconsole>>>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 withenabled=True;$pythonthen;Python3.8.5(default,Nov172020,17:58:11)[Clang12.0.0(clang-1200.0.32.27)]ondarwinType"help","copyright","credits"or"license"formoreinformation.>>>fromconsoleimportconsole>>>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 withDjango:fromdjango.confimportsettingsfromconsoleimportconsoleconsole=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 areafromconsoleimportconsoleconsole=console(source=__name__,enabled=True)console('hello','world')console.dir([])Here is an example class:classMyClass:"""Example class"""klass_var1=1klass_var2=2klass_var3='string'klass_var4=list()klass_var5=dict()klass_var6=set()def__init__(self):self.name='Name'defget_name_and_method(self):returnself.name+' get_name_and_method'def_private_method(self):returnself.name+' _private_method'@propertydefadmin(self):returnTrue@staticmethoddefstatik():return'Static'@classmethoddefklass_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 disablebasicoutput:fromconsoleimportconsoleconsole=console(source=__name__,enabled=True,basic=False)outputs with header and footer.sourcegets it’s value from__name__and
currently the value is set to__main__:[__main__:instanceofMyClass|<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']}......................................................................................................................................Optionssource: 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.stdoutValid colors are:black,red,green,yellow,blue,magenta,cyan,whiteanddefaultHere are some examples for configuration usage:fromconsoleimportconsole# colorized with header/footerconsole=console(source=__name__,basic=False,colored=True)fromconsoleimportconsole# custom colors without header/footerconsole=console(source=__name__,colored=True,dir_colors=dict(keys='red',values='yellow'))Quick tip;console = console(source=__name__, basic=False, colored=True)kills/overridesconsolefrom import. I mean;>>>fromconsoleimportconsole>>>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(mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:'NoneType'objectisnotcallableIf you want to keepconsolefrom import statement;>>>fromconsoleimportconsoleasbase_console>>>console=base_console(source=__name__,enabled=True)>>>console('hello')('hello',)>>>console=base_console(source=__name__,enabled=True,colored=True)>>>console(console)(<console.console.Consoleobjectat0x10277cf40>,)>>>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']}>>>DevelopmentI’ve prepared few rake tasks:$rake-T

rakebuild# Build packagerakebump[revision]# Bump versionrakeclean# Remove/Delete build..rakedefault# Default task => :installrakeinstall# Install package for local development purposeraketest# Run testrakeupload:main# Upload package to main distro (release)rakeupload:test# Upload package to test distroDefault rake task installs package locally for development purposes:$rake# runs rake installLicenseThis project is licensed under MITContributer(s)Uğur "vigo" Özyılmazel- Creator, maintainerContributeAll PR’s are welcome!fork(https://github.com/vbyazilim/django-vb-console/fork)Create yourbranch(git checkout -b my-features)commityours (git commit -am 'added killer options')pushyourbranch(git push origin my-features)Than create a newPull Request!Change Log2021-08-17Addout_coloroption.console('foo')will be green by default. Useconsole = console(source=__name__, enabled=True, colored=True, out_color='white')for white output!2021-02-05Re-write whole package from scracth2021-01-16Addoutput_toparam for streaming output to different targetsAddbasicparam for simple outputAdd unit testsAdd TravisMake small changes in theconsole.py2019-10-03Fix some of the codeAddENABLE_CONSOLEenvironment variableUpdate README2019-09-29Init repo!