Skip to main content

easierlog: the easy way to inspect variables in Python

Python GitHub Workflow Status (event) PyPI Downloads CodeFactor

Overview

easierlog provides an easier, but much more powerful replacement for print() function when debugging in Python.

Installation

To install the latest release, type:

$ pip install easierlog

Getting Started

Roughly every software developer needs to check how variables behave in runtime. In Python, this can be done by using print() function, that prints out the value of the passed variable. Sometimes, instead, the variable value is not enough. This is specially true when there are many variables to be inspected, or even when the same variable needs to be inspected in many parts of the code.

To inspect both variable name and value, print() is not so straightforward:

print('some_variable =', some_variable)

It became a little bit easier since Python 3.8:

print(f'{some_variable=}')

But not so easy when comparing to easierlog:

log(some_variable)

This can better understood in the script:

 1  # script1.py
 2  
 3  def function1():
 4      a = 4
 5      print(a)
 6
 7
 8  def function2():
 9      a = 3
10      b = 'Hello World'
11      print(a)
12      print(b)
13
14
15  function1()
16  function2()
17

Running the script above, it will result:

4
3
Hello World

Basic usage

By using easierlog, the previous script would become:

 1  # script2.py
 2  
 3  from easierlog import log
 4  
 5
 6  def function1():
 7      a = 4
 8      log(a)
 9 
10  
11  def function2():
12      a = 3
13      b = 'Hello World'
14      log(a)
15      log(b)
16
17
18  function1()
19  function2()
20

Running the script above, it will result:

[script2.py (line 08) in function1] (int) a = 4
[script2.py (line 14) in function2] (int) a = 3
[script2.py (line 15) in function2] (str) b = 'Hello World'

As shown above, log() provides information about where it was called:

  • File name
  • Line number
  • Function name

And about the variable passed as argument:

  • Variable type
  • Variable name
  • Variable value

Multiple variables

It is also possible to pass multiple variables at once:

 1  # script3.py
 2  
 3  from easierlog import log
 4 
 5 
 6  def function():
 7      x = 2.3
 8      y = 1.5
 9      z = 0.1
10      log(x, y, z)
11
12 
13  function()
14

It will result:

[script3.py (line 10) in function] (float) x = 2.3
[script3.py (line 10) in function] (float) y = 1.5
[script3.py (line 10) in function] (float) z = 0.1

All variables

Calling log() without any arguments it will log all declared variables in the function:

 1  # script4.py
 2  
 3  from easierlog import log
 4 
 5 
 6  def function():
 7      x = 2.3
 8      y = 1.5
 9      z = 0.1
10      log()
11
12 
13  function()
14

It will result:

[script4.py (line 10) in function] (float) x = 2.3
[script4.py (line 10) in function] (float) y = 1.5
[script4.py (line 10) in function] (float) z = 0.1

Expressions

Not only variables can be passed to log() function. Expressions also work:

 1  # script5.py
 2  
 3  from easierlog import log
 4 
 5 
 6  def function():
 7      x = 2.3
 8      y = 1.5
 9      z = 0.1
10      log(x + y + z)
12 
13  function()
14

It will result:

[script5.py (line 10) in function] (float) x + y + z = 3.9

License

This package is released under MIT License.

Release files for easierlog 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easierlog 1.1.1
File Size Uploaded
easierlog-1.1.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easierlog 1.1.1
File Interpreter ABI Platform
easierlog-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / easierlog-1.1.1.tar.gz

Download URL easierlog-1.1.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4b6c5837562d9eabb9cb713eaa279716313f2eddbab70b9ff1c23a2211fad310
BLAKE2b-256 checksum
How to use checksums
11d0924bc05ac318602ee116a985054e286d046d92b3fed3db8cb01422bc272d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

Release files / easierlog-1.1.1-py3-none-any.whl

Download URL easierlog-1.1.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f69b7b6ed9fe3c789dedaa920502cfa7a2cfd926256b74e00c2e5566e09dcbd3
BLAKE2b-256 checksum
How to use checksums
620545b4f503fff085dcc611e363d16e286521130576466df08b39f8edd54921
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page