Skip to main content

pynameof

Installation

pip install pynameof

What it is and basic usage

This package allows you to retrieve the name of entities such as types, properties, and methods. Any object declaring __module__ and __qualname__, __qualname__ on its own, or __name__ gets resolved to a name. Its main purpose is to simplify writing error messages and other forms of user interaction (see below).

The package, for now, declares two methods which are called in a straightforward way:

from pynameof import nameof, typename_of

print(nameof(str))  # prints 'str'
print(typename_of(1))  # prints 'int'

nameof returns the name of the supplied object, typename_of resolves the type of the object and returns its name instead.

nameof additionally supports a fallback to be called if the object is not named via any of the above combinations. For example, you can write

from pynameof import nameof, typename_of

print(nameof(1, repr))  # prints '1'

Since 1 does not declare neither __module__, __qualname__, nor __name__, nameof falls back to repr.

By default, nameof and typename_of strip the module names 'builtins' and '__main__'. You can deactivate this behavior using the respective strip_builtins and strip_main parameters. The values of the two parameters are True by default, unless strip_modules is set to a value. strip_modules allows indicating a filtering callback or a single module or iterable of strings to strip. Note that, in this case, strip_builtins and strip_main are set to False by default. You must explicitly set them to True or filter them manually.

Suggested usage

This package is of particular use when we want to print references to objects. As you probably know, the default representation of types and properties in Python is not the way we actually write it in code - for property objects, it is not even visible right away, what property was meant.

class X:
    @property
    def x(self) -> int: ...


print(X)  # prints "<class '[...].X'>"
print(X.x)  # prints '<property object at 0x[...]>'

For example, when reporting type errors, we want to inform the user about the actual type that was expected. In such a case, it is natural to refer to the type with an explicit reference to the type rather than writing the full path manually. This is particularly relevant when we refactor code: The module or name of the class may change, but your IDE will probably fix the imports for you while it does not recognize references inside strings properly in some cases. For example, consider renaming X in the following example:

from pynameof import nameof


class X:
    def __init__(self, x: int) -> None:
        self._x = x

    @property
    def x(self) -> int:
        return self._x


def some_method(value: X) -> None:
    if not isinstance(value, X):
        raise TypeError(f'Expected an instance of type `{nameof(X)}` for parameter `value`.')

    if value.x < 0:
        raise ValueError(f'`{nameof(some_method)}` expects that `{nameof(X.x)}` is non-negative.')

Sadly, for parameters, such as, `value`, this is not possible, since we receive a value that does not declare the name of its parameter. nameof only works since we call it on the member definition itself rather than on the value assigned in a specific instance. Note that we also referred to X.x, not to value.x for the same reason: The property defines a function providing __module__ and a __qualname__ attributes.

Metadata

Release files for pynameof 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 pynameof 0.1.0
File Size Uploaded Provenance
pynameof-0.1.0.tar.gz 11.8 kB With provenance Details

Built distribution (wheel)

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

Total release size: 16.3 kB

Release files / pynameof-0.1.0.tar.gz

Download URL pynameof-0.1.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
09eaa83d47b3e00533a5a788e10a443724ba8c608d3fab766dda705c4a0ce6b3
BLAKE2b-256 checksum
How to use checksums
db154936a497f72ce48ea66a8f8baf15dc59fb59681d58947ab5f36b6b56fe45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

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

Download URL pynameof-0.1.0-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffdd08d481dad4022c2256a46c860b2bb3b09476f7816fee16aa5eaa46bff4ad
BLAKE2b-256 checksum
How to use checksums
849096a5cc58bf20e0ff133b5788c5a3fdc1825ffd75223c989675ad0b7157e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

Security for pynameof 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pynameof-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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