skillfed

nameof

Get the name of a variable or attribute, as in C#

nameof v0.0.1 208.9K downloads/30d#9,523 on PyPI18
Permissive license MIT Abandoned released

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 nameof

uv

uv add nameof

poetry

poetry add nameof

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8

Tags

get variable name as stringnameof functionality pythonvariable name introspectionattribute name reflectionruntime variable naming
ast-introspectionabandoned

More Software Development packages