Skip to content

Latest commit

 

History

84 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple print

Local development tool for logs printing.

https://github.com/Sobolev5/simple-print

Install

To install run:

pip install simple-print

Features

  • Variable value on the first line, metadata (type, file, line, function, time) on the second line
  • Clickable file paths in terminal output — Cmd+click (macOS) or Ctrl+click (Linux/Windows) to jump to source
  • Colors, backgrounds, attributes, indentation

sprint

Print variables with its names:

master = "yoda" # variable name master
sprint(master) 
sprint(master, c="magenta") 
sprint(master, c="white", b="on_blue") 
sprint(master, c="blue", b="white", a="underline") 
sprint(master, c="blue", b="on_white", a="bold", p=True) 
master_as_s = sprint(master, s=True) # return as string
master_as_s_with_path = sprint(master, s=True, p=True) # return as string with path to file 

c color [grey, red, green, yellow, blue, magenta, cyan, white].
b background [on_grey, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan].
a attribute [bold, dark, underline, blink, reverse, concealed].
p path [True/False] with path to file.
l light [True/False] print without fn name and lineno (shortcut lprint).
i indent [1..40].
s string [True/False] return as string.
r return [True/False] print and return as string.
f force print [True/False] ignore SIMPLE_PRINT_ENABLED=False for docker production logs for example.
stream output stream [stdout, stderr, null]. stdout by default. null means no print.

Example with indent

Indent print:

def test_indent():
    fruits = ["lemon", "orange", "banana"]
    sprint(fruits, c="green")  
    for fruit in fruits:
        sprint(fruit, c="yellow", i=4)

lprint

Light version of sprint (no metadata line). Also available as lsprint for backward compatibility.

master = "yoda" # variable name master
lprint(master)
   

SprintErr

Minified error traceback with box frame.

from simple_print import SprintErr

bob = []
with SprintErr(l=30):
    bob[2]  # pretty error traceback (show 30 lines)
  

spprint

Pretty print dict with box frame.

from simple_print import spprint

spprint({"hello": "world", "lorem": "ipsum"})
spprint({"hello": "world", "lorem": "ipsum"}, i=20)  # with indent
  

Env

Stop printing on production:

export SIMPLE_PRINT_ENABLED=False

Test

pytest -s

About

Powerful debugging & logging tool for Python

Resources

Stars

52 stars

Watchers

7 watching

Forks

Releases

Packages

Used by

Contributors

Languages