nameof
Get the name of a variable or attribute, as in C#
What it is and what it does
nameof is a utility that extracts the string name of a variable or object attribute at runtime by inspecting the abstract syntax tree (AST). It attempts to replicate C#'s nameof operator, allowing code like `nameof(foo)` to return the string `"foo"`. The package has no runtime dependencies and consists of minimal code that can be copied directly into a project if needed.
However, the author explicitly states this was a toy project and recommends using an alternative instead. The package is abandoned, with its repository archived and no releases since 2020-02-01. It relies on fragile AST manipulation that breaks in the presence of other AST-modifying tools like pytest, and the author cautions that code depending on it should be thoroughly tested. It is not suitable for production use.
Use it for:
- Debugging and logging where you need to print variable names alongside their values
- Generating field names dynamically in data validation or ORM frameworks
- Building introspection tools that require mapping runtime objects back to their source variable names
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Retrieves the name of a variable or attribute as a string at runtime through AST inspection, mimicking C# nameof functionality.
No. The author explicitly recommends against this package in the description. The project is abandoned, last released 2020-02-01, and relies on fragile AST inspection that breaks with common tools. High install friction and lack of maintenance make it unsuitable for any new project.
Install
nameof on PyPI
pip
pip install nameofuv
uv add nameofpoetry
poetry add nameofInstalling nameof
Before you install
High install friction. The package is abandoned (repository archived, last release 2020-02-01) and the author explicitly recommends switching to an alternative instead.
License in practice
MIT license permits commercial and private use with minimal restrictions, requiring only license and copyright notice retention.
Quickstart
pip install nameof
from nameof import nameof
assert nameof(foo) == "foo"
assert nameof(foo.bar) == "bar"
The argument must be a variable or attribute; does not work in the presence of AST-modifying tools like pytest.
Verify before relying
- Whether the package works reliably with Python versions beyond 3.8
- Specific AST-based limitations beyond pytest and birdseye that may affect usage
- Whether the recommended alternative is a drop-in replacement or requires code changes
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,386 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 208,877/month — #9,523 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: nameof-0.0.1.tar.gz
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
varnameRetrieves variable names at runtime from inside…
permissive · top 15,000 on PyPI
executingIdentifies the AST node currently being…
permissive · top 1,000 on PyPI
typing-inspectProvides runtime inspection utilities for…
permissive · top 1,000 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
attributes-docExtracts and stores docstrings for class…
permissive · top 15,000 on PyPI
read-versionExtracts a version string or other variable…
permissive · top 15,000 on PyPI
qualnameProvides a `qualname()` function that emulates…
permissive · top 15,000 on PyPI
grpcio-reflectionEnables gRPC Python services to expose runtime…
permissive · top 5,000 on PyPI
snoopsnoop adds decorator-based and context-manager…
permissive · top 15,000 on PyPI
inspect2Provides the Python 3.6 inspect module API on…
permissive · top 15,000 on PyPI