varname
Dark magics about variable names in python.
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has low install friction, carries a permissive MIT license, and solves a real metaprogramming need. It is well-documented with concrete examples. Install it if you need runtime variable name introspection; skip it if your code does not require that capability.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.9 or later; earlier versions need varname < 0.11.
- Low install friction with only two runtime dependencies (executing and typing-extensions).
- Actively maintained with recent commits; last release 120 days ago and repository shows 357 stars.
License · maintenance · safety
MIT (permissive) — MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
last release 2026-04-16 (120 days) · last repo commit 2026-04-16 · 357 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 414,920 downloads/mo, #6,828 on PyPI
Alternatives
Verify before relying
from varname import varname
def function():
return varname()
func = function() # func == 'func'- Whether frame inspection works reliably across all Python 3.9+ implementations and edge cases.
- Performance characteristics when called repeatedly in hot code paths.
- Compatibility with async/await patterns beyond the asyncio.run example shown.
What it is and what it does
Varname is a metaprogramming library that uses stack frame inspection to retrieve the names of variables that function or class calls are assigned to, from inside those functions or classes. It exposes this core capability through functions like `varname()` (to get the assignment variable name), `argname()` (to fetch the names or source of arguments passed to a function), and `will()` (to detect the next attribute access). The library depends on executing for bytecode inspection and typing-extensions for type hints.
The package is useful when you need runtime introspection of variable names—for instance, to automatically populate an object's `__varname__` attribute with the name it was assigned to, to create dictionaries without explicitly repeating key names, or to implement debugging utilities that print variable names alongside their values. It handles complex cases like multiple assignment, nested unpacking, and calls wrapped through intermediate functions.
Use it for
- Automatically populate an object's id or name field with the variable name it was assigned to.
- Create dictionaries from variables without repeating key names (jsobj helper).
- Implement debug utilities that print variable names and values together.
- Fetch the names or source expressions of arguments passed to a function.
- Detect which attribute will be accessed next on an object (will function).
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has low install friction, carries a permissive MIT license, and solves a real metaprogramming need. It is well-documented with concrete examples. Install it if you need runtime variable name introspection; skip it if your code does not require that capability.
Install
varname on PyPI
Before you install
Low install friction with only two runtime dependencies (executing and typing-extensions). Actively maintained with recent commits; last release 120 days ago and repository shows 357 stars.
Requires Python 3.9 or later; earlier versions need varname < 0.11.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.
Quickstart
from varname import varname
def function():
return varname()
func = function() # func == 'func'
Verify before relying
- Whether frame inspection works reliably across all Python 3.9+ implementations and edge cases.
- Performance characteristics when called repeatedly in hot code paths.
- Compatibility with async/await patterns beyond the asyncio.run example shown.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.9 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesexecutingtyping-extensions |
| Maintenance | Actively maintained 120 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 414,920 / month, #6,828 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
Evidence: varname-1.0.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “get variable name at runtime”
- varnameRetrieves variable names at runtime from inside functions and…
- nameofRetrieves the name of a variable or attribute as a string at runtime…
- envierEnvier extracts application configuration from environment variables…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also nameof · executing · getname · singleton-decorator · patchy · read-version · snoop · argbind · public · icecream