Registry / ai-ml / lovely-tensors

lovely-tensors

JSON →
library0.1.22pypypi✓ verified 85d ago

lovely-tensors is a Python library that provides "syntax sugar" for PyTorch tensors, enhancing their default `repr` for better readability, debugging, and development. It adds features like rich, colored, and pretty-printed output, automatic batching, and shape inference. As of version 0.1.22, it is actively maintained with frequent minor releases focusing on new features and improvements.

pip install lovely-tensors
INSTALL
IMPORT
SIG · LOVELY-TENSORS
L
lovely-tensors
ai-mlpythonv0.1.22
Install
80.4s avg
Import
8110ms
Disk
4915MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.22 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 87.45s
py 3.11
✕ build_error
✓ 88.35s
py 3.12
✕ build_error
✓ 77.1s
py 3.13
✕ build_error
✓ 68.7s
py 3.9
✕ build_error
✕ timeout
4915MB installed
● package 4915MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lovely_tensors
import lovely_tensors as lt
The common alias `lt` is widely used in examples and makes the code more concise.
monkey_patch
import lovely_tensors as lt lt.monkey_patch()
import lovely_tensors.monkey_patch # This doesn't activate it
Calling `lt.monkey_patch()` directly is necessary to enable the enhanced `__repr__` for PyTorch tensors globally.
lovely
import lovely_tensors as lt lt.lovely(my_tensor)
Use `lt.lovely()` for explicit, controlled pretty-printing of a tensor, or when monkey-patching is not desired.

This quickstart demonstrates how to import `lovely-tensors`, enable its global monkey-patching for `torch.Tensor`'s `__repr__`, and then print PyTorch tensors to see the enhanced, colored output. It also shows how to use `lt.lovely()` for explicit pretty-printing.

import torch import lovely_tensors as lt # Enable beautiful tensor repr globally lt.monkey_patch() # Create some tensors a = torch.randn(2, 3, 4) b = torch.randint(0, 10, (1, 5), dtype=torch.int) print(f"Tensor a:\n{a}") print(f"Tensor b:\n{b}") # You can also explicitly print lovely tensors without monkey-patching # For demonstration, let's pretend monkey_patch wasn't called: # import lovely_tensors as lt # lt.lovely(torch.tensor([1,2,3]))
Debug
Known issues
gotchaTo activate the enhanced `__repr__` for PyTorch tensors automatically, you must explicitly call `lovely_tensors.monkey_patch()` after importing the library. Simply importing `lovely_tensors` is not enough.
fix
Ensure you have `import lovely_tensors as lt` followed by `lt.monkey_patch()` in your initialization code, typically at the start of your script or notebook.
affects: >=0.1.0
gotchalovely-tensors modifies the `__repr__` method of `torch.Tensor` instances. If you are using other debugging tools or libraries that also monkey-patch `torch.Tensor`'s `__repr__`, this might lead to conflicts or unexpected display behavior.
fix
If conflicts arise, try to import `lovely-tensors` before other potentially conflicting libraries. Alternatively, avoid `lt.monkey_patch()` and use `lt.lovely(tensor_instance)` for explicit pretty-printing when needed, giving you more control.
affects: >=0.1.0
deprecatedOlder versions of lovely-tensors used `lovely_tensors.init()` for activation. This method has been replaced by `lovely_tensors.monkey_patch()` for clarity and consistency.
fix
Update your code to use `lt.monkey_patch()` instead of `lt.init()` for global activation.
affects: <0.1.18
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'lovely_tensors'
The `lovely-tensors` library is not installed in your current Python environment.
fix
Run `pip install lovely-tensors` to install the library.
PyTorch tensors are not displaying with pretty colors or enhanced information, even after importing lovely_tensors.
The `monkey_patch()` function was not called, which is necessary to enable the global `__repr__` enhancement.
fix
After `import lovely_tensors as lt`, add `lt.monkey_patch()` to activate the desired behavior.
AttributeError: 'Tensor' object has no attribute 'lovely'
You are trying to access `lovely` as a method directly on a `torch.Tensor` instance, but `lovely` is a function provided by the `lovely_tensors` module, not a tensor method.
fix
Instead of `my_tensor.lovely()`, use `lt.lovely(my_tensor)` to explicitly pretty-print the tensor.
Upgrade
Version history
0.1.22latest on PyPI · released Mar 11, 2026
Audit
Dependencies
torchrequiredlovely-tensors extends PyTorch's tensor functionality and requires a compatible PyTorch version to operate.
Agent activity
4 hits · last 30 days
node
4
Resources
lovely-tensors — pip install lovely-tensors · libregistry