Skip to main content

varInspect

Print a table of your Python variables — name, datatype, and value — straight from the running program.

from varinspect import listVars

def check_order(symbol, qty, price):
    filled = False
    tags = ["intraday", "nifty"]
    risk = {"stop": 0.5, "target": 1.2}
    listVars()

check_order("NIFTY26OCT25000CE", 50, 123.45)
name    type   value
===========================================
filled  bool   False
price   float  123.45
qty     int    50
risk    dict   {'stop': 0.5, 'target': 1.2}
symbol  str    'NIFTY26OCT25000CE'
tags    list   ['intraday', 'nifty']

Install

pip install varInspect

The distribution is named varInspect; the importable module is lowercase varinspect (PEP 8):

from varinspect import listVars, formatVars, VarRow

API

listVars(target=..., *, scope="locals", ...)

Prints the table and returns the printed rows as a list of VarRow.

Parameter Default Meaning
target caller's frame What to inspect: omit for the caller's own variables, or pass a module, a mapping, or any object.
scope "locals" "locals", "globals" or "both" — only used when target is omitted.
include_private True Include names starting with a single underscore.
include_dunder False Include __dunder__ names.
sort_by "name" "name", "type" or "value".
max_value_len 60 Truncate each value to this many columns (0 = unlimited).
max_width 100 Cap the total table width; the value column absorbs the overflow (0 = unlimited).
style "simple" "simple" (ASCII) or "box" (Unicode box drawing).
file sys.stdout Where to print.

formatVars(...)

Same signature, but returns the table as a string instead of printing it.

VarRow(name, type, value)

A frozen dataclass for one inspected variable. It unpacks like a tuple:

for name, type_, value in listVars():
    ...

More examples

Inspect a module or an object instead of the local scope:

import json
from varinspect import listVars

listVars(json)            # everything bound in the json module
listVars(my_config_obj)   # instance attributes plus class attributes
listVars({"a": 1})        # any mapping

Tune the output:

listVars(style="box", max_width=60)
listVars(scope="both", include_dunder=True, sort_by="type")
listVars(max_value_len=0, max_width=0)   # never truncate
┌───────────────────────┐
│ name  │ type │ value  │
├───────────────────────┤
│ label │ str  │ '完了' │
│ ok    │ bool │ True   │
└───────────────────────┘

Wide (CJK) characters are measured by display width, so columns stay aligned.

Notes

  • listVars skips itself, so from varinspect import listVars never shows up as a variable of its own.
  • __name__, __doc__ and friends are hidden unless you ask for them.
  • A value whose __repr__ raises is reported instead of crashing the table.
  • Only the standard library is required.

Development

python -m pytest
python -m build
twine check dist/*

License

MIT

Metadata

Release files for varInspect 0.1.0

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

Source distribution (sdist)

Source distribution for varInspect 0.1.0
File Size Uploaded
varinspect-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

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

Total release size: 17.4 kB

Release files / varinspect-0.1.0.tar.gz

Download URL varinspect-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bca10deff0ba47247cc96e14de696f6eb1dc5e99bff2475217f05e686cb128c8
BLAKE2b-256 checksum
How to use checksums
cdbf631f87ab0b55df74882665bf7743d947d2a8573d1588f84b38d937af0675
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / varinspect-0.1.0-py3-none-any.whl

Download URL varinspect-0.1.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a22b4042b4ae599f852a31438df4d7bf8b3209121b24ca901e0da0633ab2edd2
BLAKE2b-256 checksum
How to use checksums
fdcc0abf57fe91d9e32bcc0bafb68e3088223937611897a8a17da50e72536d0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

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